Merge branch 'QA_3_4'
[phpmyadmin-regexreplace.git] / tbl_operations.php
blob5ba5aab47e3fdc1a469186edb3b985832a1c9b82
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';
36 $GLOBALS['js_include'][] = 'tbl_operations.js';
38 /**
39 * Class for partition management
41 require_once './libraries/Partition.class.php';
43 // reselect current db (needed in some cases probably due to
44 // the calling of relation.lib.php)
45 PMA_DBI_select_db($GLOBALS['db']);
47 /**
48 * Gets tables informations
51 require './libraries/tbl_info.inc.php';
53 // define some globals here, for improved syntax in the conditionals
54 $is_myisam_or_aria = $is_isam = $is_innodb = $is_berkeleydb = $is_aria = $is_pbxt = false;
55 // set initial value of these globals, based on the current table engine
56 PMA_set_global_variables_for_engine($tbl_type);
58 if ($is_aria) {
59 // the value for transactional can be implicit
60 // (no create option found, in this case it means 1)
61 // or explicit (option found with a value of 0 or 1)
62 // ($transactional may have been set by libraries/tbl_info.inc.php,
63 // from the $create_options)
64 $transactional = (isset($transactional) && $transactional == '0') ? '0' : '1';
65 $page_checksum = (isset($page_checksum)) ? $page_checksum : '';
68 $reread_info = false;
69 $table_alters = array();
71 /**
72 * If the table has to be moved to some other database
74 if(isset($_REQUEST['submit_move']) || isset($_REQUEST['submit_copy'])) {
75 $_message = '';
76 require_once './tbl_move_copy.php';
78 /**
79 * If the table has to be maintained
81 if(isset($_REQUEST['table_maintenance'])) {
82 require_once './sql.php';
83 unset($result);
85 /**
86 * Updates table comment, type and options if required
88 if (isset($_REQUEST['submitoptions'])) {
89 $_message = '';
90 $warning_messages = array();
92 if (isset($_REQUEST['new_name'])) {
93 if ($pma_table->rename($_REQUEST['new_name'])) {
94 $_message .= $pma_table->getLastMessage();
95 $result = true;
96 $GLOBALS['table'] = $pma_table->getName();
97 $reread_info = true;
98 $reload = true;
99 } else {
100 $_message .= $pma_table->getLastError();
101 $result = false;
104 if (isset($_REQUEST['comment'])
105 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']) {
106 $table_alters[] = 'COMMENT = \'' . PMA_sqlAddslashes($_REQUEST['comment']) . '\'';
108 if (! empty($_REQUEST['new_tbl_type'])
109 && strtolower($_REQUEST['new_tbl_type']) !== strtolower($tbl_type)) {
110 $table_alters[] = 'ENGINE = ' . $_REQUEST['new_tbl_type'];
111 $tbl_type = $_REQUEST['new_tbl_type'];
112 // reset the globals for the new engine
113 PMA_set_global_variables_for_engine($tbl_type);
114 if ($is_aria) {
115 $transactional = (isset($transactional) && $transactional == '0') ? '0' : '1';
116 $page_checksum = (isset($page_checksum)) ? $page_checksum : '';
120 if (! empty($_REQUEST['tbl_collation'])
121 && $_REQUEST['tbl_collation'] !== $tbl_collation) {
122 $table_alters[] = 'DEFAULT ' . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
125 if (($is_myisam_or_aria || $is_isam)
126 && isset($_REQUEST['new_pack_keys'])
127 && $_REQUEST['new_pack_keys'] != (string)$pack_keys) {
128 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
131 $checksum = empty($checksum) ? '0' : '1';
132 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
133 if ($is_myisam_or_aria
134 && $_REQUEST['new_checksum'] !== $checksum) {
135 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
138 $_REQUEST['new_transactional'] = empty($_REQUEST['new_transactional']) ? '0' : '1';
139 if ($is_aria
140 && $_REQUEST['new_transactional'] !== $transactional) {
141 $table_alters[] = 'TRANSACTIONAL = ' . $_REQUEST['new_transactional'];
144 $_REQUEST['new_page_checksum'] = empty($_REQUEST['new_page_checksum']) ? '0' : '1';
145 if ($is_aria
146 && $_REQUEST['new_page_checksum'] !== $page_checksum) {
147 $table_alters[] = 'PAGE_CHECKSUM = ' . $_REQUEST['new_page_checksum'];
150 $delay_key_write = empty($delay_key_write) ? '0' : '1';
151 $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
152 if ($is_myisam_or_aria
153 && $_REQUEST['new_delay_key_write'] !== $delay_key_write) {
154 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
157 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
158 && ! empty($_REQUEST['new_auto_increment'])
159 && (! isset($auto_increment) || $_REQUEST['new_auto_increment'] !== $auto_increment)) {
160 $table_alters[] = 'auto_increment = ' . PMA_sqlAddslashes($_REQUEST['new_auto_increment']);
163 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
164 && ! empty($_REQUEST['new_row_format'])
165 && (! isset($row_format) || strtolower($_REQUEST['new_row_format']) !== strtolower($row_format))) {
166 $table_alters[] = 'ROW_FORMAT = ' . PMA_sqlAddslashes($_REQUEST['new_row_format']);
169 if (count($table_alters) > 0) {
170 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']);
171 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
172 $result .= PMA_DBI_query($sql_query) ? true : false;
173 $reread_info = true;
174 unset($table_alters);
175 foreach (PMA_DBI_get_warnings() as $warning) {
176 // In MariaDB 5.1.44, when altering a table from Maria to MyISAM
177 // and if TRANSACTIONAL was set, the system reports an error;
178 // I discussed with a Maria developer and he agrees that this
179 // should not be reported with a Level of Error, so here
180 // I just ignore it. But there are other 1478 messages
181 // that it's better to show.
182 if (! ($_REQUEST['new_tbl_type'] == 'MyISAM' && $warning['Code'] == '1478' && $warning['Level'] == 'Error')) {
183 $warning_messages[] = $warning['Level'] . ': #' . $warning['Code']
184 . ' ' . $warning['Message'];
190 * Reordering the table has been requested by the user
192 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
193 $sql_query = '
194 ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
195 ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
196 if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
197 $sql_query .= ' DESC';
199 $result = PMA_DBI_query($sql_query);
200 } // end if
203 * A partition operation has been requested by the user
205 if (isset($_REQUEST['submit_partition']) && ! empty($_REQUEST['partition_operation'])) {
206 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . $_REQUEST['partition_operation'] . ' PARTITION ' . $_REQUEST['partition_name'];
207 $result = PMA_DBI_query($sql_query);
208 } // end if
210 if ($reread_info) {
211 // to avoid showing the old value (for example the AUTO_INCREMENT) after
212 // a change, clear the cache
213 PMA_Table::$cache = array();
214 $page_checksum = $checksum = $delay_key_write = 0;
215 require './libraries/tbl_info.inc.php';
217 unset($reread_info);
220 * Displays top menu links
222 require_once './libraries/tbl_links.inc.php';
224 if (isset($result) && empty($message_to_show)) {
225 // set to success by default, because result set could be empty
226 // (for example, a table rename)
227 $_type = 'success';
228 if (empty($_message)) {
229 $_message = $result ? __('Your SQL query has been executed successfully') : __('Error');
230 // $result should exist, regardless of $_message
231 $_type = $result ? 'success' : 'error';
233 if (! empty($warning_messages)) {
234 $_message = new PMA_Message;
235 $_message->addMessages($warning_messages);
236 $_message->isError(true);
237 unset($warning_messages);
239 PMA_showMessage($_message, $sql_query, $_type);
240 unset($_message, $_type);
243 $url_params['goto'] = 'tbl_operations.php';
244 $url_params['back'] = 'tbl_operations.php';
247 * Get columns names
249 $local_query = '
250 SHOW COLUMNS
251 FROM ' . PMA_backquote($GLOBALS['table']) . '
252 FROM ' . PMA_backquote($GLOBALS['db']);
253 $columns = PMA_DBI_fetch_result($local_query, null, 'Field');
254 unset($local_query);
257 * Displays the page
260 <!-- Order the table -->
261 <div class="operations_half_width">
262 <form method="post" action="tbl_operations.php">
263 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
264 <fieldset id="fieldset_table_order">
265 <legend><?php echo __('Alter table order by'); ?></legend>
266 <select name="order_field">
267 <?php
268 foreach ($columns as $fieldname) {
269 echo ' <option value="' . htmlspecialchars($fieldname) . '">'
270 . htmlspecialchars($fieldname) . '</option>' . "\n";
272 unset($columns);
274 </select> <?php echo __('(singly)'); ?>
275 <select name="order_order">
276 <option value="asc"><?php echo __('Ascending'); ?></option>
277 <option value="desc"><?php echo __('Descending'); ?></option>
278 </select>
279 </fieldset>
280 <fieldset class="tblFooters">
281 <input type="submit" name="submitorderby" value="<?php echo __('Go'); ?>" />
282 </fieldset>
283 </form>
284 </div>
286 <!-- Move table -->
287 <div class="operations_half_width">
288 <form method="post" action="tbl_operations.php"
289 onsubmit="return emptyFormElements(this, 'new_name')">
290 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
291 <input type="hidden" name="reload" value="1" />
292 <input type="hidden" name="what" value="data" />
293 <fieldset id="fieldset_table_rename">
294 <legend><?php echo __('Move table to (database<b>.</b>table):'); ?></legend>
295 <?php if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
297 <input type="text" maxlength="100" size="30" name="target_db" value="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
298 <?php
299 } else {
301 <select name="target_db">
302 <?php echo $GLOBALS['pma']->databases->getHtmlOptions(true, false); ?>
303 </select>
304 <?php
305 } // end if
307 &nbsp;<strong>.</strong>&nbsp;
308 <input type="text" size="20" name="new_name" onfocus="this.select()"
309 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br />
310 <?php
311 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
312 // next value but users can decide if they want it or not for the operation
314 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_mv" checked="checked" />
315 <label for="checkbox_auto_increment_mv"><?php echo __('Add AUTO_INCREMENT value'); ?></label><br />
316 </fieldset>
317 <fieldset class="tblFooters">
318 <input type="submit" name="submit_move" value="<?php echo __('Go'); ?>" />
319 </fieldset>
320 </form>
321 </div>
323 <?php
324 if (strstr($show_comment, '; InnoDB free') === false) {
325 if (strstr($show_comment, 'InnoDB free') === false) {
326 // only user entered comment
327 $comment = $show_comment;
328 } else {
329 // here we have just InnoDB generated part
330 $comment = '';
332 } else {
333 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
334 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
337 // PACK_KEYS: MyISAM or ISAM
338 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
339 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3, PBXT
341 // Here should be version check for InnoDB, however it is supported
342 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
343 // check for version
346 <!-- Table options -->
347 <div class="operations_half_width clearfloat">
348 <form method="post" action="tbl_operations.php">
349 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
350 <input type="hidden" name="reload" value="1" />
351 <fieldset>
352 <legend><?php echo __('Table options'); ?></legend>
354 <table>
355 <!-- Change table name -->
356 <tr><td><?php echo __('Rename table to'); ?></td>
357 <td><input type="text" size="20" name="new_name" onfocus="this.select()"
358 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
359 </td>
360 </tr>
362 <!-- Table comments -->
363 <tr><td><?php echo __('Table comments'); ?></td>
364 <td><input type="text" name="comment" maxlength="60" size="30"
365 value="<?php echo htmlspecialchars($comment); ?>" onfocus="this.select()" />
366 <input type="hidden" name="prev_comment" value="<?php echo htmlspecialchars($comment); ?>" />
367 </td>
368 </tr>
370 <!-- Storage engine -->
371 <tr><td><?php echo __('Storage Engine'); ?>
372 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
373 </td>
374 <td><?php echo PMA_StorageEngine::getHtmlSelect('new_tbl_type', null, $tbl_type); ?>
375 </td>
376 </tr>
378 <!-- Table character set -->
379 <tr><td><?php echo __('Collation'); ?></td>
380 <td><?php echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION,
381 'tbl_collation', null, $tbl_collation, false, 3); ?>
382 </td>
383 </tr>
384 <?php
385 if ($is_myisam_or_aria || $is_isam) {
387 <tr>
388 <td><label for="new_pack_keys">PACK_KEYS</label></td>
389 <td><select name="new_pack_keys" id="new_pack_keys">
390 <option value="DEFAULT"
391 <?php if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?>
392 >DEFAULT</option>
393 <option value="0"
394 <?php if ($pack_keys == '0') echo 'selected="selected"'; ?>
395 >0</option>
396 <option value="1"
397 <?php if ($pack_keys == '1') echo 'selected="selected"'; ?>
398 >1</option>
399 </select>
400 </td>
401 </tr>
402 <?php
403 } // end if (MYISAM|ISAM)
405 if ($is_myisam_or_aria) {
407 <tr><td><label for="new_checksum">CHECKSUM</label></td>
408 <td><input type="checkbox" name="new_checksum" id="new_checksum"
409 value="1"
410 <?php echo (isset($checksum) && $checksum == 1)
411 ? ' checked="checked"'
412 : ''; ?> />
413 </td>
414 </tr>
416 <tr><td><label for="new_delay_key_write">DELAY_KEY_WRITE</label></td>
417 <td><input type="checkbox" name="new_delay_key_write" id="new_delay_key_write"
418 value="1"
419 <?php echo (isset($delay_key_write) && $delay_key_write == 1)
420 ? ' checked="checked"'
421 : ''; ?> />
422 </td>
423 </tr>
425 <?php
426 } // end if (MYISAM)
428 if ($is_aria) {
430 <tr><td><label for="new_transactional">TRANSACTIONAL</label></td>
431 <td><input type="checkbox" name="new_transactional" id="new_transactional"
432 value="1"
433 <?php echo (isset($transactional) && $transactional == 1)
434 ? ' checked="checked"'
435 : ''; ?> />
436 </td>
437 </tr>
439 <tr><td><label for="new_page_checksum">PAGE_CHECKSUM</label></td>
440 <td><input type="checkbox" name="new_page_checksum" id="new_page_checksum"
441 value="1"
442 <?php echo (isset($page_checksum) && $page_checksum == 1)
443 ? ' checked="checked"'
444 : ''; ?> />
445 </td>
446 </tr>
448 <?php
449 } // end if (ARIA)
451 if (isset($auto_increment) && strlen($auto_increment) > 0
452 && ($is_myisam_or_aria || $is_innodb || $is_pbxt)) {
454 <tr><td><label for="auto_increment_opt">AUTO_INCREMENT</label></td>
455 <td><input type="text" name="new_auto_increment" id="auto_increment_opt"
456 value="<?php echo $auto_increment; ?>" /></td>
457 </tr>
458 <?php
459 } // end if (MYISAM|INNODB)
461 // the outer array is for engines, the inner array contains the dropdown
462 // option values as keys then the dropdown option labels
464 $possible_row_formats = array(
465 'ARIA' => array(
466 'FIXED' => 'FIXED',
467 'DYNAMIC' => 'DYNAMIC',
468 'PAGE' => 'PAGE'
470 'MARIA' => array(
471 'FIXED' => 'FIXED',
472 'DYNAMIC' => 'DYNAMIC',
473 'PAGE' => 'PAGE'
475 'MYISAM' => array(
476 'FIXED' => 'FIXED',
477 'DYNAMIC' => 'DYNAMIC'
479 'PBXT' => array(
480 'FIXED' => 'FIXED',
481 'DYNAMIC' => 'DYNAMIC'
483 'INNODB' => array(
484 'COMPACT' => 'COMPACT',
485 'REDUNDANT' => 'REDUNDANT')
488 $innodb_engine_plugin = PMA_StorageEngine::getEngine('innodb');
489 $innodb_plugin_version = $innodb_engine_plugin->getInnodbPluginVersion();
490 if (!empty($innodb_plugin_version)) {
491 $innodb_file_format = $innodb_engine_plugin->getInnodbFileFormat();
492 } else {
493 $innodb_file_format = '';
495 if ('Barracuda' == $innodb_file_format && $innodb_engine_plugin->supportsFilePerTable()) {
496 $possible_row_formats['INNODB']['DYNAMIC'] = 'DYNAMIC';
497 $possible_row_formats['INNODB']['COMPRESSED'] = 'COMPRESSED';
499 unset($innodb_engine_plugin, $innodb_plugin_version, $innodb_file_format);
501 // for MYISAM there is also COMPRESSED but it can be set only by the
502 // myisampack utility, so don't offer here the choice because if we
503 // try it inside an ALTER TABLE, MySQL (at least in 5.1.23-maria)
504 // does not return a warning
505 // (if the table was compressed, it can be seen on the Structure page)
507 if (isset($possible_row_formats[$tbl_type])) {
508 $current_row_format = strtoupper($showtable['Row_format']);
509 echo '<tr><td><label for="new_row_format">ROW_FORMAT</label></td>';
510 echo '<td>';
511 echo PMA_generate_html_dropdown('new_row_format', $possible_row_formats[$tbl_type], $current_row_format, 'new_row_format');
512 unset($possible_row_formats, $current_row_format);
513 echo '</td>';
514 echo '</tr>';
517 </table>
518 </fieldset>
519 <fieldset class="tblFooters">
520 <input type="submit" name="submitoptions" value="<?php echo __('Go'); ?>" />
521 </fieldset>
522 </form>
523 </div>
525 <!-- Copy table -->
526 <div class="operations_half_width">
527 <form method="post" action="tbl_operations.php"
528 onsubmit="return emptyFormElements(this, 'new_name')">
529 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
530 <input type="hidden" name="reload" value="1" />
531 <fieldset>
532 <legend><?php echo __('Copy table to (database<b>.</b>table):'); ?></legend>
533 <?php if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
535 <input type="text" maxlength="100" size="30" name="target_db" value="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
536 <?php
537 } else {
539 <select name="target_db">
540 <?php echo $GLOBALS['pma']->databases->getHtmlOptions(true, false); ?>
541 </select>
542 <?php
543 } // end if
545 &nbsp;<strong>.</strong>&nbsp;
546 <input type="text" size="20" name="new_name" onfocus="this.select()" value="<?php echo htmlspecialchars($GLOBALS['table']); ?>"/><br />
547 <?php
548 $choices = array(
549 'structure' => __('Structure only'),
550 'data' => __('Structure and data'),
551 'dataonly' => __('Data only'));
552 PMA_display_html_radio('what', $choices, 'data', true);
553 unset($choices);
556 <input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" />
557 <label for="checkbox_drop"><?php echo sprintf(__('Add %s'), 'DROP TABLE'); ?></label><br />
558 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_cp" />
559 <label for="checkbox_auto_increment_cp"><?php echo __('Add AUTO_INCREMENT value'); ?></label><br />
560 <?php
561 // display "Add constraints" choice only if there are
562 // foreign keys
563 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
565 <input type="checkbox" name="add_constraints" value="1" id="checkbox_constraints" />
566 <label for="checkbox_constraints"><?php echo __('Add constraints'); ?></label><br />
567 <?php
568 } // endif
569 if (isset($_COOKIE['pma_switch_to_new'])
570 && $_COOKIE['pma_switch_to_new'] == 'true') {
571 $pma_switch_to_new = 'true';
574 <input type="checkbox" name="switch_to_new" value="true"
575 id="checkbox_switch"<?php echo
576 isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
577 ? ' checked="checked"'
578 : ''; ?> />
579 <label for="checkbox_switch"><?php echo __('Switch to copied table'); ?></label>
580 </fieldset>
581 <fieldset class="tblFooters">
582 <input type="submit" name="submit_copy" value="<?php echo __('Go'); ?>" />
583 </fieldset>
584 </form>
585 </div>
587 <br class="clearfloat"/>
589 <div class="operations_half_width">
590 <fieldset>
591 <legend><?php echo __('Table maintenance'); ?></legend>
593 <ul>
594 <?php
595 // Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
596 if ($is_myisam_or_aria || $is_innodb || $is_berkeleydb) {
597 if ($is_myisam_or_aria || $is_innodb) {
598 $this_url_params = array_merge($url_params,
599 array(
600 'sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table']),
601 'table_maintenance' => 'Go',
604 <li><a href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
605 <?php echo __('Check table'); ?></a>
606 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?>
607 </li>
608 <?php
610 if ($is_innodb) {
611 $this_url_params = array_merge($url_params,
612 array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ENGINE = InnoDB'));
614 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
615 <?php echo __('Defragment table'); ?></a>
616 <?php echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?>
617 </li>
618 <?php
620 if ($is_myisam_or_aria || $is_berkeleydb) {
621 $this_url_params = array_merge($url_params,
622 array(
623 'sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table']),
624 'table_maintenance' => 'Go',
627 <li><a href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
628 <?php echo __('Analyze table'); ?></a>
629 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?>
630 </li>
631 <?php
633 if ($is_myisam_or_aria) {
634 $this_url_params = array_merge($url_params,
635 array(
636 'sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table']),
637 'table_maintenance' => 'Go',
640 <li><a href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
641 <?php echo __('Repair table'); ?></a>
642 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?>
643 </li>
644 <?php
646 if ($is_myisam_or_aria || $is_innodb || $is_berkeleydb) {
647 $this_url_params = array_merge($url_params,
648 array(
649 'sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table']),
650 'table_maintenance' => 'Go',
653 <li><a href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
654 <?php echo __('Optimize table'); ?></a>
655 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?>
656 </li>
657 <?php
659 } // end MYISAM or BERKELEYDB case
660 $this_url_params = array_merge($url_params,
661 array(
662 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
663 'message_to_show' => sprintf(__('Table %s has been flushed'),
664 htmlspecialchars($GLOBALS['table'])),
665 'reload' => 1,
668 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
669 <?php echo __('Flush the table (FLUSH)'); ?></a>
670 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?>
671 </li>
672 </ul>
673 </fieldset>
674 </div>
675 <?php if (! (isset($db_is_information_schema) && $db_is_information_schema)) { ?>
676 <div class="operations_half_width">
677 <fieldset class="caution">
678 <legend><?php echo __('Delete data or table'); ?></legend>
680 <ul>
681 <?php
682 if (! $tbl_is_view && ! (isset($db_is_information_schema) && $db_is_information_schema)) {
683 $this_sql_query = 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table']);
684 $this_url_params = array_merge($url_params,
685 array(
686 'sql_query' => $this_sql_query,
687 'goto' => 'tbl_structure.php',
688 'reload' => '1',
689 'message_to_show' => sprintf(__('Table %s has been emptied'), htmlspecialchars($table)),
692 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'id="truncate_tbl_anchor"' : ''); ?>>
693 <?php echo __('Empty the table (TRUNCATE)'); ?></a>
694 <?php echo PMA_showMySQLDocu('SQL-Syntax', 'TRUNCATE_TABLE'); ?>
695 </li>
696 <?php
698 if (! (isset($db_is_information_schema) && $db_is_information_schema)) {
699 $this_sql_query = 'DROP TABLE ' . PMA_backquote($GLOBALS['table']);
700 $this_url_params = array_merge($url_params,
701 array(
702 'sql_query' => $this_sql_query,
703 'goto' => 'db_operations.php',
704 'reload' => '1',
705 'purge' => '1',
706 'message_to_show' => sprintf(($tbl_is_view ? __('View %s has been dropped') : __('Table %s has been dropped')), htmlspecialchars($table)),
707 // table name is needed to avoid running
708 // PMA_relationsCleanupDatabase() on the whole db later
709 'table' => $GLOBALS['table'],
712 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'id="drop_tbl_anchor"' : ''); ?>>
713 <?php echo __('Delete the table (DROP)'); ?></a>
714 <?php echo PMA_showMySQLDocu('SQL-Syntax', 'DROP_TABLE'); ?>
715 </li>
716 <?php
719 </ul>
720 </fieldset>
721 </div>
722 <?php
725 <?php if (PMA_Partition::havePartitioning()) {
726 $partition_names = PMA_Partition::getPartitionNames($db, $table);
727 // show the Partition maintenance section only if we detect a partition
728 if (! is_null($partition_names[0])) {
730 <div class="operations_half_width">
731 <form method="post" action="tbl_operations.php">
732 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
733 <fieldset>
734 <legend><?php echo __('Partition maintenance'); ?></legend>
735 <?php
736 $html_select = '<select name="partition_name">' . "\n";
737 foreach($partition_names as $one_partition) {
738 $one_partition = htmlspecialchars($one_partition);
739 $html_select .= '<option value="' . $one_partition . '">' . $one_partition . '</option>' . "\n";
741 $html_select .= '</select>' . "\n";
742 printf(__('Partition %s'), $html_select);
743 unset($partition_names, $one_partition, $html_select);
744 $choices = array(
745 'ANALYZE' => __('Analyze'),
746 'CHECK' => __('Check'),
747 'OPTIMIZE' => __('Optimize'),
748 'REBUILD' => __('Rebuild'),
749 'REPAIR' => __('Repair'));
750 PMA_display_html_radio('partition_operation', $choices, '', false);
751 unset($choices);
752 echo PMA_showMySQLDocu('partitioning_maintenance', 'partitioning_maintenance');
753 // I'm not sure of the best way to display that; this link does
754 // not depend on the Go button
755 $this_url_params = array_merge($url_params,
756 array(
757 'sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' REMOVE PARTITIONING'
760 <br /><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
761 <?php echo __('Remove partitioning'); ?></a>
762 </fieldset>
763 <fieldset class="tblFooters">
764 <input type="submit" name="submit_partition" value="<?php echo __('Go'); ?>" />
765 </fieldset>
766 </form>
767 </div>
768 <?php
769 } // end if
770 } // end if
772 // Referential integrity check
773 // The Referential integrity check was intended for the non-InnoDB
774 // tables for which the relations are defined in pmadb
775 // so I assume that if the current table is InnoDB, I don't display
776 // this choice (InnoDB maintains integrity by itself)
778 if ($cfgRelation['relwork'] && ! $is_innodb) {
779 PMA_DBI_select_db($GLOBALS['db']);
780 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
782 if ($foreign) {
784 <!-- Referential integrity check -->
785 <div class="operations_half_width">
786 <fieldset>
787 <legend><?php echo __('Check referential integrity:'); ?></legend>
788 <ul>
789 <?php
790 echo "\n";
791 foreach ($foreign AS $master => $arr) {
792 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
793 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
794 . PMA_backquote($arr['foreign_table']);
795 if ($arr['foreign_table'] == $GLOBALS['table']) {
796 $foreign_table = $GLOBALS['table'] . '1';
797 $join_query .= ' AS ' . PMA_backquote($foreign_table);
798 } else {
799 $foreign_table = $arr['foreign_table'];
801 $join_query .= ' ON '
802 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
803 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
804 . ' WHERE '
805 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
806 . ' IS NULL AND '
807 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
808 . ' IS NOT NULL';
809 $this_url_params = array_merge($url_params,
810 array('sql_query' => $join_query));
811 echo ' <li>'
812 . '<a href="sql.php'
813 . PMA_generate_common_url($this_url_params)
814 . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
815 . '</a></li>' . "\n";
816 } // foreach $foreign
817 unset($foreign_table, $join_query);
819 </ul>
820 </fieldset>
821 </div>
822 <?php
823 } // end if ($foreign)
825 } // end if (!empty($cfg['Server']['relation']))
829 * Displays the footer
831 require './libraries/footer.inc.php';
834 function PMA_set_global_variables_for_engine($tbl_type)
836 global $is_myisam_or_aria, $is_innodb, $is_isam, $is_berkeleydb, $is_aria, $is_pbxt;
838 $is_myisam_or_aria = $is_isam = $is_innodb = $is_berkeleydb = $is_aria = $is_pbxt = false;
839 $upper_tbl_type = strtoupper($tbl_type);
841 //Options that apply to MYISAM usually apply to ARIA
842 $is_myisam_or_aria = ($upper_tbl_type == 'MYISAM' || $upper_tbl_type == 'ARIA' || $upper_tbl_type == 'MARIA');
843 $is_aria = ($upper_tbl_type == 'ARIA');
845 $is_isam = ($upper_tbl_type == 'ISAM');
846 $is_innodb = ($upper_tbl_type == 'INNODB');
847 $is_berkeleydb = ($upper_tbl_type == 'BERKELEYDB');
848 $is_pbxt = ($upper_tbl_type == 'PBXT');