Merge remote branch 'origin/master'
[phpmyadmin/dkf.git] / tbl_operations.php
blob4e0738ab744fca8e9cd282d8437340e6ecd7de98
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/common.inc.php';
13 require_once './libraries/Table.class.php';
15 $pma_table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
17 /**
18 * Runs common work
20 require './libraries/tbl_common.php';
21 $url_query .= '&amp;goto=tbl_operations.php&amp;back=tbl_operations.php';
22 $url_params['goto'] = $url_params['back'] = 'tbl_operations.php';
24 /**
25 * Gets relation settings
27 require_once './libraries/relation.lib.php';
28 $cfgRelation = PMA_getRelationsParam();
30 /**
31 * Gets available MySQL charsets and storage engines
33 require_once './libraries/mysql_charsets.lib.php';
34 require_once './libraries/StorageEngine.class.php';
36 /**
37 * Class for partition management
39 require_once './libraries/Partition.class.php';
41 // reselect current db (needed in some cases probably due to
42 // the calling of relation.lib.php)
43 PMA_DBI_select_db($GLOBALS['db']);
45 /**
46 * Gets tables informations
49 require './libraries/tbl_info.inc.php';
51 // define some globals here, for improved syntax in the conditionals
52 $is_myisam_or_maria = $is_isam = $is_innodb = $is_berkeleydb = $is_maria = $is_pbxt = false;
53 // set initial value of these globals, based on the current table engine
54 PMA_set_global_variables_for_engine($tbl_type);
56 if ($is_maria) {
57 // the value for transactional can be implicit
58 // (no create option found, in this case it means 1)
59 // or explicit (option found with a value of 0 or 1)
60 // ($transactional may have been set by libraries/tbl_info.inc.php,
61 // from the $create_options)
62 $transactional = (isset($transactional) && $transactional == '0') ? '0' : '1';
63 $page_checksum = (isset($page_checksum)) ? $page_checksum : '';
66 $reread_info = false;
67 $table_alters = array();
69 /**
70 * Updates table comment, type and options if required
72 if (isset($_REQUEST['submitoptions'])) {
73 $_message = '';
74 $warning_messages = array();
76 if (isset($_REQUEST['new_name'])) {
77 if ($pma_table->rename($_REQUEST['new_name'])) {
78 $_message .= $pma_table->getLastMessage();
79 $result = true;
80 $GLOBALS['table'] = $pma_table->getName();
81 $reread_info = true;
82 $reload = true;
83 } else {
84 $_message .= $pma_table->getLastError();
85 $result = false;
88 if (isset($_REQUEST['comment'])
89 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']) {
90 $table_alters[] = 'COMMENT = \'' . PMA_sqlAddslashes($_REQUEST['comment']) . '\'';
92 if (! empty($_REQUEST['new_tbl_type'])
93 && strtolower($_REQUEST['new_tbl_type']) !== strtolower($tbl_type)) {
94 $table_alters[] = 'ENGINE = ' . $_REQUEST['new_tbl_type'];
95 $tbl_type = $_REQUEST['new_tbl_type'];
96 // reset the globals for the new engine
97 PMA_set_global_variables_for_engine($tbl_type);
98 if ($is_maria) {
99 $transactional = (isset($transactional) && $transactional == '0') ? '0' : '1';
100 $page_checksum = (isset($page_checksum)) ? $page_checksum : '';
104 if (! empty($_REQUEST['tbl_collation'])
105 && $_REQUEST['tbl_collation'] !== $tbl_collation) {
106 $table_alters[] = 'DEFAULT ' . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
109 if (($is_myisam_or_maria || $is_isam)
110 && isset($_REQUEST['new_pack_keys'])
111 && $_REQUEST['new_pack_keys'] != (string)$pack_keys) {
112 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
115 $checksum = empty($checksum) ? '0' : '1';
116 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
117 if ($is_myisam_or_maria
118 && $_REQUEST['new_checksum'] !== $checksum) {
119 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
122 $_REQUEST['new_transactional'] = empty($_REQUEST['new_transactional']) ? '0' : '1';
123 if ($is_maria
124 && $_REQUEST['new_transactional'] !== $transactional) {
125 $table_alters[] = 'TRANSACTIONAL = ' . $_REQUEST['new_transactional'];
128 $_REQUEST['new_page_checksum'] = empty($_REQUEST['new_page_checksum']) ? '0' : '1';
129 if ($is_maria
130 && $_REQUEST['new_page_checksum'] !== $page_checksum) {
131 $table_alters[] = 'PAGE_CHECKSUM = ' . $_REQUEST['new_page_checksum'];
134 $delay_key_write = empty($delay_key_write) ? '0' : '1';
135 $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
136 if ($is_myisam_or_maria
137 && $_REQUEST['new_delay_key_write'] !== $delay_key_write) {
138 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
141 if (($is_myisam_or_maria || $is_innodb || $is_pbxt)
142 && ! empty($_REQUEST['new_auto_increment'])
143 && (! isset($auto_increment) || $_REQUEST['new_auto_increment'] !== $auto_increment)) {
144 $table_alters[] = 'auto_increment = ' . PMA_sqlAddslashes($_REQUEST['new_auto_increment']);
147 if (($is_myisam_or_maria || $is_innodb || $is_pbxt)
148 && ! empty($_REQUEST['new_row_format'])
149 && (! isset($row_format) || strtolower($_REQUEST['new_row_format']) !== strtolower($row_format))) {
150 $table_alters[] = 'ROW_FORMAT = ' . PMA_sqlAddslashes($_REQUEST['new_row_format']);
153 if (count($table_alters) > 0) {
154 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']);
155 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
156 $result .= PMA_DBI_query($sql_query) ? true : false;
157 $reread_info = true;
158 unset($table_alters);
159 foreach (PMA_DBI_get_warnings() as $warning) {
160 // In MariaDB 5.1.44, when altering a table from Maria to MyISAM
161 // and if TRANSACTIONAL was set, the system reports an error;
162 // I discussed with a Maria developer and he agrees that this
163 // should not be reported with a Level of Error, so here
164 // I just ignore it. But there are other 1478 messages
165 // that it's better to show.
166 if (! ($_REQUEST['new_tbl_type'] == 'MyISAM' && $warning['Code'] == '1478' && $warning['Level'] == 'Error')) {
167 $warning_messages[] = $warning['Level'] . ': #' . $warning['Code']
168 . ' ' . $warning['Message'];
174 * Reordering the table has been requested by the user
176 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
177 $sql_query = '
178 ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
179 ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
180 if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
181 $sql_query .= ' DESC';
183 $result = PMA_DBI_query($sql_query);
184 } // end if
187 * A partition operation has been requested by the user
189 if (isset($_REQUEST['submit_partition']) && ! empty($_REQUEST['partition_operation'])) {
190 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . $_REQUEST['partition_operation'] . ' PARTITION ' . $_REQUEST['partition_name'];
191 $result = PMA_DBI_query($sql_query);
192 } // end if
194 if ($reread_info) {
195 // to avoid showing the old value (for example the AUTO_INCREMENT) after
196 // a change, clear the cache
197 PMA_Table::$cache = array();
198 $page_checksum = $checksum = $delay_key_write = 0;
199 require './libraries/tbl_info.inc.php';
201 unset($reread_info);
204 * Displays top menu links
206 require_once './libraries/tbl_links.inc.php';
208 if (isset($result) && empty($zero_rows)) {
209 // set to success by default, because result set could be empty
210 // (for example, a table rename)
211 $_type = 'success';
212 if (empty($_message)) {
213 $_message = $result ? __('Your SQL query has been executed successfully') : __('Error');
214 // $result should exist, regardless of $_message
215 $_type = $result ? 'success' : 'error';
217 if (! empty($warning_messages)) {
218 $_message = new PMA_Message;
219 $_message->addMessages($warning_messages);
220 $_message->isWarning(true);
221 unset($warning_messages);
223 PMA_showMessage($_message, $sql_query, $_type);
224 unset($_message, $_type);
227 $url_params['goto'] = 'tbl_operations.php';
228 $url_params['back'] = 'tbl_operations.php';
231 * Get columns names
233 $local_query = '
234 SHOW COLUMNS
235 FROM ' . PMA_backquote($GLOBALS['table']) . '
236 FROM ' . PMA_backquote($GLOBALS['db']);
237 $columns = PMA_DBI_fetch_result($local_query, null, 'Field');
238 unset($local_query);
241 * Displays the page
244 <!-- Order the table -->
245 <div id="div_table_order">
246 <form method="post" action="tbl_operations.php">
247 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
248 <fieldset id="fieldset_table_order">
249 <legend><?php echo __('Alter table order by'); ?></legend>
250 <select name="order_field">
251 <?php
252 foreach ($columns as $fieldname) {
253 echo ' <option value="' . htmlspecialchars($fieldname) . '">'
254 . htmlspecialchars($fieldname) . '</option>' . "\n";
256 unset($columns);
258 </select> <?php echo __('(singly)'); ?>
259 <select name="order_order">
260 <option value="asc"><?php echo __('Ascending'); ?></option>
261 <option value="desc"><?php echo __('Descending'); ?></option>
262 </select>
263 </fieldset>
264 <fieldset class="tblFooters">
265 <input type="submit" name="submitorderby" value="<?php echo __('Go'); ?>" />
266 </fieldset>
267 </form>
268 </div>
270 <!-- Move table -->
271 <div id="div_table_rename">
272 <form method="post" action="tbl_move_copy.php"
273 onsubmit="return emptyFormElements(this, 'new_name')">
274 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
275 <input type="hidden" name="reload" value="1" />
276 <input type="hidden" name="what" value="data" />
277 <fieldset id="fieldset_table_rename">
278 <legend><?php echo __('Move table to (database<b>.</b>table):'); ?></legend>
279 <?php if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
281 <input type="text" maxlength="100" size="30" name="target_db" value="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
282 <?php
283 } else {
285 <select name="target_db">
286 <?php echo $GLOBALS['pma']->databases->getHtmlOptions(true, false); ?>
287 </select>
288 <?php
289 } // end if
291 &nbsp;<strong>.</strong>&nbsp;
292 <input type="text" size="20" name="new_name" onfocus="this.select()"
293 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br />
294 <?php
295 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
296 // next value but users can decide if they want it or not for the operation
298 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_mv" checked="checked" />
299 <label for="checkbox_auto_increment_mv"><?php echo __('Add AUTO_INCREMENT value'); ?></label><br />
300 </fieldset>
301 <fieldset class="tblFooters">
302 <input type="submit" name="submit_move" value="<?php echo __('Go'); ?>" />
303 </fieldset>
304 </form>
305 </div>
307 <?php
308 if (strstr($show_comment, '; InnoDB free') === false) {
309 if (strstr($show_comment, 'InnoDB free') === false) {
310 // only user entered comment
311 $comment = $show_comment;
312 } else {
313 // here we have just InnoDB generated part
314 $comment = '';
316 } else {
317 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
318 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
321 // PACK_KEYS: MyISAM or ISAM
322 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
323 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3, PBXT
325 // Here should be version check for InnoDB, however it is supported
326 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
327 // check for version
330 <!-- Table options -->
331 <div id="div_table_options">
332 <form method="post" action="tbl_operations.php">
333 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
334 <input type="hidden" name="reload" value="1" />
335 <fieldset>
336 <legend><?php echo __('Table options'); ?></legend>
338 <table>
339 <!-- Change table name -->
340 <tr><td><?php echo __('Rename table to'); ?></td>
341 <td><input type="text" size="20" name="new_name" onfocus="this.select()"
342 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
343 </td>
344 </tr>
346 <!-- Table comments -->
347 <tr><td><?php echo __('Table comments'); ?></td>
348 <td><input type="text" name="comment" maxlength="60" size="30"
349 value="<?php echo htmlspecialchars($comment); ?>" onfocus="this.select()" />
350 <input type="hidden" name="prev_comment" value="<?php echo htmlspecialchars($comment); ?>" />
351 </td>
352 </tr>
354 <!-- Storage engine -->
355 <tr><td><?php echo __('Storage Engine'); ?>
356 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
357 </td>
358 <td><?php echo PMA_StorageEngine::getHtmlSelect('new_tbl_type', null, $tbl_type); ?>
359 </td>
360 </tr>
362 <!-- Table character set -->
363 <tr><td><?php echo __('Collation'); ?></td>
364 <td><?php echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION,
365 'tbl_collation', null, $tbl_collation, false, 3); ?>
366 </td>
367 </tr>
368 <?php
369 if ($is_myisam_or_maria || $is_isam) {
371 <tr>
372 <td><label for="new_pack_keys">PACK_KEYS</label></td>
373 <td><select name="new_pack_keys" id="new_pack_keys">
374 <option value="DEFAULT"
375 <?php if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?>
376 >DEFAULT</option>
377 <option value="0"
378 <?php if ($pack_keys == '0') echo 'selected="selected"'; ?>
379 >0</option>
380 <option value="1"
381 <?php if ($pack_keys == '1') echo 'selected="selected"'; ?>
382 >1</option>
383 </select>
384 </td>
385 </tr>
386 <?php
387 } // end if (MYISAM|ISAM)
389 if ($is_myisam_or_maria) {
391 <tr><td><label for="new_checksum">CHECKSUM</label></td>
392 <td><input type="checkbox" name="new_checksum" id="new_checksum"
393 value="1"
394 <?php echo (isset($checksum) && $checksum == 1)
395 ? ' checked="checked"'
396 : ''; ?> />
397 </td>
398 </tr>
400 <tr><td><label for="new_delay_key_write">DELAY_KEY_WRITE</label></td>
401 <td><input type="checkbox" name="new_delay_key_write" id="new_delay_key_write"
402 value="1"
403 <?php echo (isset($delay_key_write) && $delay_key_write == 1)
404 ? ' checked="checked"'
405 : ''; ?> />
406 </td>
407 </tr>
409 <?php
410 } // end if (MYISAM)
412 if ($is_maria) {
414 <tr><td><label for="new_transactional">TRANSACTIONAL</label></td>
415 <td><input type="checkbox" name="new_transactional" id="new_transactional"
416 value="1"
417 <?php echo (isset($transactional) && $transactional == 1)
418 ? ' checked="checked"'
419 : ''; ?> />
420 </td>
421 </tr>
423 <tr><td><label for="new_page_checksum">PAGE_CHECKSUM</label></td>
424 <td><input type="checkbox" name="new_page_checksum" id="new_page_checksum"
425 value="1"
426 <?php echo (isset($page_checksum) && $page_checksum == 1)
427 ? ' checked="checked"'
428 : ''; ?> />
429 </td>
430 </tr>
432 <?php
433 } // end if (MARIA)
435 if (isset($auto_increment) && strlen($auto_increment) > 0
436 && ($is_myisam_or_maria || $is_innodb || $is_pbxt)) {
438 <tr><td><label for="auto_increment_opt">AUTO_INCREMENT</label></td>
439 <td><input type="text" name="new_auto_increment" id="auto_increment_opt"
440 value="<?php echo $auto_increment; ?>" /></td>
441 </tr>
442 <?php
443 } // end if (MYISAM|INNODB)
445 // the outer array is for engines, the inner array contains the dropdown
446 // option values as keys then the dropdown option labels
448 $possible_row_formats = array(
449 'MARIA' => array(
450 'FIXED' => 'FIXED',
451 'DYNAMIC' => 'DYNAMIC',
452 'PAGE' => 'PAGE'
454 'MYISAM' => array(
455 'FIXED' => 'FIXED',
456 'DYNAMIC' => 'DYNAMIC'
458 'PBXT' => array(
459 'FIXED' => 'FIXED',
460 'DYNAMIC' => 'DYNAMIC'
462 'INNODB' => array(
463 'COMPACT' => 'COMPACT',
464 'REDUNDANT' => 'REDUNDANT')
467 $innodb_engine_plugin = PMA_StorageEngine::getEngine('innodb');
468 $innodb_plugin_version = $innodb_engine_plugin->getInnodbPluginVersion();
469 if (!empty($innodb_plugin_version)) {
470 $innodb_file_format = $innodb_engine_plugin->getInnodbFileFormat();
471 } else {
472 $innodb_file_format = '';
474 if ('Barracuda' == $innodb_file_format && $innodb_engine_plugin->supportsFilePerTable()) {
475 $possible_row_formats['INNODB']['DYNAMIC'] = 'DYNAMIC';
476 $possible_row_formats['INNODB']['COMPRESSED'] = 'COMPRESSED';
478 unset($innodb_engine_plugin, $innodb_plugin_version, $innodb_file_format);
480 // for MYISAM there is also COMPRESSED but it can be set only by the
481 // myisampack utility, so don't offer here the choice because if we
482 // try it inside an ALTER TABLE, MySQL (at least in 5.1.23-maria)
483 // does not return a warning
484 // (if the table was compressed, it can be seen on the Structure page)
486 if (isset($possible_row_formats[$tbl_type])) {
487 $current_row_format = strtoupper($showtable['Row_format']);
488 echo '<tr><td><label for="new_row_format">ROW_FORMAT</label></td>';
489 echo '<td>';
490 echo PMA_generate_html_dropdown('new_row_format', $possible_row_formats[$tbl_type], $current_row_format, 'new_row_format');
491 unset($possible_row_formats, $current_row_format);
492 echo '</td>';
493 echo '</tr>';
496 </table>
497 </fieldset>
498 <fieldset class="tblFooters">
499 <input type="submit" name="submitoptions" value="<?php echo __('Go'); ?>" />
500 </fieldset>
501 </form>
502 </div>
504 <!-- Copy table -->
505 <div id="div_table_copy">
506 <form method="post" action="tbl_move_copy.php"
507 onsubmit="return emptyFormElements(this, 'new_name')">
508 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
509 <input type="hidden" name="reload" value="1" />
510 <fieldset>
511 <legend><?php echo __('Copy table to (database<b>.</b>table):'); ?></legend>
512 <?php if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
514 <input type="text" maxlength="100" size="30" name="target_db" value="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
515 <?php
516 } else {
518 <select name="target_db">
519 <?php echo $GLOBALS['pma']->databases->getHtmlOptions(true, false); ?>
520 </select>
521 <?php
522 } // end if
524 &nbsp;<strong>.</strong>&nbsp;
525 <input type="text" size="20" name="new_name" onfocus="this.select()" value="<?php echo htmlspecialchars($GLOBALS['table']); ?>"/><br />
526 <?php
527 $choices = array(
528 'structure' => __('Structure only'),
529 'data' => __('Structure and data'),
530 'dataonly' => __('Data only'));
531 PMA_display_html_radio('what', $choices, 'data', true);
532 unset($choices);
535 <input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" />
536 <label for="checkbox_drop"><?php echo sprintf(__('Add %s'), 'DROP TABLE'); ?></label><br />
537 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_cp" />
538 <label for="checkbox_auto_increment_cp"><?php echo __('Add AUTO_INCREMENT value'); ?></label><br />
539 <?php
540 // display "Add constraints" choice only if there are
541 // foreign keys
542 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
544 <input type="checkbox" name="add_constraints" value="1" id="checkbox_constraints" />
545 <label for="checkbox_constraints"><?php echo __('Add constraints'); ?></label><br />
546 <?php
547 } // endif
548 if (isset($_COOKIE['pma_switch_to_new'])
549 && $_COOKIE['pma_switch_to_new'] == 'true') {
550 $pma_switch_to_new = 'true';
553 <input type="checkbox" name="switch_to_new" value="true"
554 id="checkbox_switch"<?php echo
555 isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
556 ? ' checked="checked"'
557 : ''; ?> />
558 <label for="checkbox_switch"><?php echo __('Switch to copied table'); ?></label>
559 </fieldset>
560 <fieldset class="tblFooters">
561 <input type="submit" name="submit_copy" value="<?php echo __('Go'); ?>" />
562 </fieldset>
563 </form>
564 </div>
566 <br class="clearfloat"/>
568 <div id="div_table_maintenance">
569 <fieldset>
570 <legend><?php echo __('Table maintenance'); ?></legend>
572 <ul>
573 <?php
574 // Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
575 if ($is_myisam_or_maria || $is_innodb || $is_berkeleydb) {
576 if ($is_myisam_or_maria || $is_innodb) {
577 $this_url_params = array_merge($url_params,
578 array('sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table'])));
580 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
581 <?php echo __('Check table'); ?></a>
582 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?>
583 </li>
584 <?php
586 if ($is_innodb) {
587 $this_url_params = array_merge($url_params,
588 array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ENGINE = InnoDB'));
590 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
591 <?php echo __('Defragment table'); ?></a>
592 <?php echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?>
593 </li>
594 <?php
596 if ($is_myisam_or_maria || $is_berkeleydb) {
597 $this_url_params = array_merge($url_params,
598 array('sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table'])));
600 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
601 <?php echo __('Analyze table'); ?></a>
602 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?>
603 </li>
604 <?php
606 if ($is_myisam_or_maria) {
607 $this_url_params = array_merge($url_params,
608 array('sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])));
610 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
611 <?php echo __('Repair table'); ?></a>
612 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?>
613 </li>
614 <?php
616 if ($is_myisam_or_maria || $is_innodb || $is_berkeleydb) {
617 $this_url_params = array_merge($url_params,
618 array('sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table'])));
620 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
621 <?php echo __('Optimize table'); ?></a>
622 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?>
623 </li>
624 <?php
626 } // end MYISAM or BERKELEYDB case
627 $this_url_params = array_merge($url_params,
628 array(
629 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
630 'zero_rows' => sprintf(__('Table %s has been flushed'),
631 htmlspecialchars($GLOBALS['table'])),
632 'reload' => 1,
635 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
636 <?php echo __('Flush the table (FLUSH)'); ?></a>
637 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?>
638 </li>
639 </ul>
640 </fieldset>
641 </div>
642 <?php if (PMA_Partition::havePartitioning()) {
643 $partition_names = PMA_Partition::getPartitionNames($db, $table);
644 // show the Partition maintenance section only if we detect a partition
645 if (! is_null($partition_names[0])) {
647 <div id="div_partition_maintenance">
648 <form method="post" action="tbl_operations.php">
649 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
650 <fieldset>
651 <legend><?php echo __('Partition maintenance'); ?></legend>
652 <?php
653 $html_select = '<select name="partition_name">' . "\n";
654 foreach($partition_names as $one_partition) {
655 $one_partition = htmlspecialchars($one_partition);
656 $html_select .= '<option value="' . $one_partition . '">' . $one_partition . '</option>' . "\n";
658 $html_select .= '</select>' . "\n";
659 printf(__('Partition %s'), $html_select);
660 unset($partition_names, $one_partition, $html_select);
661 $choices = array(
662 'ANALYZE' => __('Analyze'),
663 'CHECK' => __('Check'),
664 'OPTIMIZE' => __('Optimize'),
665 'REBUILD' => __('Rebuild'),
666 'REPAIR' => __('Repair'));
667 PMA_display_html_radio('partition_operation', $choices, '', false);
668 unset($choices);
669 echo PMA_showMySQLDocu('partitioning_maintenance', 'partitioning_maintenance');
670 // I'm not sure of the best way to display that; this link does
671 // not depend on the Go button
672 $this_url_params = array_merge($url_params,
673 array(
674 'sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' REMOVE PARTITIONING'
677 <br /><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
678 <?php echo __('Remove partitioning'); ?></a>
679 </fieldset>
680 <fieldset class="tblFooters">
681 <input type="submit" name="submit_partition" value="<?php echo __('Go'); ?>" />
682 </fieldset>
683 </form>
684 </div>
685 <?php
686 } // end if
687 } // end if
689 // Referential integrity check
690 // The Referential integrity check was intended for the non-InnoDB
691 // tables for which the relations are defined in pmadb
692 // so I assume that if the current table is InnoDB, I don't display
693 // this choice (InnoDB maintains integrity by itself)
695 if ($cfgRelation['relwork'] && ! $is_innodb) {
696 PMA_DBI_select_db($GLOBALS['db']);
697 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
699 if ($foreign) {
701 <!-- Referential integrity check -->
702 <div id="div_referential_integrity">
703 <fieldset>
704 <legend><?php echo __('Check referential integrity:'); ?></legend>
705 <ul>
706 <?php
707 echo "\n";
708 foreach ($foreign AS $master => $arr) {
709 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
710 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
711 . PMA_backquote($arr['foreign_table']);
712 if ($arr['foreign_table'] == $GLOBALS['table']) {
713 $foreign_table = $GLOBALS['table'] . '1';
714 $join_query .= ' AS ' . PMA_backquote($foreign_table);
715 } else {
716 $foreign_table = $arr['foreign_table'];
718 $join_query .= ' ON '
719 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
720 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
721 . ' WHERE '
722 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
723 . ' IS NULL AND '
724 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
725 . ' IS NOT NULL';
726 $this_url_params = array_merge($url_params,
727 array('sql_query' => $join_query));
728 echo ' <li>'
729 . '<a href="sql.php'
730 . PMA_generate_common_url($this_url_params)
731 . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
732 . '</a></li>' . "\n";
733 } // foreach $foreign
734 unset($foreign_table, $join_query);
736 </ul>
737 </fieldset>
738 </div>
739 <?php
740 } // end if ($foreign)
742 } // end if (!empty($cfg['Server']['relation']))
746 * Displays the footer
748 require_once './libraries/footer.inc.php';
751 function PMA_set_global_variables_for_engine($tbl_type)
753 global $is_myisam_or_maria, $is_innodb, $is_isam, $is_berkeleydb, $is_maria, $is_pbxt;
755 $is_myisam_or_maria = $is_isam = $is_innodb = $is_berkeleydb = $is_maria = $is_pbxt = false;
756 $upper_tbl_type = strtoupper($tbl_type);
758 //Options that apply to MYISAM usually apply to MARIA
759 $is_myisam_or_maria = ($upper_tbl_type == 'MYISAM' || $upper_tbl_type == 'MARIA');
760 $is_maria = ($upper_tbl_type == 'MARIA');
762 $is_isam = ($upper_tbl_type == 'ISAM');
763 $is_innodb = ($upper_tbl_type == 'INNODB');
764 $is_berkeleydb = ($upper_tbl_type == 'BERKELEYDB');
765 $is_pbxt = ($upper_tbl_type == 'PBXT');