Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / operations.lib.php
blob94be5a2ebd2f01d8c5cbc60ff104efb2cb336992
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 ($GLOBALS['cfg']['PropertiesIconic']) {
29 $html_output .= '<img class="icon ic_b_comment" '
30 . 'src="themes/dot.gif" alt="" />';
32 $html_output .= __('Database comment: ');
33 $html_output .= '</legend>';
34 $html_output .= '<input type="text" name="comment" '
35 . 'class="textfield" size="30"'
36 . 'value="' . htmlspecialchars(PMA_getDBComment($db)) . '" />'
37 . '</fieldset>';
38 $html_output .= '<fieldset class="tblFooters">'
39 . '<input type="submit" value="' . __('Go') . '" />'
40 . '</fieldset>'
41 . '</form>'
42 . '</div>';
44 return $html_output;
47 /**
48 * Get HTML output for rename database
50 * @param string $db database name
52 * @return string $html_output
54 function PMA_getHtmlForRenameDatabase($db)
56 $html_output = '<div class="operations_half_width">'
57 . '<form id="rename_db_form" '
58 . 'class="ajax" '
59 . 'method="post" action="db_operations.php" '
60 . 'onsubmit="return emptyFormElements(this, \'newname\')">';
61 if (isset($_REQUEST['db_collation'])) {
62 $html_output .= '<input type="hidden" name="db_collation" '
63 . 'value="' . $_REQUEST['db_collation']
64 .'" />' . "\n";
66 $html_output .= '<input type="hidden" name="what" value="data" />'
67 . '<input type="hidden" name="db_rename" value="true" />'
68 . PMA_generate_common_hidden_inputs($db)
69 . '<fieldset>'
70 . '<legend>';
72 if ($GLOBALS['cfg']['PropertiesIconic']) {
73 $html_output .= PMA_Util::getImage('b_edit.png');
75 $html_output .= __('Rename database to') . ':'
76 . '</legend>';
78 $html_output .= '<input id="new_db_name" type="text" name="newname" '
79 . 'size="30" class="textfield" value="" />'
80 . '</fieldset>'
81 . '<fieldset class="tblFooters">'
82 . '<input id="rename_db_input" type="submit" value="' . __('Go') . '" />'
83 . '</fieldset>'
84 . '</form>'
85 . '</div>';
87 return $html_output;
90 /**
91 * Get HTML for database drop link
93 * @param string $db database name
95 * @return string $html_output
97 function PMA_getHtmlForDropDatabaseLink($db)
99 $this_sql_query = 'DROP DATABASE ' . PMA_Util::backquote($db);
100 $this_url_params = array(
101 'sql_query' => $this_sql_query,
102 'back' => 'db_operations.php',
103 'goto' => 'index.php',
104 'reload' => '1',
105 'purge' => '1',
106 'message_to_show' => sprintf(
107 __('Database %s has been dropped.'),
108 htmlspecialchars(PMA_Util::backquote($db))
110 'db' => null,
113 $html_output = '<div class="operations_half_width">'
114 . '<fieldset class="caution">';
115 $html_output .= '<legend>';
116 if ($GLOBALS['cfg']['PropertiesIconic']) {
117 $html_output .= PMA_Util::getImage('b_deltbl.png');
119 $html_output .= __('Remove database')
120 . '</legend>';
121 $html_output .= '<ul>';
122 $html_output .= PMA_getDeleteDataOrTablelink(
123 $this_url_params,
124 'DROP_DATABASE',
125 __('Drop the database (DROP)'),
126 'drop_db_anchor'
128 $html_output .= '</ul></fieldset>'
129 . '</div>';
131 return $html_output;
135 * Get HTML snippet for copy database
137 * @param string $db database name
139 * @return string $html_output
141 function PMA_getHtmlForCopyDatabase($db)
143 $drop_clause = 'DROP TABLE / DROP VIEW';
144 $choices = array(
145 'structure' => __('Structure only'),
146 'data' => __('Structure and data'),
147 'dataonly' => __('Data only')
150 if (isset($_COOKIE)
151 && isset($_COOKIE['pma_switch_to_new'])
152 && $_COOKIE['pma_switch_to_new'] == 'true'
154 $pma_switch_to_new = 'true';
157 $html_output = '<div class="operations_half_width clearfloat">';
158 $html_output .= '<form id="copy_db_form" '
159 . 'class="ajax" '
160 . 'method="post" action="db_operations.php"'
161 . 'onsubmit="return emptyFormElements(this, \'newname\')">';
163 if (isset($_REQUEST['db_collation'])) {
164 $html_output .= '<input type="hidden" name="db_collation" '
165 . 'value="' . $_REQUEST['db_collation'] .'" />' . "\n";
167 $html_output .= '<input type="hidden" name="db_copy" value="true" />' . "\n"
168 . PMA_generate_common_hidden_inputs($db);
169 $html_output .= '<fieldset>'
170 . '<legend>';
172 if ($GLOBALS['cfg']['PropertiesIconic']) {
173 $html_output .= PMA_Util::getImage('b_edit.png');
175 $html_output .= __('Copy database to') . ':'
176 . '</legend>'
177 . '<input type="text" name="newname" size="30" '
178 . 'class="textfield" value="" /><br />'
179 . PMA_Util::getRadioFields(
180 'what', $choices, 'data', true
182 $html_output .= '<input type="checkbox" name="create_database_before_copying" '
183 . 'value="1" id="checkbox_create_database_before_copying"'
184 . 'checked="checked" />';
185 $html_output .= '<label for="checkbox_create_database_before_copying">'
186 . __('CREATE DATABASE before copying') . '</label><br />';
187 $html_output .= '<input type="checkbox" name="drop_if_exists" value="true"'
188 . 'id="checkbox_drop" />';
189 $html_output .= '<label for="checkbox_drop">'
190 . sprintf(__('Add %s'), $drop_clause)
191 . '</label><br />';
192 $html_output .= '<input type="checkbox" name="sql_auto_increment" value="1" '
193 . 'checked="checked" id="checkbox_auto_increment" />';
194 $html_output .= '<label for="checkbox_auto_increment">'
195 . __('Add AUTO_INCREMENT value') . '</label><br />';
196 $html_output .= '<input type="checkbox" name="add_constraints" value="1"'
197 . 'id="checkbox_constraints" />';
198 $html_output .= '<label for="checkbox_constraints">'
199 . __('Add constraints') . '</label><br />';
200 $html_output .= '<input type="checkbox" name="switch_to_new" value="true"'
201 . 'id="checkbox_switch"'
202 . ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true')
203 ? ' checked="checked"'
204 : '')
205 . '/>';
206 $html_output .= '<label for="checkbox_switch">'
207 . __('Switch to copied database') . '</label>'
208 . '</fieldset>';
209 $html_output .= '<fieldset class="tblFooters">'
210 . '<input type="submit" name="submit_copy" value="' . __('Go') . '" />'
211 . '</fieldset>'
212 . '</form>'
213 . '</div>';
215 return $html_output;
219 * Get HTML snippet for change database charset
221 * @param string $db database name
222 * @param string $table tabel name
224 * @return string $html_output
226 function PMA_getHtmlForChangeDatabaseCharset($db, $table)
228 $html_output = '<div class="operations_half_width">'
229 . '<form id="change_db_charset_form" ';
230 $html_output .= 'class="ajax" ';
231 $html_output .= 'method="post" action="db_operations.php">';
233 $html_output .= PMA_generate_common_hidden_inputs($db, $table);
235 $html_output .= '<fieldset>' . "\n"
236 . ' <legend>';
237 if ($GLOBALS['cfg']['PropertiesIconic']) {
238 $html_output .= PMA_Util::getImage('s_asci.png');
240 $html_output .= '<label for="select_db_collation">' . __('Collation')
241 . ':</label>' . "\n"
242 . '</legend>' . "\n"
243 . PMA_generateCharsetDropdownBox(
244 PMA_CSDROPDOWN_COLLATION,
245 'db_collation',
246 'select_db_collation',
247 isset($_REQUEST['db_collation']) ? $_REQUEST['db_collation'] : '',
248 false,
251 . '</fieldset>'
252 . '<fieldset class="tblFooters">'
253 . '<input type="submit" name="submitcollation"'
254 . ' value="' . __('Go') . '" />' . "\n"
255 . '</fieldset>' . "\n"
256 . '</form></div>' . "\n";
258 return $html_output;
262 * Get HTML snippet for export relational schema view
264 * @param string $url_query
266 * @return string $html_output
268 function PMA_getHtmlForExportRelationalSchemaView($url_query)
270 $html_output = '<div class="operations_full_width">'
271 . '<fieldset><a href="schema_edit.php?' . $url_query . '">';
272 if ($GLOBALS['cfg']['PropertiesIconic']) {
273 $html_output .= PMA_Util::getImage(
274 'b_edit.png'
277 $html_output .= __('Edit or export relational schema')
278 . '</a></fieldset>'
279 . '</div>';
281 return $html_output;
285 * Run the Procedure definitions and function definitions
287 * to avoid selecting alternatively the current and new db
288 * we would need to modify the CREATE definitions to qualify
289 * the db name
291 * @param string $db database name
293 * @return void
295 function PMA_runProcedureAndFunctionDefinitions($db)
297 $procedure_names = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE');
298 if ($procedure_names) {
299 foreach ($procedure_names as $procedure_name) {
300 PMA_DBI_select_db($db);
301 $tmp_query = PMA_DBI_get_definition(
302 $db, 'PROCEDURE', $procedure_name
304 // collect for later display
305 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
306 PMA_DBI_select_db($_REQUEST['newname']);
307 PMA_DBI_query($tmp_query);
311 $function_names = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION');
312 if ($function_names) {
313 foreach ($function_names as $function_name) {
314 PMA_DBI_select_db($db);
315 $tmp_query = PMA_DBI_get_definition($db, 'FUNCTION', $function_name);
316 // collect for later display
317 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
318 PMA_DBI_select_db($_REQUEST['newname']);
319 PMA_DBI_query($tmp_query);
325 * Get sql query and create database before copy
327 * @return string $sql_query
329 function PMA_getSqlQueryAndCreateDbBeforeCopy()
331 // lower_case_table_names=1 `DB` becomes `db`
332 if (! PMA_DRIZZLE) {
333 $lower_case_table_names = PMA_DBI_fetch_value(
334 'SHOW VARIABLES LIKE "lower_case_table_names"', 0, 1
336 if ($lower_case_table_names === '1') {
337 $_REQUEST['newname'] = PMA_strtolower($_REQUEST['newname']);
341 $local_query = 'CREATE DATABASE IF NOT EXISTS '
342 . PMA_Util::backquote($_REQUEST['newname']);
343 if (isset($_REQUEST['db_collation'])) {
344 $local_query .= ' DEFAULT'
345 . PMA_generateCharsetQueryPart($_REQUEST['db_collation']);
347 $local_query .= ';';
348 $sql_query = $local_query;
349 // save the original db name because Tracker.class.php which
350 // may be called under PMA_DBI_query() changes $GLOBALS['db']
351 // for some statements, one of which being CREATE DATABASE
352 $original_db = $GLOBALS['db'];
353 PMA_DBI_query($local_query);
354 $GLOBALS['db'] = $original_db;
356 // rebuild the database list because PMA_Table::moveCopy
357 // checks in this list if the target db exists
358 $GLOBALS['pma']->databases->build();
360 return $sql_query;
364 * remove all foreign key constraints and return
365 * sql constraints query for full database
367 * @param array $tables_full array of all tables in given db or dbs
368 * @param object $export_sql_plugin export plugin instance
369 * @param boolean $move whether databse name is empty or not
370 * @param string $db database name
372 * @return string sql constraints query for full databases
374 function PMA_getSqlConstraintsQueryForFullDb(
375 $tables_full, $export_sql_plugin, $move, $db
377 $sql_constraints_query_full_db = array();
378 foreach ($tables_full as $each_table => $tmp) {
379 $sql_constraints = '';
380 $sql_drop_foreign_keys = '';
381 $sql_structure = $export_sql_plugin->getTableDef(
382 $db, $each_table, "\n", '', false, false
384 if ($move && ! empty($sql_drop_foreign_keys)) {
385 PMA_DBI_query($sql_drop_foreign_keys);
387 // keep the constraint we just dropped
388 if (! empty($sql_constraints)) {
389 $sql_constraints_query_full_db[] = $sql_constraints;
392 return $sql_constraints_query_full_db;
396 * Get views as an array and create SQL view stand-in
398 * @param array $tables_full array of all tables in given db or dbs
399 * @param object $export_sql_plugin export plugin instance
400 * @param strin $db database name
402 * @return array $views
404 function PMA_getViewsAndCreateSqlViewStandIn(
405 $tables_full, $export_sql_plugin, $db
407 $views = array();
408 foreach ($tables_full as $each_table => $tmp) {
409 // to be able to rename a db containing views,
410 // first all the views are collected and a stand-in is created
411 // the real views are created after the tables
412 if (PMA_Table::isView($db, $each_table)) {
413 $views[] = $each_table;
414 // Create stand-in definition to resolve view dependencies
415 $sql_view_standin = $export_sql_plugin->getTableDefStandIn(
416 $db, $each_table, "\n"
418 PMA_DBI_select_db($_REQUEST['newname']);
419 PMA_DBI_query($sql_view_standin);
420 $GLOBALS['sql_query'] .= "\n" . $sql_view_standin;
423 return $views;
427 * Get sql query for copy/rename table and boolean for whether copy/rename or not
429 * @param array $tables_full array of all tables in given db or dbs
430 * @param string $sql_query sql query for all operations
431 * @param boolean $move whether databse name is empty or not
432 * @param string $db database name
434 * @return array ($sql_query, $error)
436 function PMA_getSqlQueryForCopyTable($tables_full, $sql_query, $move, $db)
438 $error = false;
439 foreach ($tables_full as $each_table => $tmp) {
440 // skip the views; we have creted stand-in definitions
441 if (PMA_Table::isView($db, $each_table)) {
442 continue;
444 $back = $sql_query;
445 $sql_query = '';
447 // value of $what for this table only
448 $this_what = $_REQUEST['what'];
450 // do not copy the data from a Merge table
451 // note: on the calling FORM, 'data' means 'structure and data'
452 if (PMA_Table::isMerge($db, $each_table)) {
453 if ($this_what == 'data') {
454 $this_what = 'structure';
456 if ($this_what == 'dataonly') {
457 $this_what = 'nocopy';
461 if ($this_what != 'nocopy') {
462 // keep the triggers from the original db+table
463 // (third param is empty because delimiters are only intended
464 // for importing via the mysql client or our Import feature)
465 $triggers = PMA_DBI_get_triggers($db, $each_table, '');
467 if (! PMA_Table::moveCopy(
468 $db, $each_table, $_REQUEST['newname'], $each_table,
469 (isset($this_what) ? $this_what : 'data'),
470 $move, 'db_copy'
471 )) {
472 $error = true;
473 // $sql_query is filled by PMA_Table::moveCopy()
474 $sql_query = $back . $sql_query;
475 break;
477 // apply the triggers to the destination db+table
478 if ($triggers) {
479 PMA_DBI_select_db($_REQUEST['newname']);
480 foreach ($triggers as $trigger) {
481 PMA_DBI_query($trigger['create']);
482 $GLOBALS['sql_query'] .= "\n" . $trigger['create'] . ';';
486 // this does not apply to a rename operation
487 if (isset($_REQUEST['add_constraints'])
488 && ! empty($GLOBALS['sql_constraints_query'])
490 $GLOBALS['sql_constraints_query_full_db'][]
491 = $GLOBALS['sql_constraints_query'];
492 unset($GLOBALS['sql_constraints_query']);
495 // $sql_query is filled by PMA_Table::moveCopy()
496 $sql_query = $back . $sql_query;
498 return array($sql_query, $error);
502 * Run the EVENT definition for selected database
504 * to avoid selecting alternatively the current and new db
505 * we would need to modify the CREATE definitions to qualify
506 * the db name
508 * @param string $db database name
510 * @return void
512 function PMA_runEventDefinitionsForDb($db)
514 $event_names = PMA_DBI_fetch_result(
515 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \''
516 . PMA_Util::sqlAddSlashes($db, true) . '\';'
518 if ($event_names) {
519 foreach ($event_names as $event_name) {
520 PMA_DBI_select_db($db);
521 $tmp_query = PMA_DBI_get_definition($db, 'EVENT', $event_name);
522 // collect for later display
523 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
524 PMA_DBI_select_db($_REQUEST['newname']);
525 PMA_DBI_query($tmp_query);
531 * Handle the views, return the boolean value whether table rename/copy or not
533 * @param array $views views as an array
534 * @param boolean $move whether databse name is empty or not
535 * @param string $db database name
537 * @return boolean $_error whether table rename/copy or not
539 function PMA_handleTheViews($views, $move, $db)
541 $_error = false;
542 // temporarily force to add DROP IF EXIST to CREATE VIEW query,
543 // to remove stand-in VIEW that was created earlier
544 // ( $_REQUEST['drop_if_exists'] is used in moveCopy() )
545 if (isset($_REQUEST['drop_if_exists'])) {
546 $temp_drop_if_exists = $_REQUEST['drop_if_exists'];
548 $_REQUEST['drop_if_exists'] = 'true';
550 foreach ($views as $view) {
551 $copying_succeeded = PMA_Table::moveCopy(
552 $db, $view, $_REQUEST['newname'], $view, 'structure', $move, 'db_copy'
554 if (! $copying_succeeded) {
555 $_error = true;
556 break;
559 unset($_REQUEST['drop_if_exists']);
560 if (isset($temp_drop_if_exists)) {
561 // restore previous value
562 $_REQUEST['drop_if_exists'] = $temp_drop_if_exists;
564 return $_error;
568 * Create all accumulated constraaints
570 * @return void
572 function PMA_createAllAccumulatedConstraints()
574 PMA_DBI_select_db($_REQUEST['newname']);
575 foreach ($GLOBALS['sql_constraints_query_full_db'] as $one_query) {
576 PMA_DBI_query($one_query);
577 // and prepare to display them
578 $GLOBALS['sql_query'] .= "\n" . $one_query;
580 unset($GLOBALS['sql_constraints_query_full_db']);
584 * Duplicate the bookmarks for the db (done once for each db)
586 * @param boolean $_error whether table rename/copy or not
587 * @param string $db database name
589 * @return void
591 function PMA_duplicateBookmarks($_error, $db)
593 if (! $_error && $db != $_REQUEST['newname']) {
594 $get_fields = array('user', 'label', 'query');
595 $where_fields = array('dbase' => $db);
596 $new_fields = array('dbase' => $_REQUEST['newname']);
597 PMA_Table::duplicateInfo(
598 'bookmarkwork', 'bookmark', $get_fields,
599 $where_fields, $new_fields
605 * Get the HTML snippet for order the table
607 * @param array $columns columns array
609 * @return string $html_out
611 function PMA_getHtmlForOrderTheTable($columns)
613 $html_output = '<div class="operations_half_width">';
614 $html_output .= '<form method="post" id="alterTableOrderby" '
615 . 'action="tbl_operations.php">';
616 $html_output .= PMA_generate_common_hidden_inputs(
617 $GLOBALS['db'], $GLOBALS['table']
619 $html_output .= '<fieldset id="fieldset_table_order">'
620 . '<legend>' . __('Alter table order by') . '</legend>'
621 . '<select name="order_field">';
623 foreach ($columns as $fieldname) {
624 $html_output .= '<option '
625 . 'value="' . htmlspecialchars($fieldname['Field']) . '">'
626 . htmlspecialchars($fieldname['Field']) . '</option>' . "\n";
628 $html_output .= '</select> ' . __('(singly)') . ' '
629 . '<select name="order_order">'
630 . '<option value="asc">' . __('Ascending') . '</option>'
631 . '<option value="desc">' . __('Descending') . '</option>'
632 . '</select>'
633 . '</fieldset>'
634 . '<fieldset class="tblFooters">'
635 . '<input type="hidden" name="submitorderby" value="1" />'
636 . '<input type="submit" value="' . __('Go') . '" />'
637 . '</fieldset>'
638 . '</form>'
639 . '</div>';
641 return $html_output;
645 * Get the HTML snippet for move table
647 * @return string $html_output
649 function PMA_getHtmlForMoveTable()
651 $html_output = '<div class="operations_half_width">';
652 $html_output .= '<form method="post" action="tbl_operations.php"'
653 . ' id="moveTableForm" class="ajax"'
654 . ' onsubmit="return emptyFormElements(this, \'new_name\')">'
655 . PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']);
657 $html_output .= '<input type="hidden" name="reload" value="1" />'
658 . '<input type="hidden" name="what" value="data" />'
659 . '<fieldset id="fieldset_table_rename">';
661 $html_output .= '<legend>' . __('Move table to (database<b>.</b>table):')
662 . '</legend>';
664 if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
665 $html_output .= '<input type="text" maxlength="100" size="30" '
666 . 'name="target_db" value="' . htmlspecialchars($GLOBALS['db'])
667 . '"/>';
668 } else {
669 $html_output .= '<select name="target_db">'
670 . $GLOBALS['pma']->databases->getHtmlOptions(true, false)
671 . '</select>';
673 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
674 $html_output .= '<input type="text" size="20" name="new_name"'
675 . ' onfocus="this.select()"'
676 . 'value="' . htmlspecialchars($GLOBALS['table']) . '" /><br />';
678 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
679 // next value but users can decide if they want it or not for the operation
681 $html_output .= '<input type="checkbox" name="sql_auto_increment" '
682 . 'value="1" id="checkbox_auto_increment_mv" checked="checked" />'
683 . '<label for="checkbox_auto_increment_mv">'
684 . __('Add AUTO_INCREMENT value')
685 . '</label><br />'
686 . '</fieldset>';
688 $html_output .= '<fieldset class="tblFooters">'
689 . '<input type="submit" name="submit_move" value="' . __('Go') . '" />'
690 . '</fieldset>'
691 . '</form>'
692 . '</div>';
694 return $html_output;
698 * Get the HTML div for Table option
700 * @param string $comment Comment
701 * @param array $tbl_collation table collation
702 * @param string $tbl_storage_engine table storage engine
703 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
704 * @param boolean $is_isam whether ISAM or not
705 * @param array $pack_keys pack keys
706 * @param string $auto_increment value of auto increment
707 * @param string $delay_key_write delay key write
708 * @param string $transactional value of transactional
709 * @param string $page_checksum value of page checksum
710 * @param boolean $is_innodb whether INNODB or not
711 * @param boolean $is_pbxt whether PBXT or not
712 * @param boolean $is_aria whether ARIA or not
713 * @param string $checksum the checksum
715 * @return string $html_output
717 function PMA_getTableOptionDiv($comment, $tbl_collation, $tbl_storage_engine,
718 $is_myisam_or_aria, $is_isam, $pack_keys, $auto_increment, $delay_key_write,
719 $transactional, $page_checksum, $is_innodb, $is_pbxt, $is_aria, $checksum
721 $html_output = '<div class="operations_half_width clearfloat">';
722 $html_output .= '<form method="post" action="tbl_operations.php"';
723 $html_output .= ' id="tableOptionsForm" class="ajax">';
724 $html_output .= PMA_generate_common_hidden_inputs(
725 $GLOBALS['db'], $GLOBALS['table']
727 $html_output .= '<input type="hidden" name="reload" value="1" />';
729 $html_output .= PMA_getTableOptionFieldset(
730 $comment, $tbl_collation,
731 $tbl_storage_engine, $is_myisam_or_aria, $is_isam, $pack_keys,
732 $delay_key_write, $auto_increment, $transactional, $page_checksum,
733 $is_innodb, $is_pbxt, $is_aria, $checksum
736 $html_output .= '<fieldset class="tblFooters">'
737 . '<input type="hidden" name="submitoptions" value="1" />'
738 . '<input type="submit" value="' . __('Go') . '" />'
739 . '</fieldset>'
740 . '</form>'
741 . '</div>';
743 return $html_output;
747 * Get HTML fieldset for Table option, it contains HTML table for options
749 * @param string $comment Comment
750 * @param array $tbl_collation table collation
751 * @param string $tbl_storage_engine table storage engine
752 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
753 * @param boolean $is_isam whether ISAM or not
754 * @param array $pack_keys pack keys
755 * @param string $delay_key_write delay key write
756 * @param string $auto_increment value of auto increment
757 * @param string $transactional value of transactional
758 * @param string $page_checksum value of page checksum
759 * @param boolean $is_innodb whether INNODB or not
760 * @param boolean $is_pbxt whether PBXT or not
761 * @param boolean $is_aria whether ARIA or not
762 * @param string $checksum the checksum
764 * @return string $html_output
766 function PMA_getTableOptionFieldset($comment, $tbl_collation,
767 $tbl_storage_engine, $is_myisam_or_aria, $is_isam, $pack_keys,
768 $delay_key_write, $auto_increment, $transactional,
769 $page_checksum, $is_innodb, $is_pbxt, $is_aria, $checksum
771 $html_output = '<fieldset>'
772 . '<legend>' . __('Table options') . '</legend>';
774 $html_output .= '<table>';
775 //Change table name
776 $html_output .= '<tr><td>' . __('Rename table to') . '</td>'
777 . '<td>'
778 . '<input type="text" size="20" name="new_name" onfocus="this.select()"'
779 . 'value="' . htmlspecialchars($GLOBALS['table']) . '" />'
780 . '</td>'
781 . '</tr>';
783 //Table comments
784 $html_output .= '<tr><td>' . __('Table comments') . '</td>'
785 . '<td><input type="text" name="comment" maxlength="60" size="30"'
786 . 'value="' . htmlspecialchars($comment) . '" onfocus="this.select()" />'
787 . '<input type="hidden" name="prev_comment" value="'
788 . htmlspecialchars($comment) . '" />'
789 . '</td>'
790 . '</tr>';
792 //Storage engine
793 $html_output .= '<tr><td>' . __('Storage Engine')
794 . PMA_Util::showMySQLDocu(
795 'Storage_engines', 'Storage_engines'
797 . '</td>'
798 . '<td>'
799 . PMA_StorageEngine::getHtmlSelect(
800 'new_tbl_storage_engine', null, $tbl_storage_engine
802 . '</td>'
803 . '</tr>';
805 //Table character set
806 $html_output .= '<tr><td>' . __('Collation') . '</td>'
807 . '<td>'
808 . PMA_generateCharsetDropdownBox(
809 PMA_CSDROPDOWN_COLLATION,
810 'tbl_collation', null, $tbl_collation, false, 3
812 . '</td>'
813 . '</tr>';
815 if ($is_myisam_or_aria || $is_isam) {
816 $html_output .= '<tr>'
817 . '<td><label for="new_pack_keys">PACK_KEYS</label></td>'
818 . '<td><select name="new_pack_keys" id="new_pack_keys">';
820 $html_output .= '<option value="DEFAULT"';
821 if ($pack_keys == 'DEFAULT') {
822 $html_output .= 'selected="selected"';
824 $html_output .= '>DEFAULT</option>
825 <option value="0"';
826 if ($pack_keys == '0') {
827 $html_output .= 'selected="selected"';
829 $html_output .= '>0</option>
830 <option value="1" ';
831 if ($pack_keys == '1') {
832 $html_output .= 'selected="selected"';
834 $html_output .= '>1</option>'
835 . '</select>'
836 . '</td>'
837 . '</tr>';
838 } // end if (MYISAM|ISAM)
840 if ($is_myisam_or_aria) {
841 $html_output .= PMA_getHtmlForTableRow(
842 'new_checksum',
843 'CHECKSUM',
844 $checksum
847 $html_output .= PMA_getHtmlForTableRow(
848 'new_delay_key_write',
849 'DELAY_KEY_WRITE',
850 $delay_key_write
852 } // end if (MYISAM)
854 if ($is_aria) {
855 $html_output .= PMA_getHtmlForTableRow(
856 'new_transactional',
857 'TRANSACTIONAL',
858 $transactional
861 $html_output .= PMA_getHtmlForTableRow(
862 'new_page_checksum',
863 'PAGE_CHECKSUM',
864 $page_checksum
866 } // end if (ARIA)
868 if (strlen($auto_increment) > 0
869 && ($is_myisam_or_aria || $is_innodb || $is_pbxt)
871 $html_output .= '<tr><td>'
872 . '<label for="auto_increment_opt">AUTO_INCREMENT</label></td>'
873 . '<td><input type="text" name="new_auto_increment" '
874 . 'id="auto_increment_opt"'
875 . 'value="' . $auto_increment . '" /></td>'
876 . '</tr> ';
877 } // end if (MYISAM|INNODB)
879 $possible_row_formats = PMA_getPossibleRowFormat();
881 // for MYISAM there is also COMPRESSED but it can be set only by the
882 // myisampack utility, so don't offer here the choice because if we
883 // try it inside an ALTER TABLE, MySQL (at least in 5.1.23-maria)
884 // does not return a warning
885 // (if the table was compressed, it can be seen on the Structure page)
887 if (isset($possible_row_formats[$tbl_storage_engine])) {
888 $current_row_format = strtoupper($GLOBALS['showtable']['Row_format']);
889 $html_output .= '<tr><td>'
890 . '<label for="new_row_format">ROW_FORMAT</label></td>'
891 . '<td>';
892 $html_output .= PMA_Util::getDropdown(
893 'new_row_format', $possible_row_formats[$tbl_storage_engine],
894 $current_row_format, 'new_row_format'
896 $html_output .= '</td></tr>';
898 $html_output .= '</table>'
899 . '</fieldset>';
901 return $html_output;
905 * Get the common HTML table row (tr) for new_checksum, new_delay_key_write,
906 * new_transactional and new_page_checksum
908 * @param string $attribute class, name and id attribute
909 * @param string $label label value
910 * @param string $val checksum, delay_key_write, transactional, page_checksum
912 * @return string $html_output
914 function PMA_getHtmlForTableRow($attribute, $label, $val)
916 return '<tr>'
917 . '<td><label for="' . $attribute . '">' . $label . '</label></td>'
918 . '<td><input type="checkbox" name="'. $attribute .'"'
919 . ' id="' . $attribute .'"'
920 . ' value="1"'
921 . ((!empty($val) && $val == 1) ? ' checked="checked"' : '') . '/></td>'
922 . '</tr>';
926 * Get array of possible row formats
928 * @return array $possible_row_formats
930 function PMA_getPossibleRowFormat()
932 // the outer array is for engines, the inner array contains the dropdown
933 // option values as keys then the dropdown option labels
935 $possible_row_formats = array(
936 'ARIA' => array(
937 'FIXED' => 'FIXED',
938 'DYNAMIC' => 'DYNAMIC',
939 'PAGE' => 'PAGE'
941 'MARIA' => array(
942 'FIXED' => 'FIXED',
943 'DYNAMIC' => 'DYNAMIC',
944 'PAGE' => 'PAGE'
946 'MYISAM' => array(
947 'FIXED' => 'FIXED',
948 'DYNAMIC' => 'DYNAMIC'
950 'PBXT' => array(
951 'FIXED' => 'FIXED',
952 'DYNAMIC' => 'DYNAMIC'
954 'INNODB' => array(
955 'COMPACT' => 'COMPACT',
956 'REDUNDANT' => 'REDUNDANT'
960 $innodb_engine_plugin = PMA_StorageEngine::getEngine('innodb');
961 $innodb_plugin_version = $innodb_engine_plugin->getInnodbPluginVersion();
962 if (!empty($innodb_plugin_version)) {
963 $innodb_file_format = $innodb_engine_plugin->getInnodbFileFormat();
964 } else {
965 $innodb_file_format = '';
967 if ('Barracuda' == $innodb_file_format
968 && $innodb_engine_plugin->supportsFilePerTable()
970 $possible_row_formats['INNODB']['DYNAMIC'] = 'DYNAMIC';
971 $possible_row_formats['INNODB']['COMPRESSED'] = 'COMPRESSED';
974 return $possible_row_formats;
978 * Get HTML div for copy table
980 * @return string $html_output
982 function PMA_getHtmlForCopytable()
984 $html_output = '<div class="operations_half_width">';
985 $html_output .= '<form method="post" action="tbl_operations.php" '
986 . 'name="copyTable" '
987 . 'id="copyTable" '
988 . ' class="ajax" '
989 . 'onsubmit="return emptyFormElements(this, \'new_name\')">'
990 . PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table'])
991 . '<input type="hidden" name="reload" value="1" />';
993 $html_output .= '<fieldset>';
994 $html_output .= '<legend>'
995 . __('Copy table to (database<b>.</b>table):') . '</legend>';
997 if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
998 $html_output .= '<input type="text" maxlength="100" '
999 . 'size="30" name="target_db" '
1000 . 'value="'. htmlspecialchars($GLOBALS['db']) . '"/>';
1001 } else {
1002 $html_output .= '<select name="target_db">'
1003 . $GLOBALS['pma']->databases->getHtmlOptions(true, false)
1004 . '</select>';
1006 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
1007 $html_output .= '<input type="text" size="20" name="new_name" '
1008 . 'onfocus="this.select()" '
1009 . 'value="'. htmlspecialchars($GLOBALS['table']) . '"/><br />';
1011 $choices = array(
1012 'structure' => __('Structure only'),
1013 'data' => __('Structure and data'),
1014 'dataonly' => __('Data only'));
1016 $html_output .= PMA_Util::getRadioFields(
1017 'what', $choices, 'data', true
1020 $html_output .= '<input type="checkbox" name="drop_if_exists" '
1021 . 'value="true" id="checkbox_drop" />'
1022 . '<label for="checkbox_drop">'
1023 . sprintf(__('Add %s'), 'DROP TABLE') . '</label><br />'
1024 . '<input type="checkbox" name="sql_auto_increment" '
1025 . 'value="1" id="checkbox_auto_increment_cp" />'
1026 . '<label for="checkbox_auto_increment_cp">'
1027 . __('Add AUTO_INCREMENT value') . '</label><br />';
1029 // display "Add constraints" choice only if there are
1030 // foreign keys
1031 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
1032 $html_output .= '<input type="checkbox" name="add_constraints" '
1033 . 'value="1" id="checkbox_constraints" />';
1034 $html_output .= '<label for="checkbox_constraints">'
1035 .__('Add constraints') . '</label><br />';
1036 } // endif
1038 if (isset($_COOKIE['pma_switch_to_new'])
1039 && $_COOKIE['pma_switch_to_new'] == 'true'
1041 $pma_switch_to_new = 'true';
1044 $html_output .= '<input type="checkbox" name="switch_to_new" value="true"'
1045 . 'id="checkbox_switch"'
1046 . ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true')
1047 ? ' checked="checked"'
1048 : '' . '/>');
1049 $html_output .= '<label for="checkbox_switch">'
1050 . __('Switch to copied table') . '</label>'
1051 . '</fieldset>';
1053 $html_output .= '<fieldset class="tblFooters">'
1054 . '<input type="submit" name="submit_copy" value="' .__('Go') . '" />'
1055 . '</fieldset>'
1056 . '</form>'
1057 . '</div>';
1059 return $html_output;
1063 * Get HTML snippet for table maintence
1065 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
1066 * @param boolean $is_innodb whether innodb or not
1067 * @param boolean $is_berkeleydb whether berkeleydb or not
1068 * @param array $url_params array of URL parameters
1070 * @return string $html_output
1072 function PMA_getHtmlForTableMaintenance(
1073 $is_myisam_or_aria, $is_innodb, $is_berkeleydb, $url_params
1075 $html_output = '<div class="operations_half_width">';
1076 $html_output .= '<fieldset>'
1077 . '<legend>' . __('Table maintenance') . '</legend>';
1078 $html_output .= '<ul id="tbl_maintenance">';
1080 // Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
1081 $html_output .= PMA_getListofMaintainActionLink(
1082 $is_myisam_or_aria, $is_innodb, $url_params, $is_berkeleydb
1085 $html_output .= '</ul>'
1086 . '</fieldset>'
1087 . '</div>';
1089 return $html_output;
1093 * Get HTML 'li' having a link of maintain action
1095 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
1096 * @param boolean $is_innodb whether innodb or not
1097 * @param array $url_params array of URL parameters
1098 * @param boolean $is_berkeleydb whether berkeleydb or not
1100 * @return string $html_output
1102 function PMA_getListofMaintainActionLink($is_myisam_or_aria,
1103 $is_innodb, $url_params, $is_berkeleydb
1105 $html_output = '';
1107 if ($is_myisam_or_aria || $is_innodb || $is_berkeleydb) {
1108 if ($is_myisam_or_aria || $is_innodb) {
1109 $params = array(
1110 'sql_query' => 'CHECK TABLE '
1111 . PMA_Util::backquote($GLOBALS['table']),
1112 'table_maintenance' => 'Go',
1114 $html_output .= PMA_getMaintainActionlink(
1115 __('Check table'),
1116 $params,
1117 $url_params,
1118 'CHECK_TABLE'
1121 if ($is_innodb) {
1122 $params = array(
1123 'sql_query' => 'ALTER TABLE '
1124 . PMA_Util::backquote($GLOBALS['table'])
1125 . ' ENGINE = InnoDB;'
1127 $html_output .= PMA_getMaintainActionlink(
1128 __('Defragment table'),
1129 $params,
1130 $url_params,
1131 'InnoDB_File_Defragmenting',
1132 'Table_types'
1135 if ($is_myisam_or_aria || $is_berkeleydb) {
1136 $params = array(
1137 'sql_query' => 'ANALYZE TABLE '
1138 . PMA_Util::backquote($GLOBALS['table']),
1139 'table_maintenance' => 'Go',
1141 $html_output .= PMA_getMaintainActionlink(
1142 __('Analyze table'),
1143 $params,
1144 $url_params,
1145 'ANALYZE_TABLE'
1148 if ($is_myisam_or_aria && !PMA_DRIZZLE) {
1149 $params = array(
1150 'sql_query' => 'REPAIR TABLE '
1151 . PMA_Util::backquote($GLOBALS['table']),
1152 'table_maintenance' => 'Go',
1154 $html_output .= PMA_getMaintainActionlink(
1155 __('Repair table'),
1156 $params,
1157 $url_params,
1158 'REPAIR_TABLE'
1161 if (($is_myisam_or_aria || $is_innodb || $is_berkeleydb)
1162 && !PMA_DRIZZLE
1164 $params = array(
1165 'sql_query' => 'OPTIMIZE TABLE '
1166 . PMA_Util::backquote($GLOBALS['table']),
1167 'table_maintenance' => 'Go',
1169 $html_output .= PMA_getMaintainActionlink(
1170 __('Optimize table'),
1171 $params,
1172 $url_params,
1173 'OPTIMIZE_TABLE'
1176 } // end MYISAM or BERKELEYDB case
1178 $params = array(
1179 'sql_query' => 'FLUSH TABLE '
1180 . PMA_Util::backquote($GLOBALS['table']),
1181 'message_to_show' => sprintf(
1182 __('Table %s has been flushed'),
1183 htmlspecialchars($GLOBALS['table'])
1185 'reload' => 1,
1188 $html_output .= PMA_getMaintainActionlink(
1189 __('Flush the table (FLUSH)'),
1190 $params,
1191 $url_params,
1192 'FLUSH'
1195 return $html_output;
1199 * Get maintain action HTML link
1201 * @param string $action
1202 * @param array $params url parameters array
1203 * @param array $url_params
1204 * @param string $link contains name of page/anchor that is being linked
1205 * @param string $chapter chapter of "HTML, one page per chapter" documentation
1207 * @return string $html_output
1209 function PMA_getMaintainActionlink($action, $params, $url_params, $link,
1210 $chapter = 'MySQL_Database_Administration'
1212 return '<li>'
1213 . '<a class="maintain_action ajax" '
1214 . 'href="sql.php'
1215 . PMA_generate_common_url(array_merge($url_params, $params)) .'">'
1216 . $action
1217 . '</a>'
1218 . PMA_Util::showMySQLDocu($chapter, $link)
1219 . '</li>';
1223 * Get HTML for Delete data or table (truncate table, drop table)
1225 * @param array $truncate_table_url_params url parameter array for truncate table
1226 * @param array $drop_table_url_params url parameter array for drop table
1228 * @return string $html_output
1230 function PMA_getHtmlForDeleteDataOrTable(
1231 $truncate_table_url_params,
1232 $drop_table_url_params
1234 $html_output = '<div class="operations_half_width">'
1235 . '<fieldset class="caution">'
1236 . '<legend>' . __('Delete data or table') . '</legend>';
1238 $html_output .= '<ul>';
1240 if (! empty($truncate_table_url_params)) {
1241 $html_output .= PMA_getDeleteDataOrTablelink(
1242 $truncate_table_url_params,
1243 'TRUNCATE_TABLE',
1244 __('Empty the table (TRUNCATE)'),
1245 'truncate_tbl_anchor'
1248 if (!empty ($drop_table_url_params)) {
1249 $html_output .= PMA_getDeleteDataOrTablelink(
1250 $drop_table_url_params,
1251 'DROP_TABLE',
1252 __('Delete the table (DROP)'),
1253 'drop_tbl_anchor'
1256 $html_output .= '</ul></fieldset></div>';
1258 return $html_output;
1262 * Get the HTML link for Truncate table, Drop table and Drop db
1264 * @param array $url_params url parameter array for delete data or table
1265 * @param string $syntax TRUNCATE_TABLE or DROP_TABLE or DROP_DATABASE
1266 * @param string $link link to be shown
1267 * @param string $id id of the link
1269 * @return String html output
1271 function PMA_getDeleteDataOrTablelink($url_params, $syntax, $link, $id)
1273 return '<li><a '
1274 . 'href="sql.php' . PMA_generate_common_url($url_params) . '"'
1275 . ' id="' . $id . '" class="ajax">'
1276 . $link . '</a>'
1277 . PMA_Util::showMySQLDocu(
1278 'SQL-Syntax', $syntax
1280 . '</li>';
1284 * Get HTML snippet for partition maintenance
1286 * @param array $partition_names array of partition names for a specific db/table
1287 * @param array $url_params url parameters
1289 * @return string $html_output
1291 function PMA_getHtmlForPartitionMaintenance($partition_names, $url_params)
1293 $choices = array(
1294 'ANALYZE' => __('Analyze'),
1295 'CHECK' => __('Check'),
1296 'OPTIMIZE' => __('Optimize'),
1297 'REBUILD' => __('Rebuild'),
1298 'REPAIR' => __('Repair')
1301 $html_output = '<div class="operations_half_width">'
1302 . '<form method="post" action="tbl_operations.php">'
1303 . PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table'])
1304 . '<fieldset>'
1305 . '<legend>' . __('Partition maintenance') . '</legend>';
1307 $html_select = '<select name="partition_name">' . "\n";
1308 foreach ($partition_names as $one_partition) {
1309 $one_partition = htmlspecialchars($one_partition);
1310 $html_select .= '<option value="' . $one_partition . '">'
1311 . $one_partition . '</option>' . "\n";
1313 $html_select .= '</select>' . "\n";
1314 $html_output .= sprintf(__('Partition %s'), $html_select);
1316 $html_output .= PMA_Util::getRadioFields(
1317 'partition_operation', $choices, '', false
1319 $html_output .= PMA_Util::showMySQLDocu(
1320 'partitioning_maintenance',
1321 'partitioning_maintenance'
1323 $this_url_params = array_merge(
1324 $url_params,
1325 array(
1326 'sql_query' => 'ALTER TABLE '
1327 . PMA_Util::backquote($GLOBALS['table'])
1328 . ' REMOVE PARTITIONING;'
1331 $html_output .= '<br /><a href="sql.php'
1332 . PMA_generate_common_url($this_url_params) . '">'
1333 . __('Remove partitioning') . '</a>';
1335 $html_output .= '</fieldset>'
1336 . '<fieldset class="tblFooters">'
1337 . '<input type="submit" name="submit_partition" '
1338 . 'value="' . __('Go') . '" />'
1339 . '</fieldset>'
1340 . '</form>'
1341 . '</div>';
1343 return $html_output;
1347 * Get the HTML for Referential Integrity check
1349 * @param array $foreign all Relations to foreign tables for a given table
1350 * or optionally a given column in a table
1351 * @param array $url_params array of url parameters
1353 * @return string $html_output
1355 function PMA_getHtmlForReferentialIntegrityCheck($foreign, $url_params)
1357 $html_output = '<div class="operations_half_width">'
1358 . '<fieldset>'
1359 . '<legend>' . __('Check referential integrity:') . '</legend>';
1361 $html_output .= '<ul>';
1363 foreach ($foreign AS $master => $arr) {
1364 $join_query = 'SELECT '
1365 . PMA_Util::backquote($GLOBALS['table']) . '.*'
1366 . ' FROM ' . PMA_Util::backquote($GLOBALS['table'])
1367 . ' LEFT JOIN '
1368 . PMA_Util::backquote($arr['foreign_db'])
1369 . '.'
1370 . PMA_Util::backquote($arr['foreign_table']);
1371 if ($arr['foreign_table'] == $GLOBALS['table']) {
1372 $foreign_table = $GLOBALS['table'] . '1';
1373 $join_query .= ' AS ' . PMA_Util::backquote($foreign_table);
1374 } else {
1375 $foreign_table = $arr['foreign_table'];
1377 $join_query .= ' ON '
1378 . PMA_Util::backquote($GLOBALS['table']) . '.'
1379 . PMA_Util::backquote($master)
1380 . ' = '
1381 . PMA_Util::backquote($arr['foreign_db'])
1382 . '.'
1383 . PMA_Util::backquote($foreign_table) . '.'
1384 . PMA_Util::backquote($arr['foreign_field'])
1385 . ' WHERE '
1386 . PMA_Util::backquote($arr['foreign_db'])
1387 . '.'
1388 . PMA_Util::backquote($foreign_table) . '.'
1389 . PMA_Util::backquote($arr['foreign_field'])
1390 . ' IS NULL AND '
1391 . PMA_Util::backquote($GLOBALS['table']) . '.'
1392 . PMA_Util::backquote($master)
1393 . ' IS NOT NULL';
1394 $this_url_params = array_merge(
1395 $url_params,
1396 array('sql_query' => $join_query)
1399 $html_output .= '<li>'
1400 . '<a href="sql.php'
1401 . PMA_generate_common_url($this_url_params)
1402 . '">'
1403 . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.'
1404 . $arr['foreign_field']
1405 . '</a></li>' . "\n";
1406 } // foreach $foreign
1407 $html_output .= '</ul></fieldset></div>';
1409 return $html_output;
1412 function PMA_getQueryAndResultForReorderingTable()
1414 $sql_query = 'ALTER TABLE '
1415 . PMA_Util::backquote($GLOBALS['table'])
1416 . ' ORDER BY '
1417 . PMA_Util::backquote(urldecode($_REQUEST['order_field']));
1418 if (isset($_REQUEST['order_order'])
1419 && $_REQUEST['order_order'] === 'desc'
1421 $sql_query .= ' DESC';
1423 $sql_query .= ';';
1424 $result = PMA_DBI_query($sql_query);
1426 return array($sql_query, $result);
1430 * Get table alters array
1432 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
1433 * @param boolean $is_isam whether ISAM or not
1434 * @param string $pack_keys pack keys
1435 * @param string $checksum value of checksum
1436 * @param boolean $is_aria whether ARIA or not
1437 * @param string $page_checksum value of page checksum
1438 * @param string $delay_key_write delay key write
1439 * @param boolean $is_innodb whether INNODB or not
1440 * @param boolean $is_pbxt whether PBXT or not
1441 * @param string $row_format row format
1442 * @param string $tbl_storage_engine table storage engine
1443 * @param string $transactional value of transactional
1444 * @param string $tbl_collation collation of the table
1446 * @return array $table_alters
1448 function PMA_getTableAltersArray($is_myisam_or_aria, $is_isam, $pack_keys,
1449 $checksum, $is_aria, $page_checksum, $delay_key_write, $is_innodb,
1450 $is_pbxt, $row_format, $new_tbl_storage_engine, $transactional, $tbl_collation
1452 global $auto_increment;
1454 $table_alters = array();
1456 if (isset($_REQUEST['comment'])
1457 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']
1459 $table_alters[] = 'COMMENT = \''
1460 . PMA_Util::sqlAddSlashes($_REQUEST['comment']) . '\'';
1462 if (! empty($new_tbl_storage_engine)
1463 && strtolower($new_tbl_storage_engine) !== strtolower($GLOBALS['tbl_storage_engine'])
1465 $table_alters[] = 'ENGINE = ' . $new_tbl_storage_engine;
1467 if (! empty($_REQUEST['tbl_collation'])
1468 && $_REQUEST['tbl_collation'] !== $tbl_collation
1470 $table_alters[] = 'DEFAULT '
1471 . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
1474 if (($is_myisam_or_aria || $is_isam)
1475 && isset($_REQUEST['new_pack_keys'])
1476 && $_REQUEST['new_pack_keys'] != (string)$pack_keys
1478 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
1481 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
1482 if ($is_myisam_or_aria
1483 && $_REQUEST['new_checksum'] !== $checksum
1485 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
1488 $_REQUEST['new_transactional']
1489 = empty($_REQUEST['new_transactional']) ? '0' : '1';
1490 if ($is_aria
1491 && $_REQUEST['new_transactional'] !== $transactional
1493 $table_alters[] = 'TRANSACTIONAL = ' . $_REQUEST['new_transactional'];
1496 $_REQUEST['new_page_checksum']
1497 = empty($_REQUEST['new_page_checksum']) ? '0' : '1';
1498 if ($is_aria
1499 && $_REQUEST['new_page_checksum'] !== $page_checksum
1501 $table_alters[] = 'PAGE_CHECKSUM = ' . $_REQUEST['new_page_checksum'];
1504 $_REQUEST['new_delay_key_write']
1505 = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
1506 if ($is_myisam_or_aria
1507 && $_REQUEST['new_delay_key_write'] !== $delay_key_write
1509 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
1512 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
1513 && ! empty($_REQUEST['new_auto_increment'])
1514 && (! isset($auto_increment)
1515 || $_REQUEST['new_auto_increment'] !== $auto_increment)
1517 $table_alters[] = 'auto_increment = '
1518 . PMA_Util::sqlAddSlashes($_REQUEST['new_auto_increment']);
1521 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
1522 && ! empty($_REQUEST['new_row_format'])
1523 && (!strlen($row_format)
1524 || strtolower($_REQUEST['new_row_format']) !== strtolower($row_format))
1526 $table_alters[] = 'ROW_FORMAT = '
1527 . PMA_Util::sqlAddSlashes($_REQUEST['new_row_format']);
1530 return $table_alters;
1534 * set initial value of the set of variables, based on the current table engine
1536 * @param string $tbl_storage_engine table storage engine
1538 * @return array ($is_myisam_or_aria, $is_innodb, $is_isam,
1539 * $is_berkeleydb, $is_aria, $is_pbxt)
1541 function PMA_setGlobalVariablesForEngine($tbl_storage_engine)
1543 $is_myisam_or_aria = $is_isam = $is_innodb = $is_berkeleydb
1544 = $is_aria = $is_pbxt = false;
1545 $upper_tbl_storage_engine = strtoupper($tbl_storage_engine);
1547 //Options that apply to MYISAM usually apply to ARIA
1548 $is_myisam_or_aria = ($upper_tbl_storage_engine == 'MYISAM'
1549 || $upper_tbl_storage_engine == 'ARIA'
1550 || $upper_tbl_storage_engine == 'MARIA'
1552 $is_aria = ($upper_tbl_storage_engine == 'ARIA');
1554 $is_isam = ($upper_tbl_storage_engine == 'ISAM');
1555 $is_innodb = ($upper_tbl_storage_engine == 'INNODB');
1556 $is_berkeleydb = ($upper_tbl_storage_engine == 'BERKELEYDB');
1557 $is_pbxt = ($upper_tbl_storage_engine == 'PBXT');
1559 return array(
1560 $is_myisam_or_aria, $is_innodb, $is_isam,
1561 $is_berkeleydb, $is_aria, $is_pbxt
1566 * Get warning messages array
1568 * @return array $warning_messages
1570 function PMA_getWarningMessagesArray()
1572 $warning_messages = array();
1573 foreach (PMA_DBI_get_warnings() as $warning) {
1574 // In MariaDB 5.1.44, when altering a table from Maria to MyISAM
1575 // and if TRANSACTIONAL was set, the system reports an error;
1576 // I discussed with a Maria developer and he agrees that this
1577 // should not be reported with a Level of Error, so here
1578 // I just ignore it. But there are other 1478 messages
1579 // that it's better to show.
1580 if (! ($_REQUEST['new_tbl_storage_engine'] == 'MyISAM'
1581 && $warning['Code'] == '1478'
1582 && $warning['Level'] == 'Error')
1584 $warning_messages[] = $warning['Level'] . ': #' . $warning['Code']
1585 . ' ' . $warning['Message'];
1588 return $warning_messages;
1592 * Get SQL query and result after ran this SQL query for a partition operation
1593 * has been requested by the user
1595 * @return array $sql_query, $result
1597 function PMA_getQueryAndResultForPartition()
1599 $sql_query = 'ALTER TABLE '
1600 . PMA_Util::backquote($GLOBALS['table']) . ' '
1601 . $_REQUEST['partition_operation']
1602 . ' PARTITION '
1603 . $_REQUEST['partition_name'] . ';';
1604 $result = PMA_DBI_query($sql_query);
1606 return array($sql_query, $result);