Translated using Weblate.
[phpmyadmin.git] / tbl_operations.php
blobccdd68ebc1fcd504cca524fe727bb15836d83995
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 /**
34 * Class for partition management
36 require_once 'libraries/Partition.class.php';
38 // reselect current db (needed in some cases probably due to
39 // the calling of relation.lib.php)
40 PMA_DBI_select_db($GLOBALS['db']);
42 /**
43 * Gets tables informations
46 require 'libraries/tbl_info.inc.php';
48 // define some globals here, for improved syntax in the conditionals
49 $is_myisam_or_aria = $is_isam = $is_innodb = $is_berkeleydb = $is_aria = $is_pbxt = false;
50 // set initial value of these globals, based on the current table engine
51 PMA_set_global_variables_for_engine($tbl_storage_engine);
53 if ($is_aria) {
54 // the value for transactional can be implicit
55 // (no create option found, in this case it means 1)
56 // or explicit (option found with a value of 0 or 1)
57 // ($transactional may have been set by libraries/tbl_info.inc.php,
58 // from the $create_options)
59 $transactional = (isset($transactional) && $transactional == '0') ? '0' : '1';
60 $page_checksum = (isset($page_checksum)) ? $page_checksum : '';
63 $reread_info = false;
64 $table_alters = array();
66 /**
67 * If the table has to be moved to some other database
69 if (isset($_REQUEST['submit_move']) || isset($_REQUEST['submit_copy'])) {
70 $_message = '';
71 include_once 'tbl_move_copy.php';
73 /**
74 * If the table has to be maintained
76 if (isset($_REQUEST['table_maintenance'])) {
77 include_once 'sql.php';
78 unset($result);
80 /**
81 * Updates table comment, type and options if required
83 if (isset($_REQUEST['submitoptions'])) {
84 $_message = '';
85 $warning_messages = array();
87 if (isset($_REQUEST['new_name'])) {
88 if ($pma_table->rename($_REQUEST['new_name'])) {
89 $_message .= $pma_table->getLastMessage();
90 $result = true;
91 $GLOBALS['table'] = $pma_table->getName();
92 $reread_info = true;
93 $reload = true;
94 } else {
95 $_message .= $pma_table->getLastError();
96 $result = false;
99 if (isset($_REQUEST['comment'])
100 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']) {
101 $table_alters[] = 'COMMENT = \'' . PMA_sqlAddSlashes($_REQUEST['comment']) . '\'';
103 if (! empty($_REQUEST['new_tbl_storage_engine'])
104 && strtolower($_REQUEST['new_tbl_storage_engine']) !== strtolower($tbl_storage_engine)) {
105 $table_alters[] = 'ENGINE = ' . $_REQUEST['new_tbl_storage_engine'];
106 $tbl_storage_engine = $_REQUEST['new_tbl_storage_engine'];
107 // reset the globals for the new engine
108 PMA_set_global_variables_for_engine($tbl_storage_engine);
109 if ($is_aria) {
110 $transactional = (isset($transactional) && $transactional == '0') ? '0' : '1';
111 $page_checksum = (isset($page_checksum)) ? $page_checksum : '';
115 if (! empty($_REQUEST['tbl_collation'])
116 && $_REQUEST['tbl_collation'] !== $tbl_collation) {
117 $table_alters[] = 'DEFAULT ' . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
120 if (($is_myisam_or_aria || $is_isam)
121 && isset($_REQUEST['new_pack_keys'])
122 && $_REQUEST['new_pack_keys'] != (string)$pack_keys) {
123 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
126 $checksum = empty($checksum) ? '0' : '1';
127 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
128 if ($is_myisam_or_aria
129 && $_REQUEST['new_checksum'] !== $checksum) {
130 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
133 $_REQUEST['new_transactional'] = empty($_REQUEST['new_transactional']) ? '0' : '1';
134 if ($is_aria
135 && $_REQUEST['new_transactional'] !== $transactional) {
136 $table_alters[] = 'TRANSACTIONAL = ' . $_REQUEST['new_transactional'];
139 $_REQUEST['new_page_checksum'] = empty($_REQUEST['new_page_checksum']) ? '0' : '1';
140 if ($is_aria
141 && $_REQUEST['new_page_checksum'] !== $page_checksum) {
142 $table_alters[] = 'PAGE_CHECKSUM = ' . $_REQUEST['new_page_checksum'];
145 $delay_key_write = empty($delay_key_write) ? '0' : '1';
146 $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
147 if ($is_myisam_or_aria
148 && $_REQUEST['new_delay_key_write'] !== $delay_key_write) {
149 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
152 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
153 && ! empty($_REQUEST['new_auto_increment'])
154 && (! isset($auto_increment) || $_REQUEST['new_auto_increment'] !== $auto_increment)) {
155 $table_alters[] = 'auto_increment = ' . PMA_sqlAddSlashes($_REQUEST['new_auto_increment']);
158 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
159 && ! empty($_REQUEST['new_row_format'])
160 && (! isset($row_format) || strtolower($_REQUEST['new_row_format']) !== strtolower($row_format))) {
161 $table_alters[] = 'ROW_FORMAT = ' . PMA_sqlAddSlashes($_REQUEST['new_row_format']);
164 if (count($table_alters) > 0) {
165 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']);
166 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
167 $result .= PMA_DBI_query($sql_query) ? true : false;
168 $reread_info = true;
169 unset($table_alters);
170 foreach (PMA_DBI_get_warnings() as $warning) {
171 // In MariaDB 5.1.44, when altering a table from Maria to MyISAM
172 // and if TRANSACTIONAL was set, the system reports an error;
173 // I discussed with a Maria developer and he agrees that this
174 // should not be reported with a Level of Error, so here
175 // I just ignore it. But there are other 1478 messages
176 // that it's better to show.
177 if (! ($_REQUEST['new_tbl_storage_engine'] == 'MyISAM' && $warning['Code'] == '1478' && $warning['Level'] == 'Error')) {
178 $warning_messages[] = $warning['Level'] . ': #' . $warning['Code']
179 . ' ' . $warning['Message'];
185 * Reordering the table has been requested by the user
187 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
188 $sql_query = '
189 ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
190 ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
191 if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
192 $sql_query .= ' DESC';
194 $result = PMA_DBI_query($sql_query);
195 } // end if
198 * A partition operation has been requested by the user
200 if (isset($_REQUEST['submit_partition']) && ! empty($_REQUEST['partition_operation'])) {
201 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . $_REQUEST['partition_operation'] . ' PARTITION ' . $_REQUEST['partition_name'];
202 $result = PMA_DBI_query($sql_query);
203 } // end if
205 if ($reread_info) {
206 // to avoid showing the old value (for example the AUTO_INCREMENT) after
207 // a change, clear the cache
208 PMA_Table::$cache = array();
209 $page_checksum = $checksum = $delay_key_write = 0;
210 include 'libraries/tbl_info.inc.php';
212 unset($reread_info);
215 * Displays top menu links in non ajax requests
217 if (!isset($_REQUEST['ajax_request'])) {
218 include_once 'libraries/tbl_links.inc.php';
220 if (isset($result) && empty($message_to_show)) {
221 // set to success by default, because result set could be empty
222 // (for example, a table rename)
223 $_type = 'success';
224 if (empty($_message)) {
225 $_message = $result ? $message = PMA_Message::success(__('Your SQL query has been executed successfully')) : PMA_Message::error(__('Error'));
226 // $result should exist, regardless of $_message
227 $_type = $result ? 'success' : 'error';
228 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
229 $extra_data['sql_query'] = PMA_showMessage(null, $sql_query);
230 PMA_ajaxResponse($_message, $_message->isSuccess(), $extra_data);
233 if (! empty($warning_messages)) {
234 $_message = new PMA_Message;
235 $_message->addMessages($warning_messages);
236 $_message->isError(true);
237 if ( $_REQUEST['ajax_request'] == true) {
238 PMA_ajaxResponse($_message, false);
240 unset($warning_messages);
243 PMA_showMessage($_message, $sql_query, $_type);
244 unset($_message, $_type);
247 $url_params['goto'] =
248 $url_params['back'] = 'tbl_operations.php';
251 * Get columns names
253 $columns = PMA_DBI_get_columns($GLOBALS['db'], $GLOBALS['table']);
256 * Displays the page
259 <!-- Order the table -->
260 <div class="operations_half_width">
261 <form method="post" id="alterTableOrderby" action="tbl_operations.php" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '');?>>
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['Field']) . '">'
269 . htmlspecialchars($fieldname['Field']) . '</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_storage_engine', null, $tbl_storage_engine); ?>
374 </td>
375 </tr>
377 <!-- Table character set -->
378 <tr><td><?php echo __('Collation'); ?></td>
379 <td><?php echo PMA_generateCharsetDropdownBox(
380 PMA_CSDROPDOWN_COLLATION,
381 'tbl_collation', null, $tbl_collation, false, 3
382 ); ?>
383 </td>
384 </tr>
385 <?php
386 if ($is_myisam_or_aria || $is_isam) {
388 <tr>
389 <td><label for="new_pack_keys">PACK_KEYS</label></td>
390 <td><select name="new_pack_keys" id="new_pack_keys">
391 <option value="DEFAULT"
392 <?php if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?>
393 >DEFAULT</option>
394 <option value="0"
395 <?php if ($pack_keys == '0') echo 'selected="selected"'; ?>
396 >0</option>
397 <option value="1"
398 <?php if ($pack_keys == '1') echo 'selected="selected"'; ?>
399 >1</option>
400 </select>
401 </td>
402 </tr>
403 <?php
404 } // end if (MYISAM|ISAM)
406 if ($is_myisam_or_aria) {
408 <tr><td><label for="new_checksum">CHECKSUM</label></td>
409 <td><input type="checkbox" name="new_checksum" id="new_checksum"
410 value="1"
411 <?php echo (isset($checksum) && $checksum == 1)
412 ? ' checked="checked"'
413 : ''; ?> />
414 </td>
415 </tr>
417 <tr><td><label for="new_delay_key_write">DELAY_KEY_WRITE</label></td>
418 <td><input type="checkbox" name="new_delay_key_write" id="new_delay_key_write"
419 value="1"
420 <?php echo (isset($delay_key_write) && $delay_key_write == 1)
421 ? ' checked="checked"'
422 : ''; ?> />
423 </td>
424 </tr>
426 <?php
427 } // end if (MYISAM)
429 if ($is_aria) {
431 <tr><td><label for="new_transactional">TRANSACTIONAL</label></td>
432 <td><input type="checkbox" name="new_transactional" id="new_transactional"
433 value="1"
434 <?php echo (isset($transactional) && $transactional == 1)
435 ? ' checked="checked"'
436 : ''; ?> />
437 </td>
438 </tr>
440 <tr><td><label for="new_page_checksum">PAGE_CHECKSUM</label></td>
441 <td><input type="checkbox" name="new_page_checksum" id="new_page_checksum"
442 value="1"
443 <?php echo (isset($page_checksum) && $page_checksum == 1)
444 ? ' checked="checked"'
445 : ''; ?> />
446 </td>
447 </tr>
449 <?php
450 } // end if (ARIA)
452 if (isset($auto_increment) && strlen($auto_increment) > 0
453 && ($is_myisam_or_aria || $is_innodb || $is_pbxt)) {
455 <tr><td><label for="auto_increment_opt">AUTO_INCREMENT</label></td>
456 <td><input type="text" name="new_auto_increment" id="auto_increment_opt"
457 value="<?php echo $auto_increment; ?>" /></td>
458 </tr>
459 <?php
460 } // end if (MYISAM|INNODB)
462 // the outer array is for engines, the inner array contains the dropdown
463 // option values as keys then the dropdown option labels
465 $possible_row_formats = array(
466 'ARIA' => array(
467 'FIXED' => 'FIXED',
468 'DYNAMIC' => 'DYNAMIC',
469 'PAGE' => 'PAGE'
471 'MARIA' => array(
472 'FIXED' => 'FIXED',
473 'DYNAMIC' => 'DYNAMIC',
474 'PAGE' => 'PAGE'
476 'MYISAM' => array(
477 'FIXED' => 'FIXED',
478 'DYNAMIC' => 'DYNAMIC'
480 'PBXT' => array(
481 'FIXED' => 'FIXED',
482 'DYNAMIC' => 'DYNAMIC'
484 'INNODB' => array(
485 'COMPACT' => 'COMPACT',
486 'REDUNDANT' => 'REDUNDANT')
489 $innodb_engine_plugin = PMA_StorageEngine::getEngine('innodb');
490 $innodb_plugin_version = $innodb_engine_plugin->getInnodbPluginVersion();
491 if (!empty($innodb_plugin_version)) {
492 $innodb_file_format = $innodb_engine_plugin->getInnodbFileFormat();
493 } else {
494 $innodb_file_format = '';
496 if ('Barracuda' == $innodb_file_format && $innodb_engine_plugin->supportsFilePerTable()) {
497 $possible_row_formats['INNODB']['DYNAMIC'] = 'DYNAMIC';
498 $possible_row_formats['INNODB']['COMPRESSED'] = 'COMPRESSED';
500 unset($innodb_engine_plugin, $innodb_plugin_version, $innodb_file_format);
502 // for MYISAM there is also COMPRESSED but it can be set only by the
503 // myisampack utility, so don't offer here the choice because if we
504 // try it inside an ALTER TABLE, MySQL (at least in 5.1.23-maria)
505 // does not return a warning
506 // (if the table was compressed, it can be seen on the Structure page)
508 if (isset($possible_row_formats[$tbl_storage_engine])) {
509 $current_row_format = strtoupper($showtable['Row_format']);
510 echo '<tr><td><label for="new_row_format">ROW_FORMAT</label></td>';
511 echo '<td>';
512 echo PMA_generate_html_dropdown('new_row_format', $possible_row_formats[$tbl_storage_engine], $current_row_format, 'new_row_format');
513 unset($possible_row_formats, $current_row_format);
514 echo '</td>';
515 echo '</tr>';
518 </table>
519 </fieldset>
520 <fieldset class="tblFooters">
521 <input type="submit" name="submitoptions" value="<?php echo __('Go'); ?>" />
522 </fieldset>
523 </form>
524 </div>
526 <!-- Copy table -->
527 <div class="operations_half_width">
528 <form method="post" action="tbl_operations.php" name="copyTable" id="copyTable" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '');?>
529 onsubmit="return emptyFormElements(this, 'new_name')">
530 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
531 <input type="hidden" name="reload" value="1" />
532 <fieldset>
533 <legend><?php echo __('Copy table to (database<b>.</b>table):'); ?></legend>
534 <?php if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
536 <input type="text" maxlength="100" size="30" name="target_db" value="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
537 <?php
538 } else {
540 <select name="target_db">
541 <?php echo $GLOBALS['pma']->databases->getHtmlOptions(true, false); ?>
542 </select>
543 <?php
544 } // end if
546 &nbsp;<strong>.</strong>&nbsp;
547 <input type="text" size="20" name="new_name" onfocus="this.select()" value="<?php echo htmlspecialchars($GLOBALS['table']); ?>"/><br />
548 <?php
549 $choices = array(
550 'structure' => __('Structure only'),
551 'data' => __('Structure and data'),
552 'dataonly' => __('Data only'));
553 PMA_display_html_radio('what', $choices, 'data', true);
554 unset($choices);
557 <input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" />
558 <label for="checkbox_drop"><?php echo sprintf(__('Add %s'), 'DROP TABLE'); ?></label><br />
559 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_cp" />
560 <label for="checkbox_auto_increment_cp"><?php echo __('Add AUTO_INCREMENT value'); ?></label><br />
561 <?php
562 // display "Add constraints" choice only if there are
563 // foreign keys
564 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
566 <input type="checkbox" name="add_constraints" value="1" id="checkbox_constraints" />
567 <label for="checkbox_constraints"><?php echo __('Add constraints'); ?></label><br />
568 <?php
569 } // endif
570 if (isset($_COOKIE['pma_switch_to_new'])
571 && $_COOKIE['pma_switch_to_new'] == 'true') {
572 $pma_switch_to_new = 'true';
575 <input type="checkbox" name="switch_to_new" value="true"
576 id="checkbox_switch"<?php echo
577 isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
578 ? ' checked="checked"'
579 : ''; ?> />
580 <label for="checkbox_switch"><?php echo __('Switch to copied table'); ?></label>
581 </fieldset>
582 <fieldset class="tblFooters">
583 <input type="submit" name="submit_copy" value="<?php echo __('Go'); ?>" />
584 </fieldset>
585 </form>
586 </div>
588 <br class="clearfloat"/>
590 <div class="operations_half_width">
591 <fieldset>
592 <legend><?php echo __('Table maintenance'); ?></legend>
594 <ul id="tbl_maintenance" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '');?>>
595 <?php
596 // Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
597 if ($is_myisam_or_aria || $is_innodb || $is_berkeleydb) {
598 if ($is_myisam_or_aria || $is_innodb) {
599 $this_url_params = array_merge(
600 $url_params,
601 array(
602 'sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table']),
603 'table_maintenance' => 'Go',
607 <li><a class='maintain_action' href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
608 <?php echo __('Check table'); ?></a>
609 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?>
610 </li>
611 <?php
613 if ($is_innodb) {
614 $this_url_params = array_merge(
615 $url_params,
616 array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ENGINE = InnoDB')
619 <li><a class='maintain_action' href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
620 <?php echo __('Defragment table'); ?></a>
621 <?php echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?>
622 </li>
623 <?php
625 if ($is_myisam_or_aria || $is_berkeleydb) {
626 $this_url_params = array_merge(
627 $url_params,
628 array(
629 'sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table']),
630 'table_maintenance' => 'Go',
634 <li><a class='maintain_action' href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
635 <?php echo __('Analyze table'); ?></a>
636 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?>
637 </li>
638 <?php
640 if ($is_myisam_or_aria && !PMA_DRIZZLE) {
641 $this_url_params = array_merge(
642 $url_params,
643 array(
644 'sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table']),
645 'table_maintenance' => 'Go',
649 <li><a class='maintain_action' href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
650 <?php echo __('Repair table'); ?></a>
651 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?>
652 </li>
653 <?php
655 if (($is_myisam_or_aria || $is_innodb || $is_berkeleydb) && !PMA_DRIZZLE) {
656 $this_url_params = array_merge(
657 $url_params,
658 array(
659 'sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table']),
660 'table_maintenance' => 'Go',
664 <li><a class='maintain_action' href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
665 <?php echo __('Optimize table'); ?></a>
666 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?>
667 </li>
668 <?php
670 } // end MYISAM or BERKELEYDB case
671 $this_url_params = array_merge(
672 $url_params,
673 array(
674 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
675 'message_to_show' => sprintf(
676 __('Table %s has been flushed'),
677 htmlspecialchars($GLOBALS['table'])
679 'reload' => 1,
683 <li><a class='maintain_action' href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
684 <?php echo __('Flush the table (FLUSH)'); ?></a>
685 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?>
686 </li>
687 </ul>
688 </fieldset>
689 </div>
690 <?php if (! (isset($db_is_information_schema) && $db_is_information_schema)) { ?>
691 <div class="operations_half_width">
692 <fieldset class="caution">
693 <legend><?php echo __('Delete data or table'); ?></legend>
695 <ul>
696 <?php
697 if (! $tbl_is_view && ! (isset($db_is_information_schema) && $db_is_information_schema)) {
698 $this_sql_query = 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table']);
699 $this_url_params = array_merge(
700 $url_params,
701 array(
702 'sql_query' => $this_sql_query,
703 'goto' => 'tbl_structure.php',
704 'reload' => '1',
705 'message_to_show' => sprintf(__('Table %s has been emptied'), htmlspecialchars($table)),
709 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'id="truncate_tbl_anchor" class="ajax"' : ''); ?>>
710 <?php echo __('Empty the table (TRUNCATE)'); ?></a>
711 <?php echo PMA_showMySQLDocu('SQL-Syntax', 'TRUNCATE_TABLE'); ?>
712 </li>
713 <?php
715 if (! (isset($db_is_information_schema) && $db_is_information_schema)) {
716 $this_sql_query = 'DROP TABLE ' . PMA_backquote($GLOBALS['table']);
717 $this_url_params = array_merge(
718 $url_params,
719 array(
720 'sql_query' => $this_sql_query,
721 'goto' => 'db_operations.php',
722 'reload' => '1',
723 'purge' => '1',
724 'message_to_show' => sprintf(($tbl_is_view ? __('View %s has been dropped') : __('Table %s has been dropped')), htmlspecialchars($table)),
725 // table name is needed to avoid running
726 // PMA_relationsCleanupDatabase() on the whole db later
727 'table' => $GLOBALS['table'],
731 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'id="drop_tbl_anchor"' : ''); ?>>
732 <?php echo __('Delete the table (DROP)'); ?></a>
733 <?php echo PMA_showMySQLDocu('SQL-Syntax', 'DROP_TABLE'); ?>
734 </li>
735 <?php
738 </ul>
739 </fieldset>
740 </div>
741 <?php
744 <br class="clearfloat">
745 <?php if (PMA_Partition::havePartitioning()) {
746 $partition_names = PMA_Partition::getPartitionNames($db, $table);
747 // show the Partition maintenance section only if we detect a partition
748 if (! is_null($partition_names[0])) {
750 <div class="operations_half_width">
751 <form method="post" action="tbl_operations.php">
752 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
753 <fieldset>
754 <legend><?php echo __('Partition maintenance'); ?></legend>
755 <?php
756 $html_select = '<select name="partition_name">' . "\n";
757 foreach ($partition_names as $one_partition) {
758 $one_partition = htmlspecialchars($one_partition);
759 $html_select .= '<option value="' . $one_partition . '">' . $one_partition . '</option>' . "\n";
761 $html_select .= '</select>' . "\n";
762 printf(__('Partition %s'), $html_select);
763 unset($partition_names, $one_partition, $html_select);
764 $choices = array(
765 'ANALYZE' => __('Analyze'),
766 'CHECK' => __('Check'),
767 'OPTIMIZE' => __('Optimize'),
768 'REBUILD' => __('Rebuild'),
769 'REPAIR' => __('Repair'));
770 PMA_display_html_radio('partition_operation', $choices, '', false);
771 unset($choices);
772 echo PMA_showMySQLDocu('partitioning_maintenance', 'partitioning_maintenance');
773 // I'm not sure of the best way to display that; this link does
774 // not depend on the Go button
775 $this_url_params = array_merge(
776 $url_params,
777 array(
778 'sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' REMOVE PARTITIONING'
782 <br /><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
783 <?php echo __('Remove partitioning'); ?></a>
784 </fieldset>
785 <fieldset class="tblFooters">
786 <input type="submit" name="submit_partition" value="<?php echo __('Go'); ?>" />
787 </fieldset>
788 </form>
789 </div>
790 <?php
791 } // end if
792 } // end if
794 // Referential integrity check
795 // The Referential integrity check was intended for the non-InnoDB
796 // tables for which the relations are defined in pmadb
797 // so I assume that if the current table is InnoDB, I don't display
798 // this choice (InnoDB maintains integrity by itself)
800 if ($cfgRelation['relwork'] && ! $is_innodb) {
801 PMA_DBI_select_db($GLOBALS['db']);
802 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
804 if ($foreign) {
806 <!-- Referential integrity check -->
807 <div class="operations_half_width">
808 <fieldset>
809 <legend><?php echo __('Check referential integrity:'); ?></legend>
810 <ul>
811 <?php
812 echo "\n";
813 foreach ($foreign AS $master => $arr) {
814 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
815 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
816 . PMA_backquote($arr['foreign_table']);
817 if ($arr['foreign_table'] == $GLOBALS['table']) {
818 $foreign_table = $GLOBALS['table'] . '1';
819 $join_query .= ' AS ' . PMA_backquote($foreign_table);
820 } else {
821 $foreign_table = $arr['foreign_table'];
823 $join_query .= ' ON '
824 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
825 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
826 . ' WHERE '
827 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
828 . ' IS NULL AND '
829 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
830 . ' IS NOT NULL';
831 $this_url_params = array_merge(
832 $url_params,
833 array('sql_query' => $join_query)
835 echo ' <li>'
836 . '<a href="sql.php'
837 . PMA_generate_common_url($this_url_params)
838 . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
839 . '</a></li>' . "\n";
840 } // foreach $foreign
841 unset($foreign_table, $join_query);
843 </ul>
844 </fieldset>
845 </div>
846 <?php
847 } // end if ($foreign)
849 } // end if (!empty($cfg['Server']['relation']))
853 * Displays the footer
855 require 'libraries/footer.inc.php';
858 function PMA_set_global_variables_for_engine($tbl_storage_engine)
860 global $is_myisam_or_aria, $is_innodb, $is_isam, $is_berkeleydb, $is_aria, $is_pbxt;
862 $is_myisam_or_aria = $is_isam = $is_innodb = $is_berkeleydb = $is_aria = $is_pbxt = false;
863 $upper_tbl_storage_engine = strtoupper($tbl_storage_engine);
865 //Options that apply to MYISAM usually apply to ARIA
866 $is_myisam_or_aria = ($upper_tbl_storage_engine == 'MYISAM' || $upper_tbl_storage_engine == 'ARIA' || $upper_tbl_storage_engine == 'MARIA');
867 $is_aria = ($upper_tbl_storage_engine == 'ARIA');
869 $is_isam = ($upper_tbl_storage_engine == 'ISAM');
870 $is_innodb = ($upper_tbl_storage_engine == 'INNODB');
871 $is_berkeleydb = ($upper_tbl_storage_engine == 'BERKELEYDB');
872 $is_pbxt = ($upper_tbl_storage_engine == 'PBXT');