Translated using Weblate (French)
[phpmyadmin.git] / libraries / operations.lib.php
blobc4c453a60b36a5b49fbf77beb4462b91a74e11de
1 <?php
3 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * set of functions with the operations section in pma
7 * @package PhpMyAdmin
8 */
10 if (! defined('PHPMYADMIN')) {
11 exit;
14 /**
15 * Get HTML output for database comment
17 * @param string $db database name
19 * @return string $html_output
21 function PMA_getHtmlForDatabaseComment($db)
23 $html_output = '<div class="operations_half_width">'
24 . '<form method="post" action="db_operations.php">'
25 . PMA_generate_common_hidden_inputs($db)
26 . '<fieldset>'
27 . '<legend>';
28 if (in_array(
29 $GLOBALS['cfg']['ActionLinksMode'],
30 array('icons', 'both')
32 ) {
33 $html_output .= '<img class="icon ic_b_comment" '
34 . 'src="themes/dot.gif" alt="" />';
36 $html_output .= __('Database comment: ');
37 $html_output .= '</legend>';
38 $html_output .= '<input type="text" name="comment" '
39 . 'class="textfield" size="30"'
40 . 'value="' . htmlspecialchars(PMA_getDBComment($db)) . '" />'
41 . '</fieldset>';
42 $html_output .= '<fieldset class="tblFooters">'
43 . '<input type="submit" value="' . __('Go') . '" />'
44 . '</fieldset>'
45 . '</form>'
46 . '</div>';
48 return $html_output;
51 /**
52 * Get HTML output for rename database
54 * @param string $db database name
56 * @return string $html_output
58 function PMA_getHtmlForRenameDatabase($db)
60 $html_output = '<div class="operations_half_width">'
61 . '<form id="rename_db_form" '
62 . 'class="ajax" '
63 . 'method="post" action="db_operations.php" '
64 . 'onsubmit="return emptyFormElements(this, \'newname\')">';
65 if (isset($_REQUEST['db_collation'])) {
66 $html_output .= '<input type="hidden" name="db_collation" '
67 . 'value="' . $_REQUEST['db_collation']
68 .'" />' . "\n";
70 $html_output .= '<input type="hidden" name="what" value="data" />'
71 . '<input type="hidden" name="db_rename" value="true" />'
72 . PMA_generate_common_hidden_inputs($db)
73 . '<fieldset>'
74 . '<legend>';
76 if (in_array(
77 $GLOBALS['cfg']['ActionLinksMode'],
78 array('icons', 'both')
80 ) {
81 $html_output .= PMA_Util::getImage('b_edit.png');
83 $html_output .= __('Rename database to') . ':'
84 . '</legend>';
86 $html_output .= '<input id="new_db_name" type="text" name="newname" '
87 . 'size="30" class="textfield" value="" />'
88 . '</fieldset>'
89 . '<fieldset class="tblFooters">'
90 . '<input id="rename_db_input" type="submit" value="' . __('Go') . '" />'
91 . '</fieldset>'
92 . '</form>'
93 . '</div>';
95 return $html_output;
98 /**
99 * Get HTML for database drop link
101 * @param string $db database name
103 * @return string $html_output
105 function PMA_getHtmlForDropDatabaseLink($db)
107 $this_sql_query = 'DROP DATABASE ' . PMA_Util::backquote($db);
108 $this_url_params = array(
109 'sql_query' => $this_sql_query,
110 'back' => 'db_operations.php',
111 'goto' => 'index.php',
112 'reload' => '1',
113 'purge' => '1',
114 'message_to_show' => sprintf(
115 __('Database %s has been dropped.'),
116 htmlspecialchars(PMA_Util::backquote($db))
118 'db' => null,
121 $html_output = '<div class="operations_half_width">'
122 . '<fieldset class="caution">';
123 $html_output .= '<legend>';
124 if (in_array(
125 $GLOBALS['cfg']['ActionLinksMode'],
126 array('icons', 'both')
129 $html_output .= PMA_Util::getImage('b_deltbl.png');
131 $html_output .= __('Remove database')
132 . '</legend>';
133 $html_output .= '<ul>';
134 $html_output .= PMA_getDeleteDataOrTablelink(
135 $this_url_params,
136 'DROP_DATABASE',
137 __('Drop the database (DROP)'),
138 'drop_db_anchor'
140 $html_output .= '</ul></fieldset>'
141 . '</div>';
143 return $html_output;
147 * Get HTML snippet for copy database
149 * @param string $db database name
151 * @return string $html_output
153 function PMA_getHtmlForCopyDatabase($db)
155 $drop_clause = 'DROP TABLE / DROP VIEW';
156 $choices = array(
157 'structure' => __('Structure only'),
158 'data' => __('Structure and data'),
159 'dataonly' => __('Data only')
162 if (isset($_COOKIE)
163 && isset($_COOKIE['pma_switch_to_new'])
164 && $_COOKIE['pma_switch_to_new'] == 'true'
166 $pma_switch_to_new = 'true';
169 $html_output = '<div class="operations_half_width clearfloat">';
170 $html_output .= '<form id="copy_db_form" '
171 . 'class="ajax" '
172 . 'method="post" action="db_operations.php"'
173 . 'onsubmit="return emptyFormElements(this, \'newname\')">';
175 if (isset($_REQUEST['db_collation'])) {
176 $html_output .= '<input type="hidden" name="db_collation" '
177 . 'value="' . $_REQUEST['db_collation'] .'" />' . "\n";
179 $html_output .= '<input type="hidden" name="db_copy" value="true" />' . "\n"
180 . PMA_generate_common_hidden_inputs($db);
181 $html_output .= '<fieldset>'
182 . '<legend>';
184 if (in_array(
185 $GLOBALS['cfg']['ActionLinksMode'],
186 array('icons', 'both')
189 $html_output .= PMA_Util::getImage('b_edit.png');
191 $html_output .= __('Copy database to') . ':'
192 . '</legend>'
193 . '<input type="text" name="newname" size="30" '
194 . 'class="textfield" value="" /><br />'
195 . PMA_Util::getRadioFields(
196 'what', $choices, 'data', true
198 $html_output .= '<input type="checkbox" name="create_database_before_copying" '
199 . 'value="1" id="checkbox_create_database_before_copying"'
200 . 'checked="checked" />';
201 $html_output .= '<label for="checkbox_create_database_before_copying">'
202 . __('CREATE DATABASE before copying') . '</label><br />';
203 $html_output .= '<input type="checkbox" name="drop_if_exists" value="true"'
204 . 'id="checkbox_drop" />';
205 $html_output .= '<label for="checkbox_drop">'
206 . sprintf(__('Add %s'), $drop_clause)
207 . '</label><br />';
208 $html_output .= '<input type="checkbox" name="sql_auto_increment" value="1" '
209 . 'checked="checked" id="checkbox_auto_increment" />';
210 $html_output .= '<label for="checkbox_auto_increment">'
211 . __('Add AUTO_INCREMENT value') . '</label><br />';
212 $html_output .= '<input type="checkbox" name="add_constraints" value="1"'
213 . 'id="checkbox_constraints" />';
214 $html_output .= '<label for="checkbox_constraints">'
215 . __('Add constraints') . '</label><br />';
216 $html_output .= '<input type="checkbox" name="switch_to_new" value="true"'
217 . 'id="checkbox_switch"'
218 . ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true')
219 ? ' checked="checked"'
220 : '')
221 . '/>';
222 $html_output .= '<label for="checkbox_switch">'
223 . __('Switch to copied database') . '</label>'
224 . '</fieldset>';
225 $html_output .= '<fieldset class="tblFooters">'
226 . '<input type="submit" name="submit_copy" value="' . __('Go') . '" />'
227 . '</fieldset>'
228 . '</form>'
229 . '</div>';
231 return $html_output;
235 * Get HTML snippet for change database charset
237 * @param string $db database name
238 * @param string $table tabel name
240 * @return string $html_output
242 function PMA_getHtmlForChangeDatabaseCharset($db, $table)
244 $html_output = '<div class="operations_half_width">'
245 . '<form id="change_db_charset_form" ';
246 $html_output .= 'class="ajax" ';
247 $html_output .= 'method="post" action="db_operations.php">';
249 $html_output .= PMA_generate_common_hidden_inputs($db, $table);
251 $html_output .= '<fieldset>' . "\n"
252 . ' <legend>';
253 if (in_array(
254 $GLOBALS['cfg']['ActionLinksMode'],
255 array('icons', 'both')
258 $html_output .= PMA_Util::getImage('s_asci.png');
260 $html_output .= '<label for="select_db_collation">' . __('Collation')
261 . ':</label>' . "\n"
262 . '</legend>' . "\n"
263 . PMA_generateCharsetDropdownBox(
264 PMA_CSDROPDOWN_COLLATION,
265 'db_collation',
266 'select_db_collation',
267 isset($_REQUEST['db_collation']) ? $_REQUEST['db_collation'] : '',
268 false,
271 . '</fieldset>'
272 . '<fieldset class="tblFooters">'
273 . '<input type="submit" name="submitcollation"'
274 . ' value="' . __('Go') . '" />' . "\n"
275 . '</fieldset>' . "\n"
276 . '</form></div>' . "\n";
278 return $html_output;
282 * Get HTML snippet for export relational schema view
284 * @param string $url_query
286 * @return string $html_output
288 function PMA_getHtmlForExportRelationalSchemaView($url_query)
290 $html_output = '<div class="operations_full_width">'
291 . '<fieldset><a href="schema_edit.php?' . $url_query . '">';
292 if (in_array(
293 $GLOBALS['cfg']['ActionLinksMode'],
294 array('icons', 'both')
297 $html_output .= PMA_Util::getImage(
298 'b_edit.png'
301 $html_output .= __('Edit or export relational schema')
302 . '</a></fieldset>'
303 . '</div>';
305 return $html_output;
309 * Run the Procedure definitions and function definitions
311 * to avoid selecting alternatively the current and new db
312 * we would need to modify the CREATE definitions to qualify
313 * the db name
315 * @param string $db database name
317 * @return void
319 function PMA_runProcedureAndFunctionDefinitions($db)
321 $procedure_names = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE');
322 if ($procedure_names) {
323 foreach ($procedure_names as $procedure_name) {
324 PMA_DBI_select_db($db);
325 $tmp_query = PMA_DBI_get_definition(
326 $db, 'PROCEDURE', $procedure_name
328 // collect for later display
329 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
330 PMA_DBI_select_db($_REQUEST['newname']);
331 PMA_DBI_query($tmp_query);
335 $function_names = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION');
336 if ($function_names) {
337 foreach ($function_names as $function_name) {
338 PMA_DBI_select_db($db);
339 $tmp_query = PMA_DBI_get_definition($db, 'FUNCTION', $function_name);
340 // collect for later display
341 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
342 PMA_DBI_select_db($_REQUEST['newname']);
343 PMA_DBI_query($tmp_query);
349 * Get sql query and create database before copy
351 * @return string $sql_query
353 function PMA_getSqlQueryAndCreateDbBeforeCopy()
355 // lower_case_table_names=1 `DB` becomes `db`
356 if (! PMA_DRIZZLE) {
357 $lower_case_table_names = PMA_DBI_fetch_value(
358 'SHOW VARIABLES LIKE "lower_case_table_names"', 0, 1
360 if ($lower_case_table_names === '1') {
361 $_REQUEST['newname'] = PMA_strtolower($_REQUEST['newname']);
365 $local_query = 'CREATE DATABASE IF NOT EXISTS '
366 . PMA_Util::backquote($_REQUEST['newname']);
367 if (isset($_REQUEST['db_collation'])) {
368 $local_query .= ' DEFAULT'
369 . PMA_generateCharsetQueryPart($_REQUEST['db_collation']);
371 $local_query .= ';';
372 $sql_query = $local_query;
373 // save the original db name because Tracker.class.php which
374 // may be called under PMA_DBI_query() changes $GLOBALS['db']
375 // for some statements, one of which being CREATE DATABASE
376 $original_db = $GLOBALS['db'];
377 PMA_DBI_query($local_query);
378 $GLOBALS['db'] = $original_db;
380 // rebuild the database list because PMA_Table::moveCopy
381 // checks in this list if the target db exists
382 $GLOBALS['pma']->databases->build();
384 return $sql_query;
388 * remove all foreign key constraints and return
389 * sql constraints query for full database
391 * @param array $tables_full array of all tables in given db or dbs
392 * @param object $export_sql_plugin export plugin instance
393 * @param boolean $move whether databse name is empty or not
394 * @param string $db database name
396 * @return string sql constraints query for full databases
398 function PMA_getSqlConstraintsQueryForFullDb(
399 $tables_full, $export_sql_plugin, $move, $db
401 $sql_constraints_query_full_db = array();
402 foreach ($tables_full as $each_table => $tmp) {
403 $sql_constraints = '';
404 $sql_drop_foreign_keys = '';
405 $sql_structure = $export_sql_plugin->getTableDef(
406 $db, $each_table, "\n", '', false, false
408 if ($move && ! empty($sql_drop_foreign_keys)) {
409 PMA_DBI_query($sql_drop_foreign_keys);
411 // keep the constraint we just dropped
412 if (! empty($sql_constraints)) {
413 $sql_constraints_query_full_db[] = $sql_constraints;
416 return $sql_constraints_query_full_db;
420 * Get views as an array and create SQL view stand-in
422 * @param array $tables_full array of all tables in given db or dbs
423 * @param object $export_sql_plugin export plugin instance
424 * @param strin $db database name
426 * @return array $views
428 function PMA_getViewsAndCreateSqlViewStandIn(
429 $tables_full, $export_sql_plugin, $db
431 $views = array();
432 foreach ($tables_full as $each_table => $tmp) {
433 // to be able to rename a db containing views,
434 // first all the views are collected and a stand-in is created
435 // the real views are created after the tables
436 if (PMA_Table::isView($db, $each_table)) {
437 $views[] = $each_table;
438 // Create stand-in definition to resolve view dependencies
439 $sql_view_standin = $export_sql_plugin->getTableDefStandIn(
440 $db, $each_table, "\n"
442 PMA_DBI_select_db($_REQUEST['newname']);
443 PMA_DBI_query($sql_view_standin);
444 $GLOBALS['sql_query'] .= "\n" . $sql_view_standin;
447 return $views;
451 * Get sql query for copy/rename table and boolean for whether copy/rename or not
453 * @param array $tables_full array of all tables in given db or dbs
454 * @param string $sql_query sql query for all operations
455 * @param boolean $move whether databse name is empty or not
456 * @param string $db database name
458 * @return array ($sql_query, $error)
460 function PMA_getSqlQueryForCopyTable($tables_full, $sql_query, $move, $db)
462 $error = false;
463 foreach ($tables_full as $each_table => $tmp) {
464 // skip the views; we have creted stand-in definitions
465 if (PMA_Table::isView($db, $each_table)) {
466 continue;
468 $back = $sql_query;
469 $sql_query = '';
471 // value of $what for this table only
472 $this_what = $_REQUEST['what'];
474 // do not copy the data from a Merge table
475 // note: on the calling FORM, 'data' means 'structure and data'
476 if (PMA_Table::isMerge($db, $each_table)) {
477 if ($this_what == 'data') {
478 $this_what = 'structure';
480 if ($this_what == 'dataonly') {
481 $this_what = 'nocopy';
485 if ($this_what != 'nocopy') {
486 // keep the triggers from the original db+table
487 // (third param is empty because delimiters are only intended
488 // for importing via the mysql client or our Import feature)
489 $triggers = PMA_DBI_get_triggers($db, $each_table, '');
491 if (! PMA_Table::moveCopy(
492 $db, $each_table, $_REQUEST['newname'], $each_table,
493 (isset($this_what) ? $this_what : 'data'),
494 $move, 'db_copy'
495 )) {
496 $error = true;
497 // $sql_query is filled by PMA_Table::moveCopy()
498 $sql_query = $back . $sql_query;
499 break;
501 // apply the triggers to the destination db+table
502 if ($triggers) {
503 PMA_DBI_select_db($_REQUEST['newname']);
504 foreach ($triggers as $trigger) {
505 PMA_DBI_query($trigger['create']);
506 $GLOBALS['sql_query'] .= "\n" . $trigger['create'] . ';';
510 // this does not apply to a rename operation
511 if (isset($_REQUEST['add_constraints'])
512 && ! empty($GLOBALS['sql_constraints_query'])
514 $GLOBALS['sql_constraints_query_full_db'][]
515 = $GLOBALS['sql_constraints_query'];
516 unset($GLOBALS['sql_constraints_query']);
519 // $sql_query is filled by PMA_Table::moveCopy()
520 $sql_query = $back . $sql_query;
522 return array($sql_query, $error);
526 * Run the EVENT definition for selected database
528 * to avoid selecting alternatively the current and new db
529 * we would need to modify the CREATE definitions to qualify
530 * the db name
532 * @param string $db database name
534 * @return void
536 function PMA_runEventDefinitionsForDb($db)
538 $event_names = PMA_DBI_fetch_result(
539 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \''
540 . PMA_Util::sqlAddSlashes($db, true) . '\';'
542 if ($event_names) {
543 foreach ($event_names as $event_name) {
544 PMA_DBI_select_db($db);
545 $tmp_query = PMA_DBI_get_definition($db, 'EVENT', $event_name);
546 // collect for later display
547 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
548 PMA_DBI_select_db($_REQUEST['newname']);
549 PMA_DBI_query($tmp_query);
555 * Handle the views, return the boolean value whether table rename/copy or not
557 * @param array $views views as an array
558 * @param boolean $move whether databse name is empty or not
559 * @param string $db database name
561 * @return boolean $_error whether table rename/copy or not
563 function PMA_handleTheViews($views, $move, $db)
565 $_error = false;
566 // temporarily force to add DROP IF EXIST to CREATE VIEW query,
567 // to remove stand-in VIEW that was created earlier
568 // ( $_REQUEST['drop_if_exists'] is used in moveCopy() )
569 if (isset($_REQUEST['drop_if_exists'])) {
570 $temp_drop_if_exists = $_REQUEST['drop_if_exists'];
572 $_REQUEST['drop_if_exists'] = 'true';
574 foreach ($views as $view) {
575 $copying_succeeded = PMA_Table::moveCopy(
576 $db, $view, $_REQUEST['newname'], $view, 'structure', $move, 'db_copy'
578 if (! $copying_succeeded) {
579 $_error = true;
580 break;
583 unset($_REQUEST['drop_if_exists']);
584 if (isset($temp_drop_if_exists)) {
585 // restore previous value
586 $_REQUEST['drop_if_exists'] = $temp_drop_if_exists;
588 return $_error;
592 * Create all accumulated constraaints
594 * @return void
596 function PMA_createAllAccumulatedConstraints()
598 PMA_DBI_select_db($_REQUEST['newname']);
599 foreach ($GLOBALS['sql_constraints_query_full_db'] as $one_query) {
600 PMA_DBI_query($one_query);
601 // and prepare to display them
602 $GLOBALS['sql_query'] .= "\n" . $one_query;
604 unset($GLOBALS['sql_constraints_query_full_db']);
608 * Duplicate the bookmarks for the db (done once for each db)
610 * @param boolean $_error whether table rename/copy or not
611 * @param string $db database name
613 * @return void
615 function PMA_duplicateBookmarks($_error, $db)
617 if (! $_error && $db != $_REQUEST['newname']) {
618 $get_fields = array('user', 'label', 'query');
619 $where_fields = array('dbase' => $db);
620 $new_fields = array('dbase' => $_REQUEST['newname']);
621 PMA_Table::duplicateInfo(
622 'bookmarkwork', 'bookmark', $get_fields,
623 $where_fields, $new_fields
629 * Get the HTML snippet for order the table
631 * @param array $columns columns array
633 * @return string $html_out
635 function PMA_getHtmlForOrderTheTable($columns)
637 $html_output = '<div class="operations_half_width">';
638 $html_output .= '<form method="post" id="alterTableOrderby" '
639 . 'action="tbl_operations.php">';
640 $html_output .= PMA_generate_common_hidden_inputs(
641 $GLOBALS['db'], $GLOBALS['table']
643 $html_output .= '<fieldset id="fieldset_table_order">'
644 . '<legend>' . __('Alter table order by') . '</legend>'
645 . '<select name="order_field">';
647 foreach ($columns as $fieldname) {
648 $html_output .= '<option '
649 . 'value="' . htmlspecialchars($fieldname['Field']) . '">'
650 . htmlspecialchars($fieldname['Field']) . '</option>' . "\n";
652 $html_output .= '</select> ' . __('(singly)') . ' '
653 . '<select name="order_order">'
654 . '<option value="asc">' . __('Ascending') . '</option>'
655 . '<option value="desc">' . __('Descending') . '</option>'
656 . '</select>'
657 . '</fieldset>'
658 . '<fieldset class="tblFooters">'
659 . '<input type="hidden" name="submitorderby" value="1" />'
660 . '<input type="submit" value="' . __('Go') . '" />'
661 . '</fieldset>'
662 . '</form>'
663 . '</div>';
665 return $html_output;
669 * Get the HTML snippet for move table
671 * @return string $html_output
673 function PMA_getHtmlForMoveTable()
675 $html_output = '<div class="operations_half_width">';
676 $html_output .= '<form method="post" action="tbl_operations.php"'
677 . ' id="moveTableForm" class="ajax"'
678 . ' onsubmit="return emptyFormElements(this, \'new_name\')">'
679 . PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']);
681 $html_output .= '<input type="hidden" name="reload" value="1" />'
682 . '<input type="hidden" name="what" value="data" />'
683 . '<fieldset id="fieldset_table_rename">';
685 $html_output .= '<legend>' . __('Move table to (database<b>.</b>table):')
686 . '</legend>';
688 if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
689 $html_output .= '<input type="text" maxlength="100" size="30" '
690 . 'name="target_db" value="' . htmlspecialchars($GLOBALS['db'])
691 . '"/>';
692 } else {
693 $html_output .= '<select name="target_db">'
694 . $GLOBALS['pma']->databases->getHtmlOptions(true, false)
695 . '</select>';
697 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
698 $html_output .= '<input type="text" size="20" name="new_name"'
699 . ' onfocus="this.select()"'
700 . 'value="' . htmlspecialchars($GLOBALS['table']) . '" /><br />';
702 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
703 // next value but users can decide if they want it or not for the operation
705 $html_output .= '<input type="checkbox" name="sql_auto_increment" '
706 . 'value="1" id="checkbox_auto_increment_mv" checked="checked" />'
707 . '<label for="checkbox_auto_increment_mv">'
708 . __('Add AUTO_INCREMENT value')
709 . '</label><br />'
710 . '</fieldset>';
712 $html_output .= '<fieldset class="tblFooters">'
713 . '<input type="submit" name="submit_move" value="' . __('Go') . '" />'
714 . '</fieldset>'
715 . '</form>'
716 . '</div>';
718 return $html_output;
722 * Get the HTML div for Table option
724 * @param string $comment Comment
725 * @param array $tbl_collation table collation
726 * @param string $tbl_storage_engine table storage engine
727 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
728 * @param boolean $is_isam whether ISAM or not
729 * @param array $pack_keys pack keys
730 * @param string $auto_increment value of auto increment
731 * @param string $delay_key_write delay key write
732 * @param string $transactional value of transactional
733 * @param string $page_checksum value of page checksum
734 * @param boolean $is_innodb whether INNODB or not
735 * @param boolean $is_pbxt whether PBXT or not
736 * @param boolean $is_aria whether ARIA or not
737 * @param string $checksum the checksum
739 * @return string $html_output
741 function PMA_getTableOptionDiv($comment, $tbl_collation, $tbl_storage_engine,
742 $is_myisam_or_aria, $is_isam, $pack_keys, $auto_increment, $delay_key_write,
743 $transactional, $page_checksum, $is_innodb, $is_pbxt, $is_aria, $checksum
745 $html_output = '<div class="operations_half_width clearfloat">';
746 $html_output .= '<form method="post" action="tbl_operations.php"';
747 $html_output .= ' id="tableOptionsForm" class="ajax">';
748 $html_output .= PMA_generate_common_hidden_inputs(
749 $GLOBALS['db'], $GLOBALS['table']
751 $html_output .= '<input type="hidden" name="reload" value="1" />';
753 $html_output .= PMA_getTableOptionFieldset(
754 $comment, $tbl_collation,
755 $tbl_storage_engine, $is_myisam_or_aria, $is_isam, $pack_keys,
756 $delay_key_write, $auto_increment, $transactional, $page_checksum,
757 $is_innodb, $is_pbxt, $is_aria, $checksum
760 $html_output .= '<fieldset class="tblFooters">'
761 . '<input type="hidden" name="submitoptions" value="1" />'
762 . '<input type="submit" value="' . __('Go') . '" />'
763 . '</fieldset>'
764 . '</form>'
765 . '</div>';
767 return $html_output;
771 * Get HTML fieldset for Table option, it contains HTML table for options
773 * @param string $comment Comment
774 * @param array $tbl_collation table collation
775 * @param string $tbl_storage_engine table storage engine
776 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
777 * @param boolean $is_isam whether ISAM or not
778 * @param array $pack_keys pack keys
779 * @param string $delay_key_write delay key write
780 * @param string $auto_increment value of auto increment
781 * @param string $transactional value of transactional
782 * @param string $page_checksum value of page checksum
783 * @param boolean $is_innodb whether INNODB or not
784 * @param boolean $is_pbxt whether PBXT or not
785 * @param boolean $is_aria whether ARIA or not
786 * @param string $checksum the checksum
788 * @return string $html_output
790 function PMA_getTableOptionFieldset($comment, $tbl_collation,
791 $tbl_storage_engine, $is_myisam_or_aria, $is_isam, $pack_keys,
792 $delay_key_write, $auto_increment, $transactional,
793 $page_checksum, $is_innodb, $is_pbxt, $is_aria, $checksum
795 $html_output = '<fieldset>'
796 . '<legend>' . __('Table options') . '</legend>';
798 $html_output .= '<table>';
799 //Change table name
800 $html_output .= '<tr><td>' . __('Rename table to') . '</td>'
801 . '<td>'
802 . '<input type="text" size="20" name="new_name" onfocus="this.select()"'
803 . 'value="' . htmlspecialchars($GLOBALS['table']) . '" />'
804 . '</td>'
805 . '</tr>';
807 //Table comments
808 $html_output .= '<tr><td>' . __('Table comments') . '</td>'
809 . '<td><input type="text" name="comment" maxlength="60" size="30"'
810 . 'value="' . htmlspecialchars($comment) . '" onfocus="this.select()" />'
811 . '<input type="hidden" name="prev_comment" value="'
812 . htmlspecialchars($comment) . '" />'
813 . '</td>'
814 . '</tr>';
816 //Storage engine
817 $html_output .= '<tr><td>' . __('Storage Engine')
818 . PMA_Util::showMySQLDocu(
819 'Storage_engines', 'Storage_engines'
821 . '</td>'
822 . '<td>'
823 . PMA_StorageEngine::getHtmlSelect(
824 'new_tbl_storage_engine', null, $tbl_storage_engine
826 . '</td>'
827 . '</tr>';
829 //Table character set
830 $html_output .= '<tr><td>' . __('Collation') . '</td>'
831 . '<td>'
832 . PMA_generateCharsetDropdownBox(
833 PMA_CSDROPDOWN_COLLATION,
834 'tbl_collation', null, $tbl_collation, false, 3
836 . '</td>'
837 . '</tr>';
839 if ($is_myisam_or_aria || $is_isam) {
840 $html_output .= '<tr>'
841 . '<td><label for="new_pack_keys">PACK_KEYS</label></td>'
842 . '<td><select name="new_pack_keys" id="new_pack_keys">';
844 $html_output .= '<option value="DEFAULT"';
845 if ($pack_keys == 'DEFAULT') {
846 $html_output .= 'selected="selected"';
848 $html_output .= '>DEFAULT</option>
849 <option value="0"';
850 if ($pack_keys == '0') {
851 $html_output .= 'selected="selected"';
853 $html_output .= '>0</option>
854 <option value="1" ';
855 if ($pack_keys == '1') {
856 $html_output .= 'selected="selected"';
858 $html_output .= '>1</option>'
859 . '</select>'
860 . '</td>'
861 . '</tr>';
862 } // end if (MYISAM|ISAM)
864 if ($is_myisam_or_aria) {
865 $html_output .= PMA_getHtmlForTableRow(
866 'new_checksum',
867 'CHECKSUM',
868 $checksum
871 $html_output .= PMA_getHtmlForTableRow(
872 'new_delay_key_write',
873 'DELAY_KEY_WRITE',
874 $delay_key_write
876 } // end if (MYISAM)
878 if ($is_aria) {
879 $html_output .= PMA_getHtmlForTableRow(
880 'new_transactional',
881 'TRANSACTIONAL',
882 $transactional
885 $html_output .= PMA_getHtmlForTableRow(
886 'new_page_checksum',
887 'PAGE_CHECKSUM',
888 $page_checksum
890 } // end if (ARIA)
892 if (strlen($auto_increment) > 0
893 && ($is_myisam_or_aria || $is_innodb || $is_pbxt)
895 $html_output .= '<tr><td>'
896 . '<label for="auto_increment_opt">AUTO_INCREMENT</label></td>'
897 . '<td><input type="text" name="new_auto_increment" '
898 . 'id="auto_increment_opt"'
899 . 'value="' . $auto_increment . '" /></td>'
900 . '</tr> ';
901 } // end if (MYISAM|INNODB)
903 $possible_row_formats = PMA_getPossibleRowFormat();
905 // for MYISAM there is also COMPRESSED but it can be set only by the
906 // myisampack utility, so don't offer here the choice because if we
907 // try it inside an ALTER TABLE, MySQL (at least in 5.1.23-maria)
908 // does not return a warning
909 // (if the table was compressed, it can be seen on the Structure page)
911 if (isset($possible_row_formats[$tbl_storage_engine])) {
912 $current_row_format = strtoupper($GLOBALS['showtable']['Row_format']);
913 $html_output .= '<tr><td>'
914 . '<label for="new_row_format">ROW_FORMAT</label></td>'
915 . '<td>';
916 $html_output .= PMA_Util::getDropdown(
917 'new_row_format', $possible_row_formats[$tbl_storage_engine],
918 $current_row_format, 'new_row_format'
920 $html_output .= '</td></tr>';
922 $html_output .= '</table>'
923 . '</fieldset>';
925 return $html_output;
929 * Get the common HTML table row (tr) for new_checksum, new_delay_key_write,
930 * new_transactional and new_page_checksum
932 * @param string $attribute class, name and id attribute
933 * @param string $label label value
934 * @param string $val checksum, delay_key_write, transactional, page_checksum
936 * @return string $html_output
938 function PMA_getHtmlForTableRow($attribute, $label, $val)
940 return '<tr>'
941 . '<td><label for="' . $attribute . '">' . $label . '</label></td>'
942 . '<td><input type="checkbox" name="'. $attribute .'"'
943 . ' id="' . $attribute .'"'
944 . ' value="1"'
945 . ((!empty($val) && $val == 1) ? ' checked="checked"' : '') . '/></td>'
946 . '</tr>';
950 * Get array of possible row formats
952 * @return array $possible_row_formats
954 function PMA_getPossibleRowFormat()
956 // the outer array is for engines, the inner array contains the dropdown
957 // option values as keys then the dropdown option labels
959 $possible_row_formats = array(
960 'ARIA' => array(
961 'FIXED' => 'FIXED',
962 'DYNAMIC' => 'DYNAMIC',
963 'PAGE' => 'PAGE'
965 'MARIA' => array(
966 'FIXED' => 'FIXED',
967 'DYNAMIC' => 'DYNAMIC',
968 'PAGE' => 'PAGE'
970 'MYISAM' => array(
971 'FIXED' => 'FIXED',
972 'DYNAMIC' => 'DYNAMIC'
974 'PBXT' => array(
975 'FIXED' => 'FIXED',
976 'DYNAMIC' => 'DYNAMIC'
978 'INNODB' => array(
979 'COMPACT' => 'COMPACT',
980 'REDUNDANT' => 'REDUNDANT'
984 $innodb_engine_plugin = PMA_StorageEngine::getEngine('innodb');
985 $innodb_plugin_version = $innodb_engine_plugin->getInnodbPluginVersion();
986 if (!empty($innodb_plugin_version)) {
987 $innodb_file_format = $innodb_engine_plugin->getInnodbFileFormat();
988 } else {
989 $innodb_file_format = '';
991 if ('Barracuda' == $innodb_file_format
992 && $innodb_engine_plugin->supportsFilePerTable()
994 $possible_row_formats['INNODB']['DYNAMIC'] = 'DYNAMIC';
995 $possible_row_formats['INNODB']['COMPRESSED'] = 'COMPRESSED';
998 return $possible_row_formats;
1002 * Get HTML div for copy table
1004 * @return string $html_output
1006 function PMA_getHtmlForCopytable()
1008 $html_output = '<div class="operations_half_width">';
1009 $html_output .= '<form method="post" action="tbl_operations.php" '
1010 . 'name="copyTable" '
1011 . 'id="copyTable" '
1012 . ' class="ajax" '
1013 . 'onsubmit="return emptyFormElements(this, \'new_name\')">'
1014 . PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table'])
1015 . '<input type="hidden" name="reload" value="1" />';
1017 $html_output .= '<fieldset>';
1018 $html_output .= '<legend>'
1019 . __('Copy table to (database<b>.</b>table):') . '</legend>';
1021 if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
1022 $html_output .= '<input type="text" maxlength="100" '
1023 . 'size="30" name="target_db" '
1024 . 'value="'. htmlspecialchars($GLOBALS['db']) . '"/>';
1025 } else {
1026 $html_output .= '<select name="target_db">'
1027 . $GLOBALS['pma']->databases->getHtmlOptions(true, false)
1028 . '</select>';
1030 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
1031 $html_output .= '<input type="text" size="20" name="new_name" '
1032 . 'onfocus="this.select()" '
1033 . 'value="'. htmlspecialchars($GLOBALS['table']) . '"/><br />';
1035 $choices = array(
1036 'structure' => __('Structure only'),
1037 'data' => __('Structure and data'),
1038 'dataonly' => __('Data only'));
1040 $html_output .= PMA_Util::getRadioFields(
1041 'what', $choices, 'data', true
1044 $html_output .= '<input type="checkbox" name="drop_if_exists" '
1045 . 'value="true" id="checkbox_drop" />'
1046 . '<label for="checkbox_drop">'
1047 . sprintf(__('Add %s'), 'DROP TABLE') . '</label><br />'
1048 . '<input type="checkbox" name="sql_auto_increment" '
1049 . 'value="1" id="checkbox_auto_increment_cp" />'
1050 . '<label for="checkbox_auto_increment_cp">'
1051 . __('Add AUTO_INCREMENT value') . '</label><br />';
1053 // display "Add constraints" choice only if there are
1054 // foreign keys
1055 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
1056 $html_output .= '<input type="checkbox" name="add_constraints" '
1057 . 'value="1" id="checkbox_constraints" />';
1058 $html_output .= '<label for="checkbox_constraints">'
1059 .__('Add constraints') . '</label><br />';
1060 } // endif
1062 if (isset($_COOKIE['pma_switch_to_new'])
1063 && $_COOKIE['pma_switch_to_new'] == 'true'
1065 $pma_switch_to_new = 'true';
1068 $html_output .= '<input type="checkbox" name="switch_to_new" value="true"'
1069 . 'id="checkbox_switch"'
1070 . ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true')
1071 ? ' checked="checked"'
1072 : '' . '/>');
1073 $html_output .= '<label for="checkbox_switch">'
1074 . __('Switch to copied table') . '</label>'
1075 . '</fieldset>';
1077 $html_output .= '<fieldset class="tblFooters">'
1078 . '<input type="submit" name="submit_copy" value="' .__('Go') . '" />'
1079 . '</fieldset>'
1080 . '</form>'
1081 . '</div>';
1083 return $html_output;
1087 * Get HTML snippet for table maintence
1089 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
1090 * @param boolean $is_innodb whether innodb or not
1091 * @param boolean $is_berkeleydb whether berkeleydb or not
1092 * @param array $url_params array of URL parameters
1094 * @return string $html_output
1096 function PMA_getHtmlForTableMaintenance(
1097 $is_myisam_or_aria, $is_innodb, $is_berkeleydb, $url_params
1099 $html_output = '<div class="operations_half_width">';
1100 $html_output .= '<fieldset>'
1101 . '<legend>' . __('Table maintenance') . '</legend>';
1102 $html_output .= '<ul id="tbl_maintenance">';
1104 // Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
1105 $html_output .= PMA_getListofMaintainActionLink(
1106 $is_myisam_or_aria, $is_innodb, $url_params, $is_berkeleydb
1109 $html_output .= '</ul>'
1110 . '</fieldset>'
1111 . '</div>';
1113 return $html_output;
1117 * Get HTML 'li' having a link of maintain action
1119 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
1120 * @param boolean $is_innodb whether innodb or not
1121 * @param array $url_params array of URL parameters
1122 * @param boolean $is_berkeleydb whether berkeleydb or not
1124 * @return string $html_output
1126 function PMA_getListofMaintainActionLink($is_myisam_or_aria,
1127 $is_innodb, $url_params, $is_berkeleydb
1129 $html_output = '';
1131 if ($is_myisam_or_aria || $is_innodb || $is_berkeleydb) {
1132 if ($is_myisam_or_aria || $is_innodb) {
1133 $params = array(
1134 'sql_query' => 'CHECK TABLE '
1135 . PMA_Util::backquote($GLOBALS['table']),
1136 'table_maintenance' => 'Go',
1138 $html_output .= PMA_getMaintainActionlink(
1139 __('Check table'),
1140 $params,
1141 $url_params,
1142 'CHECK_TABLE'
1145 if ($is_innodb) {
1146 $params = array(
1147 'sql_query' => 'ALTER TABLE '
1148 . PMA_Util::backquote($GLOBALS['table'])
1149 . ' ENGINE = InnoDB;'
1151 $html_output .= PMA_getMaintainActionlink(
1152 __('Defragment table'),
1153 $params,
1154 $url_params,
1155 'InnoDB_File_Defragmenting',
1156 'Table_types'
1159 if ($is_innodb || $is_myisam_or_aria || $is_berkeleydb) {
1160 $params = array(
1161 'sql_query' => 'ANALYZE TABLE '
1162 . PMA_Util::backquote($GLOBALS['table']),
1163 'table_maintenance' => 'Go',
1165 $html_output .= PMA_getMaintainActionlink(
1166 __('Analyze table'),
1167 $params,
1168 $url_params,
1169 'ANALYZE_TABLE'
1172 if ($is_myisam_or_aria && !PMA_DRIZZLE) {
1173 $params = array(
1174 'sql_query' => 'REPAIR TABLE '
1175 . PMA_Util::backquote($GLOBALS['table']),
1176 'table_maintenance' => 'Go',
1178 $html_output .= PMA_getMaintainActionlink(
1179 __('Repair table'),
1180 $params,
1181 $url_params,
1182 'REPAIR_TABLE'
1185 if (($is_myisam_or_aria || $is_innodb || $is_berkeleydb)
1186 && !PMA_DRIZZLE
1188 $params = array(
1189 'sql_query' => 'OPTIMIZE TABLE '
1190 . PMA_Util::backquote($GLOBALS['table']),
1191 'table_maintenance' => 'Go',
1193 $html_output .= PMA_getMaintainActionlink(
1194 __('Optimize table'),
1195 $params,
1196 $url_params,
1197 'OPTIMIZE_TABLE'
1200 } // end MYISAM or BERKELEYDB case
1202 $params = array(
1203 'sql_query' => 'FLUSH TABLE '
1204 . PMA_Util::backquote($GLOBALS['table']),
1205 'message_to_show' => sprintf(
1206 __('Table %s has been flushed'),
1207 htmlspecialchars($GLOBALS['table'])
1209 'reload' => 1,
1212 $html_output .= PMA_getMaintainActionlink(
1213 __('Flush the table (FLUSH)'),
1214 $params,
1215 $url_params,
1216 'FLUSH'
1219 return $html_output;
1223 * Get maintain action HTML link
1225 * @param string $action
1226 * @param array $params url parameters array
1227 * @param array $url_params
1228 * @param string $link contains name of page/anchor that is being linked
1229 * @param string $chapter chapter of "HTML, one page per chapter" documentation
1231 * @return string $html_output
1233 function PMA_getMaintainActionlink($action, $params, $url_params, $link,
1234 $chapter = 'MySQL_Database_Administration'
1236 return '<li>'
1237 . '<a class="maintain_action ajax" '
1238 . 'href="sql.php'
1239 . PMA_generate_common_url(array_merge($url_params, $params)) .'">'
1240 . $action
1241 . '</a>'
1242 . PMA_Util::showMySQLDocu($chapter, $link)
1243 . '</li>';
1247 * Get HTML for Delete data or table (truncate table, drop table)
1249 * @param array $truncate_table_url_params url parameter array for truncate table
1250 * @param array $drop_table_url_params url parameter array for drop table
1252 * @return string $html_output
1254 function PMA_getHtmlForDeleteDataOrTable(
1255 $truncate_table_url_params,
1256 $drop_table_url_params
1258 $html_output = '<div class="operations_half_width">'
1259 . '<fieldset class="caution">'
1260 . '<legend>' . __('Delete data or table') . '</legend>';
1262 $html_output .= '<ul>';
1264 if (! empty($truncate_table_url_params)) {
1265 $html_output .= PMA_getDeleteDataOrTablelink(
1266 $truncate_table_url_params,
1267 'TRUNCATE_TABLE',
1268 __('Empty the table (TRUNCATE)'),
1269 'truncate_tbl_anchor'
1272 if (!empty ($drop_table_url_params)) {
1273 $html_output .= PMA_getDeleteDataOrTablelink(
1274 $drop_table_url_params,
1275 'DROP_TABLE',
1276 __('Delete the table (DROP)'),
1277 'drop_tbl_anchor'
1280 $html_output .= '</ul></fieldset></div>';
1282 return $html_output;
1286 * Get the HTML link for Truncate table, Drop table and Drop db
1288 * @param array $url_params url parameter array for delete data or table
1289 * @param string $syntax TRUNCATE_TABLE or DROP_TABLE or DROP_DATABASE
1290 * @param string $link link to be shown
1291 * @param string $id id of the link
1293 * @return String html output
1295 function PMA_getDeleteDataOrTablelink($url_params, $syntax, $link, $id)
1297 return '<li><a '
1298 . 'href="sql.php' . PMA_generate_common_url($url_params) . '"'
1299 . ' id="' . $id . '" class="ajax">'
1300 . $link . '</a>'
1301 . PMA_Util::showMySQLDocu(
1302 'SQL-Syntax', $syntax
1304 . '</li>';
1308 * Get HTML snippet for partition maintenance
1310 * @param array $partition_names array of partition names for a specific db/table
1311 * @param array $url_params url parameters
1313 * @return string $html_output
1315 function PMA_getHtmlForPartitionMaintenance($partition_names, $url_params)
1317 $choices = array(
1318 'ANALYZE' => __('Analyze'),
1319 'CHECK' => __('Check'),
1320 'OPTIMIZE' => __('Optimize'),
1321 'REBUILD' => __('Rebuild'),
1322 'REPAIR' => __('Repair')
1325 $html_output = '<div class="operations_half_width">'
1326 . '<form method="post" action="tbl_operations.php">'
1327 . PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table'])
1328 . '<fieldset>'
1329 . '<legend>' . __('Partition maintenance') . '</legend>';
1331 $html_select = '<select name="partition_name">' . "\n";
1332 foreach ($partition_names as $one_partition) {
1333 $one_partition = htmlspecialchars($one_partition);
1334 $html_select .= '<option value="' . $one_partition . '">'
1335 . $one_partition . '</option>' . "\n";
1337 $html_select .= '</select>' . "\n";
1338 $html_output .= sprintf(__('Partition %s'), $html_select);
1340 $html_output .= PMA_Util::getRadioFields(
1341 'partition_operation', $choices, '', false
1343 $html_output .= PMA_Util::showMySQLDocu(
1344 'partitioning_maintenance',
1345 'partitioning_maintenance'
1347 $this_url_params = array_merge(
1348 $url_params,
1349 array(
1350 'sql_query' => 'ALTER TABLE '
1351 . PMA_Util::backquote($GLOBALS['table'])
1352 . ' REMOVE PARTITIONING;'
1355 $html_output .= '<br /><a href="sql.php'
1356 . PMA_generate_common_url($this_url_params) . '">'
1357 . __('Remove partitioning') . '</a>';
1359 $html_output .= '</fieldset>'
1360 . '<fieldset class="tblFooters">'
1361 . '<input type="submit" name="submit_partition" '
1362 . 'value="' . __('Go') . '" />'
1363 . '</fieldset>'
1364 . '</form>'
1365 . '</div>';
1367 return $html_output;
1371 * Get the HTML for Referential Integrity check
1373 * @param array $foreign all Relations to foreign tables for a given table
1374 * or optionally a given column in a table
1375 * @param array $url_params array of url parameters
1377 * @return string $html_output
1379 function PMA_getHtmlForReferentialIntegrityCheck($foreign, $url_params)
1381 $html_output = '<div class="operations_half_width">'
1382 . '<fieldset>'
1383 . '<legend>' . __('Check referential integrity:') . '</legend>';
1385 $html_output .= '<ul>';
1387 foreach ($foreign AS $master => $arr) {
1388 $join_query = 'SELECT '
1389 . PMA_Util::backquote($GLOBALS['table']) . '.*'
1390 . ' FROM ' . PMA_Util::backquote($GLOBALS['table'])
1391 . ' LEFT JOIN '
1392 . PMA_Util::backquote($arr['foreign_db'])
1393 . '.'
1394 . PMA_Util::backquote($arr['foreign_table']);
1395 if ($arr['foreign_table'] == $GLOBALS['table']) {
1396 $foreign_table = $GLOBALS['table'] . '1';
1397 $join_query .= ' AS ' . PMA_Util::backquote($foreign_table);
1398 } else {
1399 $foreign_table = $arr['foreign_table'];
1401 $join_query .= ' ON '
1402 . PMA_Util::backquote($GLOBALS['table']) . '.'
1403 . PMA_Util::backquote($master)
1404 . ' = '
1405 . PMA_Util::backquote($arr['foreign_db'])
1406 . '.'
1407 . PMA_Util::backquote($foreign_table) . '.'
1408 . PMA_Util::backquote($arr['foreign_field'])
1409 . ' WHERE '
1410 . PMA_Util::backquote($arr['foreign_db'])
1411 . '.'
1412 . PMA_Util::backquote($foreign_table) . '.'
1413 . PMA_Util::backquote($arr['foreign_field'])
1414 . ' IS NULL AND '
1415 . PMA_Util::backquote($GLOBALS['table']) . '.'
1416 . PMA_Util::backquote($master)
1417 . ' IS NOT NULL';
1418 $this_url_params = array_merge(
1419 $url_params,
1420 array('sql_query' => $join_query)
1423 $html_output .= '<li>'
1424 . '<a href="sql.php'
1425 . PMA_generate_common_url($this_url_params)
1426 . '">'
1427 . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.'
1428 . $arr['foreign_field']
1429 . '</a></li>' . "\n";
1430 } // foreach $foreign
1431 $html_output .= '</ul></fieldset></div>';
1433 return $html_output;
1436 function PMA_getQueryAndResultForReorderingTable()
1438 $sql_query = 'ALTER TABLE '
1439 . PMA_Util::backquote($GLOBALS['table'])
1440 . ' ORDER BY '
1441 . PMA_Util::backquote(urldecode($_REQUEST['order_field']));
1442 if (isset($_REQUEST['order_order'])
1443 && $_REQUEST['order_order'] === 'desc'
1445 $sql_query .= ' DESC';
1447 $sql_query .= ';';
1448 $result = PMA_DBI_query($sql_query);
1450 return array($sql_query, $result);
1454 * Get table alters array
1456 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
1457 * @param boolean $is_isam whether ISAM or not
1458 * @param string $pack_keys pack keys
1459 * @param string $checksum value of checksum
1460 * @param boolean $is_aria whether ARIA or not
1461 * @param string $page_checksum value of page checksum
1462 * @param string $delay_key_write delay key write
1463 * @param boolean $is_innodb whether INNODB or not
1464 * @param boolean $is_pbxt whether PBXT or not
1465 * @param string $row_format row format
1466 * @param string $tbl_storage_engine table storage engine
1467 * @param string $transactional value of transactional
1468 * @param string $tbl_collation collation of the table
1470 * @return array $table_alters
1472 function PMA_getTableAltersArray($is_myisam_or_aria, $is_isam, $pack_keys,
1473 $checksum, $is_aria, $page_checksum, $delay_key_write, $is_innodb,
1474 $is_pbxt, $row_format, $new_tbl_storage_engine, $transactional, $tbl_collation
1476 global $auto_increment;
1478 $table_alters = array();
1480 if (isset($_REQUEST['comment'])
1481 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']
1483 $table_alters[] = 'COMMENT = \''
1484 . PMA_Util::sqlAddSlashes($_REQUEST['comment']) . '\'';
1486 if (! empty($new_tbl_storage_engine)
1487 && strtolower($new_tbl_storage_engine) !== strtolower($GLOBALS['tbl_storage_engine'])
1489 $table_alters[] = 'ENGINE = ' . $new_tbl_storage_engine;
1491 if (! empty($_REQUEST['tbl_collation'])
1492 && $_REQUEST['tbl_collation'] !== $tbl_collation
1494 $table_alters[] = 'DEFAULT '
1495 . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
1498 if (($is_myisam_or_aria || $is_isam)
1499 && isset($_REQUEST['new_pack_keys'])
1500 && $_REQUEST['new_pack_keys'] != (string)$pack_keys
1502 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
1505 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
1506 if ($is_myisam_or_aria
1507 && $_REQUEST['new_checksum'] !== $checksum
1509 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
1512 $_REQUEST['new_transactional']
1513 = empty($_REQUEST['new_transactional']) ? '0' : '1';
1514 if ($is_aria
1515 && $_REQUEST['new_transactional'] !== $transactional
1517 $table_alters[] = 'TRANSACTIONAL = ' . $_REQUEST['new_transactional'];
1520 $_REQUEST['new_page_checksum']
1521 = empty($_REQUEST['new_page_checksum']) ? '0' : '1';
1522 if ($is_aria
1523 && $_REQUEST['new_page_checksum'] !== $page_checksum
1525 $table_alters[] = 'PAGE_CHECKSUM = ' . $_REQUEST['new_page_checksum'];
1528 $_REQUEST['new_delay_key_write']
1529 = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
1530 if ($is_myisam_or_aria
1531 && $_REQUEST['new_delay_key_write'] !== $delay_key_write
1533 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
1536 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
1537 && ! empty($_REQUEST['new_auto_increment'])
1538 && (! isset($auto_increment)
1539 || $_REQUEST['new_auto_increment'] !== $auto_increment)
1541 $table_alters[] = 'auto_increment = '
1542 . PMA_Util::sqlAddSlashes($_REQUEST['new_auto_increment']);
1545 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
1546 && ! empty($_REQUEST['new_row_format'])
1547 && (!strlen($row_format)
1548 || strtolower($_REQUEST['new_row_format']) !== strtolower($row_format))
1550 $table_alters[] = 'ROW_FORMAT = '
1551 . PMA_Util::sqlAddSlashes($_REQUEST['new_row_format']);
1554 return $table_alters;
1558 * set initial value of the set of variables, based on the current table engine
1560 * @param string $tbl_storage_engine table storage engine
1562 * @return array ($is_myisam_or_aria, $is_innodb, $is_isam,
1563 * $is_berkeleydb, $is_aria, $is_pbxt)
1565 function PMA_setGlobalVariablesForEngine($tbl_storage_engine)
1567 $is_myisam_or_aria = $is_isam = $is_innodb = $is_berkeleydb
1568 = $is_aria = $is_pbxt = false;
1569 $upper_tbl_storage_engine = strtoupper($tbl_storage_engine);
1571 //Options that apply to MYISAM usually apply to ARIA
1572 $is_myisam_or_aria = ($upper_tbl_storage_engine == 'MYISAM'
1573 || $upper_tbl_storage_engine == 'ARIA'
1574 || $upper_tbl_storage_engine == 'MARIA'
1576 $is_aria = ($upper_tbl_storage_engine == 'ARIA');
1578 $is_isam = ($upper_tbl_storage_engine == 'ISAM');
1579 $is_innodb = ($upper_tbl_storage_engine == 'INNODB');
1580 $is_berkeleydb = ($upper_tbl_storage_engine == 'BERKELEYDB');
1581 $is_pbxt = ($upper_tbl_storage_engine == 'PBXT');
1583 return array(
1584 $is_myisam_or_aria, $is_innodb, $is_isam,
1585 $is_berkeleydb, $is_aria, $is_pbxt
1590 * Get warning messages array
1592 * @return array $warning_messages
1594 function PMA_getWarningMessagesArray()
1596 $warning_messages = array();
1597 foreach (PMA_DBI_get_warnings() as $warning) {
1598 // In MariaDB 5.1.44, when altering a table from Maria to MyISAM
1599 // and if TRANSACTIONAL was set, the system reports an error;
1600 // I discussed with a Maria developer and he agrees that this
1601 // should not be reported with a Level of Error, so here
1602 // I just ignore it. But there are other 1478 messages
1603 // that it's better to show.
1604 if (! ($_REQUEST['new_tbl_storage_engine'] == 'MyISAM'
1605 && $warning['Code'] == '1478'
1606 && $warning['Level'] == 'Error')
1608 $warning_messages[] = $warning['Level'] . ': #' . $warning['Code']
1609 . ' ' . $warning['Message'];
1612 return $warning_messages;
1616 * Get SQL query and result after ran this SQL query for a partition operation
1617 * has been requested by the user
1619 * @return array $sql_query, $result
1621 function PMA_getQueryAndResultForPartition()
1623 $sql_query = 'ALTER TABLE '
1624 . PMA_Util::backquote($GLOBALS['table']) . ' '
1625 . $_REQUEST['partition_operation']
1626 . ' PARTITION '
1627 . $_REQUEST['partition_name'] . ';';
1628 $result = PMA_DBI_query($sql_query);
1630 return array($sql_query, $result);