Merge remote-tracking branch 'origin/master' into drizzle
[phpmyadmin.git] / tbl_operations.php
blobbdac085fe710638fdce32ad2df44205b0809ecb6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
6 */
8 /**
11 require_once './libraries/common.inc.php';
13 $pma_table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
15 /**
16 * Runs common work
18 require './libraries/tbl_common.php';
19 $url_query .= '&amp;goto=tbl_operations.php&amp;back=tbl_operations.php';
20 $url_params['goto'] = $url_params['back'] = 'tbl_operations.php';
22 /**
23 * Gets relation settings
25 $cfgRelation = PMA_getRelationsParam();
27 /**
28 * Gets available MySQL charsets and storage engines
30 require_once './libraries/mysql_charsets.lib.php';
31 require_once './libraries/StorageEngine.class.php';
33 // add a javascript file for jQuery functions to handle Ajax actions
34 // also add jQueryUI
35 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
37 /**
38 * Class for partition management
40 require_once './libraries/Partition.class.php';
42 // reselect current db (needed in some cases probably due to
43 // the calling of relation.lib.php)
44 PMA_DBI_select_db($GLOBALS['db']);
46 /**
47 * Gets tables informations
50 require './libraries/tbl_info.inc.php';
52 // define some globals here, for improved syntax in the conditionals
53 $is_myisam_or_aria = $is_isam = $is_innodb = $is_berkeleydb = $is_aria = $is_pbxt = false;
54 // set initial value of these globals, based on the current table engine
55 PMA_set_global_variables_for_engine($tbl_type);
57 if ($is_aria) {
58 // the value for transactional can be implicit
59 // (no create option found, in this case it means 1)
60 // or explicit (option found with a value of 0 or 1)
61 // ($transactional may have been set by libraries/tbl_info.inc.php,
62 // from the $create_options)
63 $transactional = (isset($transactional) && $transactional == '0') ? '0' : '1';
64 $page_checksum = (isset($page_checksum)) ? $page_checksum : '';
67 $reread_info = false;
68 $table_alters = array();
70 /**
71 * If the table has to be moved to some other database
73 if(isset($_REQUEST['submit_move']) || isset($_REQUEST['submit_copy'])) {
74 $_message = '';
75 require_once './tbl_move_copy.php';
77 /**
78 * If the table has to be maintained
80 if(isset($_REQUEST['table_maintenance'])) {
81 require_once './sql.php';
82 unset($result);
84 /**
85 * Updates table comment, type and options if required
87 if (isset($_REQUEST['submitoptions'])) {
88 $_message = '';
89 $warning_messages = array();
91 if (isset($_REQUEST['new_name'])) {
92 if ($pma_table->rename($_REQUEST['new_name'])) {
93 $_message .= $pma_table->getLastMessage();
94 $result = true;
95 $GLOBALS['table'] = $pma_table->getName();
96 $reread_info = true;
97 $reload = true;
98 } else {
99 $_message .= $pma_table->getLastError();
100 $result = false;
103 if (isset($_REQUEST['comment'])
104 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']) {
105 $table_alters[] = 'COMMENT = \'' . PMA_sqlAddSlashes($_REQUEST['comment']) . '\'';
107 if (! empty($_REQUEST['new_tbl_type'])
108 && strtolower($_REQUEST['new_tbl_type']) !== strtolower($tbl_type)) {
109 $table_alters[] = 'ENGINE = ' . $_REQUEST['new_tbl_type'];
110 $tbl_type = $_REQUEST['new_tbl_type'];
111 // reset the globals for the new engine
112 PMA_set_global_variables_for_engine($tbl_type);
113 if ($is_aria) {
114 $transactional = (isset($transactional) && $transactional == '0') ? '0' : '1';
115 $page_checksum = (isset($page_checksum)) ? $page_checksum : '';
119 if (! empty($_REQUEST['tbl_collation'])
120 && $_REQUEST['tbl_collation'] !== $tbl_collation) {
121 $table_alters[] = 'DEFAULT ' . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
124 if (($is_myisam_or_aria || $is_isam)
125 && isset($_REQUEST['new_pack_keys'])
126 && $_REQUEST['new_pack_keys'] != (string)$pack_keys) {
127 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
130 $checksum = empty($checksum) ? '0' : '1';
131 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
132 if ($is_myisam_or_aria
133 && $_REQUEST['new_checksum'] !== $checksum) {
134 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
137 $_REQUEST['new_transactional'] = empty($_REQUEST['new_transactional']) ? '0' : '1';
138 if ($is_aria
139 && $_REQUEST['new_transactional'] !== $transactional) {
140 $table_alters[] = 'TRANSACTIONAL = ' . $_REQUEST['new_transactional'];
143 $_REQUEST['new_page_checksum'] = empty($_REQUEST['new_page_checksum']) ? '0' : '1';
144 if ($is_aria
145 && $_REQUEST['new_page_checksum'] !== $page_checksum) {
146 $table_alters[] = 'PAGE_CHECKSUM = ' . $_REQUEST['new_page_checksum'];
149 $delay_key_write = empty($delay_key_write) ? '0' : '1';
150 $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
151 if ($is_myisam_or_aria
152 && $_REQUEST['new_delay_key_write'] !== $delay_key_write) {
153 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
156 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
157 && ! empty($_REQUEST['new_auto_increment'])
158 && (! isset($auto_increment) || $_REQUEST['new_auto_increment'] !== $auto_increment)) {
159 $table_alters[] = 'auto_increment = ' . PMA_sqlAddSlashes($_REQUEST['new_auto_increment']);
162 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
163 && ! empty($_REQUEST['new_row_format'])
164 && (! isset($row_format) || strtolower($_REQUEST['new_row_format']) !== strtolower($row_format))) {
165 $table_alters[] = 'ROW_FORMAT = ' . PMA_sqlAddSlashes($_REQUEST['new_row_format']);
168 if (count($table_alters) > 0) {
169 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']);
170 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
171 $result .= PMA_DBI_query($sql_query) ? true : false;
172 $reread_info = true;
173 unset($table_alters);
174 foreach (PMA_DBI_get_warnings() as $warning) {
175 // In MariaDB 5.1.44, when altering a table from Maria to MyISAM
176 // and if TRANSACTIONAL was set, the system reports an error;
177 // I discussed with a Maria developer and he agrees that this
178 // should not be reported with a Level of Error, so here
179 // I just ignore it. But there are other 1478 messages
180 // that it's better to show.
181 if (! ($_REQUEST['new_tbl_type'] == 'MyISAM' && $warning['Code'] == '1478' && $warning['Level'] == 'Error')) {
182 $warning_messages[] = $warning['Level'] . ': #' . $warning['Code']
183 . ' ' . $warning['Message'];
189 * Reordering the table has been requested by the user
191 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
192 $sql_query = '
193 ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
194 ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
195 if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
196 $sql_query .= ' DESC';
198 $result = PMA_DBI_query($sql_query);
199 } // end if
202 * A partition operation has been requested by the user
204 if (isset($_REQUEST['submit_partition']) && ! empty($_REQUEST['partition_operation'])) {
205 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . $_REQUEST['partition_operation'] . ' PARTITION ' . $_REQUEST['partition_name'];
206 $result = PMA_DBI_query($sql_query);
207 } // end if
209 if ($reread_info) {
210 // to avoid showing the old value (for example the AUTO_INCREMENT) after
211 // a change, clear the cache
212 PMA_Table::$cache = array();
213 $page_checksum = $checksum = $delay_key_write = 0;
214 require './libraries/tbl_info.inc.php';
216 unset($reread_info);
219 * Displays top menu links
221 require_once './libraries/tbl_links.inc.php';
223 if (isset($result) && empty($message_to_show)) {
224 // set to success by default, because result set could be empty
225 // (for example, a table rename)
226 $_type = 'success';
227 if (empty($_message)) {
228 $_message = $result ? __('Your SQL query has been executed successfully') : __('Error');
229 // $result should exist, regardless of $_message
230 $_type = $result ? 'success' : 'error';
232 if (! empty($warning_messages)) {
233 $_message = new PMA_Message;
234 $_message->addMessages($warning_messages);
235 $_message->isError(true);
236 unset($warning_messages);
238 PMA_showMessage($_message, $sql_query, $_type);
239 unset($_message, $_type);
242 $url_params['goto'] = 'tbl_operations.php';
243 $url_params['back'] = 'tbl_operations.php';
246 * Get columns names
248 $local_query = '
249 SHOW COLUMNS
250 FROM ' . PMA_backquote($GLOBALS['table']) . '
251 FROM ' . PMA_backquote($GLOBALS['db']);
252 $columns = PMA_DBI_fetch_result($local_query, null, 'Field');
253 unset($local_query);
256 * Displays the page
259 <!-- Order the table -->
260 <div class="operations_half_width">
261 <form method="post" action="tbl_operations.php">
262 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
263 <fieldset id="fieldset_table_order">
264 <legend><?php echo __('Alter table order by'); ?></legend>
265 <select name="order_field">
266 <?php
267 foreach ($columns as $fieldname) {
268 echo ' <option value="' . htmlspecialchars($fieldname) . '">'
269 . htmlspecialchars($fieldname) . '</option>' . "\n";
271 unset($columns);
273 </select> <?php echo __('(singly)'); ?>
274 <select name="order_order">
275 <option value="asc"><?php echo __('Ascending'); ?></option>
276 <option value="desc"><?php echo __('Descending'); ?></option>
277 </select>
278 </fieldset>
279 <fieldset class="tblFooters">
280 <input type="submit" name="submitorderby" value="<?php echo __('Go'); ?>" />
281 </fieldset>
282 </form>
283 </div>
285 <!-- Move table -->
286 <div class="operations_half_width">
287 <form method="post" action="tbl_operations.php"
288 onsubmit="return emptyFormElements(this, 'new_name')">
289 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
290 <input type="hidden" name="reload" value="1" />
291 <input type="hidden" name="what" value="data" />
292 <fieldset id="fieldset_table_rename">
293 <legend><?php echo __('Move table to (database<b>.</b>table):'); ?></legend>
294 <?php if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
296 <input type="text" maxlength="100" size="30" name="target_db" value="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
297 <?php
298 } else {
300 <select name="target_db">
301 <?php echo $GLOBALS['pma']->databases->getHtmlOptions(true, false); ?>
302 </select>
303 <?php
304 } // end if
306 &nbsp;<strong>.</strong>&nbsp;
307 <input type="text" size="20" name="new_name" onfocus="this.select()"
308 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br />
309 <?php
310 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
311 // next value but users can decide if they want it or not for the operation
313 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_mv" checked="checked" />
314 <label for="checkbox_auto_increment_mv"><?php echo __('Add AUTO_INCREMENT value'); ?></label><br />
315 </fieldset>
316 <fieldset class="tblFooters">
317 <input type="submit" name="submit_move" value="<?php echo __('Go'); ?>" />
318 </fieldset>
319 </form>
320 </div>
322 <?php
323 if (strstr($show_comment, '; InnoDB free') === false) {
324 if (strstr($show_comment, 'InnoDB free') === false) {
325 // only user entered comment
326 $comment = $show_comment;
327 } else {
328 // here we have just InnoDB generated part
329 $comment = '';
331 } else {
332 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
333 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
336 // PACK_KEYS: MyISAM or ISAM
337 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
338 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3, PBXT
340 // Here should be version check for InnoDB, however it is supported
341 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
342 // check for version
345 <!-- Table options -->
346 <div class="operations_half_width clearfloat">
347 <form method="post" action="tbl_operations.php">
348 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
349 <input type="hidden" name="reload" value="1" />
350 <fieldset>
351 <legend><?php echo __('Table options'); ?></legend>
353 <table>
354 <!-- Change table name -->
355 <tr><td><?php echo __('Rename table to'); ?></td>
356 <td><input type="text" size="20" name="new_name" onfocus="this.select()"
357 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
358 </td>
359 </tr>
361 <!-- Table comments -->
362 <tr><td><?php echo __('Table comments'); ?></td>
363 <td><input type="text" name="comment" maxlength="60" size="30"
364 value="<?php echo htmlspecialchars($comment); ?>" onfocus="this.select()" />
365 <input type="hidden" name="prev_comment" value="<?php echo htmlspecialchars($comment); ?>" />
366 </td>
367 </tr>
369 <!-- Storage engine -->
370 <tr><td><?php echo __('Storage Engine'); ?>
371 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
372 </td>
373 <td><?php echo PMA_StorageEngine::getHtmlSelect('new_tbl_type', null, $tbl_type); ?>
374 </td>
375 </tr>
377 <!-- Table character set -->
378 <tr><td><?php echo __('Collation'); ?></td>
379 <td><?php echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION,
380 'tbl_collation', null, $tbl_collation, false, 3); ?>
381 </td>
382 </tr>
383 <?php
384 if ($is_myisam_or_aria || $is_isam) {
386 <tr>
387 <td><label for="new_pack_keys">PACK_KEYS</label></td>
388 <td><select name="new_pack_keys" id="new_pack_keys">
389 <option value="DEFAULT"
390 <?php if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?>
391 >DEFAULT</option>
392 <option value="0"
393 <?php if ($pack_keys == '0') echo 'selected="selected"'; ?>
394 >0</option>
395 <option value="1"
396 <?php if ($pack_keys == '1') echo 'selected="selected"'; ?>
397 >1</option>
398 </select>
399 </td>
400 </tr>
401 <?php
402 } // end if (MYISAM|ISAM)
404 if ($is_myisam_or_aria) {
406 <tr><td><label for="new_checksum">CHECKSUM</label></td>
407 <td><input type="checkbox" name="new_checksum" id="new_checksum"
408 value="1"
409 <?php echo (isset($checksum) && $checksum == 1)
410 ? ' checked="checked"'
411 : ''; ?> />
412 </td>
413 </tr>
415 <tr><td><label for="new_delay_key_write">DELAY_KEY_WRITE</label></td>
416 <td><input type="checkbox" name="new_delay_key_write" id="new_delay_key_write"
417 value="1"
418 <?php echo (isset($delay_key_write) && $delay_key_write == 1)
419 ? ' checked="checked"'
420 : ''; ?> />
421 </td>
422 </tr>
424 <?php
425 } // end if (MYISAM)
427 if ($is_aria) {
429 <tr><td><label for="new_transactional">TRANSACTIONAL</label></td>
430 <td><input type="checkbox" name="new_transactional" id="new_transactional"
431 value="1"
432 <?php echo (isset($transactional) && $transactional == 1)
433 ? ' checked="checked"'
434 : ''; ?> />
435 </td>
436 </tr>
438 <tr><td><label for="new_page_checksum">PAGE_CHECKSUM</label></td>
439 <td><input type="checkbox" name="new_page_checksum" id="new_page_checksum"
440 value="1"
441 <?php echo (isset($page_checksum) && $page_checksum == 1)
442 ? ' checked="checked"'
443 : ''; ?> />
444 </td>
445 </tr>
447 <?php
448 } // end if (ARIA)
450 if (isset($auto_increment) && strlen($auto_increment) > 0
451 && ($is_myisam_or_aria || $is_innodb || $is_pbxt)) {
453 <tr><td><label for="auto_increment_opt">AUTO_INCREMENT</label></td>
454 <td><input type="text" name="new_auto_increment" id="auto_increment_opt"
455 value="<?php echo $auto_increment; ?>" /></td>
456 </tr>
457 <?php
458 } // end if (MYISAM|INNODB)
460 // the outer array is for engines, the inner array contains the dropdown
461 // option values as keys then the dropdown option labels
463 $possible_row_formats = array(
464 'ARIA' => array(
465 'FIXED' => 'FIXED',
466 'DYNAMIC' => 'DYNAMIC',
467 'PAGE' => 'PAGE'
469 'MARIA' => array(
470 'FIXED' => 'FIXED',
471 'DYNAMIC' => 'DYNAMIC',
472 'PAGE' => 'PAGE'
474 'MYISAM' => array(
475 'FIXED' => 'FIXED',
476 'DYNAMIC' => 'DYNAMIC'
478 'PBXT' => array(
479 'FIXED' => 'FIXED',
480 'DYNAMIC' => 'DYNAMIC'
482 'INNODB' => array(
483 'COMPACT' => 'COMPACT',
484 'REDUNDANT' => 'REDUNDANT')
487 $innodb_engine_plugin = PMA_StorageEngine::getEngine('innodb');
488 $innodb_plugin_version = $innodb_engine_plugin->getInnodbPluginVersion();
489 if (!empty($innodb_plugin_version)) {
490 $innodb_file_format = $innodb_engine_plugin->getInnodbFileFormat();
491 } else {
492 $innodb_file_format = '';
494 if ('Barracuda' == $innodb_file_format && $innodb_engine_plugin->supportsFilePerTable()) {
495 $possible_row_formats['INNODB']['DYNAMIC'] = 'DYNAMIC';
496 $possible_row_formats['INNODB']['COMPRESSED'] = 'COMPRESSED';
498 unset($innodb_engine_plugin, $innodb_plugin_version, $innodb_file_format);
500 // for MYISAM there is also COMPRESSED but it can be set only by the
501 // myisampack utility, so don't offer here the choice because if we
502 // try it inside an ALTER TABLE, MySQL (at least in 5.1.23-maria)
503 // does not return a warning
504 // (if the table was compressed, it can be seen on the Structure page)
506 if (isset($possible_row_formats[$tbl_type])) {
507 $current_row_format = strtoupper($showtable['Row_format']);
508 echo '<tr><td><label for="new_row_format">ROW_FORMAT</label></td>';
509 echo '<td>';
510 echo PMA_generate_html_dropdown('new_row_format', $possible_row_formats[$tbl_type], $current_row_format, 'new_row_format');
511 unset($possible_row_formats, $current_row_format);
512 echo '</td>';
513 echo '</tr>';
516 </table>
517 </fieldset>
518 <fieldset class="tblFooters">
519 <input type="submit" name="submitoptions" value="<?php echo __('Go'); ?>" />
520 </fieldset>
521 </form>
522 </div>
524 <!-- Copy table -->
525 <div class="operations_half_width">
526 <form method="post" action="tbl_operations.php"
527 onsubmit="return emptyFormElements(this, 'new_name')">
528 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
529 <input type="hidden" name="reload" value="1" />
530 <fieldset>
531 <legend><?php echo __('Copy table to (database<b>.</b>table):'); ?></legend>
532 <?php if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
534 <input type="text" maxlength="100" size="30" name="target_db" value="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
535 <?php
536 } else {
538 <select name="target_db">
539 <?php echo $GLOBALS['pma']->databases->getHtmlOptions(true, false); ?>
540 </select>
541 <?php
542 } // end if
544 &nbsp;<strong>.</strong>&nbsp;
545 <input type="text" size="20" name="new_name" onfocus="this.select()" value="<?php echo htmlspecialchars($GLOBALS['table']); ?>"/><br />
546 <?php
547 $choices = array(
548 'structure' => __('Structure only'),
549 'data' => __('Structure and data'),
550 'dataonly' => __('Data only'));
551 PMA_display_html_radio('what', $choices, 'data', true);
552 unset($choices);
555 <input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" />
556 <label for="checkbox_drop"><?php echo sprintf(__('Add %s'), 'DROP TABLE'); ?></label><br />
557 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_cp" />
558 <label for="checkbox_auto_increment_cp"><?php echo __('Add AUTO_INCREMENT value'); ?></label><br />
559 <?php
560 // display "Add constraints" choice only if there are
561 // foreign keys
562 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
564 <input type="checkbox" name="add_constraints" value="1" id="checkbox_constraints" />
565 <label for="checkbox_constraints"><?php echo __('Add constraints'); ?></label><br />
566 <?php
567 } // endif
568 if (isset($_COOKIE['pma_switch_to_new'])
569 && $_COOKIE['pma_switch_to_new'] == 'true') {
570 $pma_switch_to_new = 'true';
573 <input type="checkbox" name="switch_to_new" value="true"
574 id="checkbox_switch"<?php echo
575 isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
576 ? ' checked="checked"'
577 : ''; ?> />
578 <label for="checkbox_switch"><?php echo __('Switch to copied table'); ?></label>
579 </fieldset>
580 <fieldset class="tblFooters">
581 <input type="submit" name="submit_copy" value="<?php echo __('Go'); ?>" />
582 </fieldset>
583 </form>
584 </div>
586 <br class="clearfloat"/>
588 <div class="operations_half_width">
589 <fieldset>
590 <legend><?php echo __('Table maintenance'); ?></legend>
592 <ul>
593 <?php
594 // Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
595 if ($is_myisam_or_aria || $is_innodb || $is_berkeleydb) {
596 if ($is_myisam_or_aria || $is_innodb) {
597 $this_url_params = array_merge($url_params,
598 array(
599 'sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table']),
600 'table_maintenance' => 'Go',
603 <li><a href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
604 <?php echo __('Check table'); ?></a>
605 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?>
606 </li>
607 <?php
609 if ($is_innodb) {
610 $this_url_params = array_merge($url_params,
611 array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ENGINE = InnoDB'));
613 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
614 <?php echo __('Defragment table'); ?></a>
615 <?php echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?>
616 </li>
617 <?php
619 if ($is_myisam_or_aria || $is_berkeleydb) {
620 $this_url_params = array_merge($url_params,
621 array(
622 'sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table']),
623 'table_maintenance' => 'Go',
626 <li><a href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
627 <?php echo __('Analyze table'); ?></a>
628 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?>
629 </li>
630 <?php
632 if ($is_myisam_or_aria && !PMA_DRIZZLE) {
633 $this_url_params = array_merge($url_params,
634 array(
635 'sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table']),
636 'table_maintenance' => 'Go',
639 <li><a href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
640 <?php echo __('Repair table'); ?></a>
641 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?>
642 </li>
643 <?php
645 if (($is_myisam_or_aria || $is_innodb || $is_berkeleydb) && !PMA_DRIZZLE) {
646 $this_url_params = array_merge($url_params,
647 array(
648 'sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table']),
649 'table_maintenance' => 'Go',
652 <li><a href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
653 <?php echo __('Optimize table'); ?></a>
654 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?>
655 </li>
656 <?php
658 } // end MYISAM or BERKELEYDB case
659 $this_url_params = array_merge($url_params,
660 array(
661 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
662 'message_to_show' => sprintf(__('Table %s has been flushed'),
663 htmlspecialchars($GLOBALS['table'])),
664 'reload' => 1,
667 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
668 <?php echo __('Flush the table (FLUSH)'); ?></a>
669 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?>
670 </li>
671 </ul>
672 </fieldset>
673 </div>
674 <?php if (! (isset($db_is_information_schema) && $db_is_information_schema)) { ?>
675 <div class="operations_half_width">
676 <fieldset class="caution">
677 <legend><?php echo __('Delete data or table'); ?></legend>
679 <ul>
680 <?php
681 if (! $tbl_is_view && ! (isset($db_is_information_schema) && $db_is_information_schema)) {
682 $this_sql_query = 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table']);
683 $this_url_params = array_merge($url_params,
684 array(
685 'sql_query' => $this_sql_query,
686 'goto' => 'tbl_structure.php',
687 'reload' => '1',
688 'message_to_show' => sprintf(__('Table %s has been emptied'), htmlspecialchars($table)),
691 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'id="truncate_tbl_anchor"' : ''); ?>>
692 <?php echo __('Empty the table (TRUNCATE)'); ?></a>
693 <?php echo PMA_showMySQLDocu('SQL-Syntax', 'TRUNCATE_TABLE'); ?>
694 </li>
695 <?php
697 if (! (isset($db_is_information_schema) && $db_is_information_schema)) {
698 $this_sql_query = 'DROP TABLE ' . PMA_backquote($GLOBALS['table']);
699 $this_url_params = array_merge($url_params,
700 array(
701 'sql_query' => $this_sql_query,
702 'goto' => 'db_operations.php',
703 'reload' => '1',
704 'purge' => '1',
705 'message_to_show' => sprintf(($tbl_is_view ? __('View %s has been dropped') : __('Table %s has been dropped')), htmlspecialchars($table)),
706 // table name is needed to avoid running
707 // PMA_relationsCleanupDatabase() on the whole db later
708 'table' => $GLOBALS['table'],
711 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'id="drop_tbl_anchor"' : ''); ?>>
712 <?php echo __('Delete the table (DROP)'); ?></a>
713 <?php echo PMA_showMySQLDocu('SQL-Syntax', 'DROP_TABLE'); ?>
714 </li>
715 <?php
718 </ul>
719 </fieldset>
720 </div>
721 <?php
724 <?php if (PMA_Partition::havePartitioning()) {
725 $partition_names = PMA_Partition::getPartitionNames($db, $table);
726 // show the Partition maintenance section only if we detect a partition
727 if (! is_null($partition_names[0])) {
729 <div class="operations_half_width">
730 <form method="post" action="tbl_operations.php">
731 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
732 <fieldset>
733 <legend><?php echo __('Partition maintenance'); ?></legend>
734 <?php
735 $html_select = '<select name="partition_name">' . "\n";
736 foreach($partition_names as $one_partition) {
737 $one_partition = htmlspecialchars($one_partition);
738 $html_select .= '<option value="' . $one_partition . '">' . $one_partition . '</option>' . "\n";
740 $html_select .= '</select>' . "\n";
741 printf(__('Partition %s'), $html_select);
742 unset($partition_names, $one_partition, $html_select);
743 $choices = array(
744 'ANALYZE' => __('Analyze'),
745 'CHECK' => __('Check'),
746 'OPTIMIZE' => __('Optimize'),
747 'REBUILD' => __('Rebuild'),
748 'REPAIR' => __('Repair'));
749 PMA_display_html_radio('partition_operation', $choices, '', false);
750 unset($choices);
751 echo PMA_showMySQLDocu('partitioning_maintenance', 'partitioning_maintenance');
752 // I'm not sure of the best way to display that; this link does
753 // not depend on the Go button
754 $this_url_params = array_merge($url_params,
755 array(
756 'sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' REMOVE PARTITIONING'
759 <br /><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
760 <?php echo __('Remove partitioning'); ?></a>
761 </fieldset>
762 <fieldset class="tblFooters">
763 <input type="submit" name="submit_partition" value="<?php echo __('Go'); ?>" />
764 </fieldset>
765 </form>
766 </div>
767 <?php
768 } // end if
769 } // end if
771 // Referential integrity check
772 // The Referential integrity check was intended for the non-InnoDB
773 // tables for which the relations are defined in pmadb
774 // so I assume that if the current table is InnoDB, I don't display
775 // this choice (InnoDB maintains integrity by itself)
777 if ($cfgRelation['relwork'] && ! $is_innodb) {
778 PMA_DBI_select_db($GLOBALS['db']);
779 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
781 if ($foreign) {
783 <!-- Referential integrity check -->
784 <div class="operations_half_width">
785 <fieldset>
786 <legend><?php echo __('Check referential integrity:'); ?></legend>
787 <ul>
788 <?php
789 echo "\n";
790 foreach ($foreign AS $master => $arr) {
791 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
792 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
793 . PMA_backquote($arr['foreign_table']);
794 if ($arr['foreign_table'] == $GLOBALS['table']) {
795 $foreign_table = $GLOBALS['table'] . '1';
796 $join_query .= ' AS ' . PMA_backquote($foreign_table);
797 } else {
798 $foreign_table = $arr['foreign_table'];
800 $join_query .= ' ON '
801 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
802 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
803 . ' WHERE '
804 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
805 . ' IS NULL AND '
806 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
807 . ' IS NOT NULL';
808 $this_url_params = array_merge($url_params,
809 array('sql_query' => $join_query));
810 echo ' <li>'
811 . '<a href="sql.php'
812 . PMA_generate_common_url($this_url_params)
813 . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
814 . '</a></li>' . "\n";
815 } // foreach $foreign
816 unset($foreign_table, $join_query);
818 </ul>
819 </fieldset>
820 </div>
821 <?php
822 } // end if ($foreign)
824 } // end if (!empty($cfg['Server']['relation']))
828 * Displays the footer
830 require './libraries/footer.inc.php';
833 function PMA_set_global_variables_for_engine($tbl_type)
835 global $is_myisam_or_aria, $is_innodb, $is_isam, $is_berkeleydb, $is_aria, $is_pbxt;
837 $is_myisam_or_aria = $is_isam = $is_innodb = $is_berkeleydb = $is_aria = $is_pbxt = false;
838 $upper_tbl_type = strtoupper($tbl_type);
840 //Options that apply to MYISAM usually apply to ARIA
841 $is_myisam_or_aria = ($upper_tbl_type == 'MYISAM' || $upper_tbl_type == 'ARIA' || $upper_tbl_type == 'MARIA');
842 $is_aria = ($upper_tbl_type == 'ARIA');
844 $is_isam = ($upper_tbl_type == 'ISAM');
845 $is_innodb = ($upper_tbl_type == 'INNODB');
846 $is_berkeleydb = ($upper_tbl_type == 'BERKELEYDB');
847 $is_pbxt = ($upper_tbl_type == 'PBXT');