Merge remote branch 'phpmyadmin/master'
[phpmyadmin/ammaryasirr.git] / tbl_operations.php
blob3481fd1cd6a8426646545ad784b7f00e0bec33ef
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 in non ajax requests
221 if (!isset($_REQUEST['ajax_request'])) {
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 ? $message = PMA_Message::success(__('Your SQL query has been executed successfully')) : PMA_Message::error(__('Error'));
230 // $result should exist, regardless of $_message
231 $_type = $result ? 'success' : 'error';
232 if ( $GLOBALS['is_ajax_request'] == true) {
233 $extra_data['sql_query'] = PMA_showMessage(NULL, $sql_query);
234 PMA_ajaxResponse($_message,$_message->isSuccess() ,$extra_data);
237 if (! empty($warning_messages)) {
238 $_message = new PMA_Message;
239 $_message->addMessages($warning_messages);
240 $_message->isError(true);
241 if ( $GLOBALS['is_ajax_request'] == true) {
242 PMA_ajaxResponse($_message, false);
244 unset($warning_messages);
247 PMA_showMessage($_message, $sql_query, $_type);
248 unset($_message, $_type);
251 $url_params['goto'] = 'tbl_operations.php';
252 $url_params['back'] = 'tbl_operations.php';
255 * Get columns names
257 $local_query = '
258 SHOW COLUMNS
259 FROM ' . PMA_backquote($GLOBALS['table']) . '
260 FROM ' . PMA_backquote($GLOBALS['db']);
261 $columns = PMA_DBI_fetch_result($local_query, null, 'Field');
262 unset($local_query);
265 * Displays the page
268 <!-- Order the table -->
269 <div class="operations_half_width">
270 <form method="post" id="alterTableOrderby" action="tbl_operations.php" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '');?>>
271 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
272 <fieldset id="fieldset_table_order">
273 <legend><?php echo __('Alter table order by'); ?></legend>
274 <select name="order_field">
275 <?php
276 foreach ($columns as $fieldname) {
277 echo ' <option value="' . htmlspecialchars($fieldname) . '">'
278 . htmlspecialchars($fieldname) . '</option>' . "\n";
280 unset($columns);
282 </select> <?php echo __('(singly)'); ?>
283 <select name="order_order">
284 <option value="asc"><?php echo __('Ascending'); ?></option>
285 <option value="desc"><?php echo __('Descending'); ?></option>
286 </select>
287 </fieldset>
288 <fieldset class="tblFooters">
289 <input type="submit" name="submitorderby" value="<?php echo __('Go'); ?>" />
290 </fieldset>
291 </form>
292 </div>
294 <!-- Move table -->
295 <div class="operations_half_width">
296 <form method="post" action="tbl_operations.php"
297 onsubmit="return emptyFormElements(this, 'new_name')">
298 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
299 <input type="hidden" name="reload" value="1" />
300 <input type="hidden" name="what" value="data" />
301 <fieldset id="fieldset_table_rename">
302 <legend><?php echo __('Move table to (database<b>.</b>table):'); ?></legend>
303 <?php if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
305 <input type="text" maxlength="100" size="30" name="target_db" value="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
306 <?php
307 } else {
309 <select name="target_db">
310 <?php echo $GLOBALS['pma']->databases->getHtmlOptions(true, false); ?>
311 </select>
312 <?php
313 } // end if
315 &nbsp;<strong>.</strong>&nbsp;
316 <input type="text" size="20" name="new_name" onfocus="this.select()"
317 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br />
318 <?php
319 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
320 // next value but users can decide if they want it or not for the operation
322 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_mv" checked="checked" />
323 <label for="checkbox_auto_increment_mv"><?php echo __('Add AUTO_INCREMENT value'); ?></label><br />
324 </fieldset>
325 <fieldset class="tblFooters">
326 <input type="submit" name="submit_move" value="<?php echo __('Go'); ?>" />
327 </fieldset>
328 </form>
329 </div>
331 <?php
332 if (strstr($show_comment, '; InnoDB free') === false) {
333 if (strstr($show_comment, 'InnoDB free') === false) {
334 // only user entered comment
335 $comment = $show_comment;
336 } else {
337 // here we have just InnoDB generated part
338 $comment = '';
340 } else {
341 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
342 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
345 // PACK_KEYS: MyISAM or ISAM
346 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
347 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3, PBXT
349 // Here should be version check for InnoDB, however it is supported
350 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
351 // check for version
354 <!-- Table options -->
355 <div class="operations_half_width clearfloat">
356 <form method="post" action="tbl_operations.php">
357 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
358 <input type="hidden" name="reload" value="1" />
359 <fieldset>
360 <legend><?php echo __('Table options'); ?></legend>
362 <table>
363 <!-- Change table name -->
364 <tr><td><?php echo __('Rename table to'); ?></td>
365 <td><input type="text" size="20" name="new_name" onfocus="this.select()"
366 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
367 </td>
368 </tr>
370 <!-- Table comments -->
371 <tr><td><?php echo __('Table comments'); ?></td>
372 <td><input type="text" name="comment" maxlength="60" size="30"
373 value="<?php echo htmlspecialchars($comment); ?>" onfocus="this.select()" />
374 <input type="hidden" name="prev_comment" value="<?php echo htmlspecialchars($comment); ?>" />
375 </td>
376 </tr>
378 <!-- Storage engine -->
379 <tr><td><?php echo __('Storage Engine'); ?>
380 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
381 </td>
382 <td><?php echo PMA_StorageEngine::getHtmlSelect('new_tbl_type', null, $tbl_type); ?>
383 </td>
384 </tr>
386 <!-- Table character set -->
387 <tr><td><?php echo __('Collation'); ?></td>
388 <td><?php echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION,
389 'tbl_collation', null, $tbl_collation, false, 3); ?>
390 </td>
391 </tr>
392 <?php
393 if ($is_myisam_or_aria || $is_isam) {
395 <tr>
396 <td><label for="new_pack_keys">PACK_KEYS</label></td>
397 <td><select name="new_pack_keys" id="new_pack_keys">
398 <option value="DEFAULT"
399 <?php if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?>
400 >DEFAULT</option>
401 <option value="0"
402 <?php if ($pack_keys == '0') echo 'selected="selected"'; ?>
403 >0</option>
404 <option value="1"
405 <?php if ($pack_keys == '1') echo 'selected="selected"'; ?>
406 >1</option>
407 </select>
408 </td>
409 </tr>
410 <?php
411 } // end if (MYISAM|ISAM)
413 if ($is_myisam_or_aria) {
415 <tr><td><label for="new_checksum">CHECKSUM</label></td>
416 <td><input type="checkbox" name="new_checksum" id="new_checksum"
417 value="1"
418 <?php echo (isset($checksum) && $checksum == 1)
419 ? ' checked="checked"'
420 : ''; ?> />
421 </td>
422 </tr>
424 <tr><td><label for="new_delay_key_write">DELAY_KEY_WRITE</label></td>
425 <td><input type="checkbox" name="new_delay_key_write" id="new_delay_key_write"
426 value="1"
427 <?php echo (isset($delay_key_write) && $delay_key_write == 1)
428 ? ' checked="checked"'
429 : ''; ?> />
430 </td>
431 </tr>
433 <?php
434 } // end if (MYISAM)
436 if ($is_aria) {
438 <tr><td><label for="new_transactional">TRANSACTIONAL</label></td>
439 <td><input type="checkbox" name="new_transactional" id="new_transactional"
440 value="1"
441 <?php echo (isset($transactional) && $transactional == 1)
442 ? ' checked="checked"'
443 : ''; ?> />
444 </td>
445 </tr>
447 <tr><td><label for="new_page_checksum">PAGE_CHECKSUM</label></td>
448 <td><input type="checkbox" name="new_page_checksum" id="new_page_checksum"
449 value="1"
450 <?php echo (isset($page_checksum) && $page_checksum == 1)
451 ? ' checked="checked"'
452 : ''; ?> />
453 </td>
454 </tr>
456 <?php
457 } // end if (ARIA)
459 if (isset($auto_increment) && strlen($auto_increment) > 0
460 && ($is_myisam_or_aria || $is_innodb || $is_pbxt)) {
462 <tr><td><label for="auto_increment_opt">AUTO_INCREMENT</label></td>
463 <td><input type="text" name="new_auto_increment" id="auto_increment_opt"
464 value="<?php echo $auto_increment; ?>" /></td>
465 </tr>
466 <?php
467 } // end if (MYISAM|INNODB)
469 // the outer array is for engines, the inner array contains the dropdown
470 // option values as keys then the dropdown option labels
472 $possible_row_formats = array(
473 'ARIA' => array(
474 'FIXED' => 'FIXED',
475 'DYNAMIC' => 'DYNAMIC',
476 'PAGE' => 'PAGE'
478 'MARIA' => array(
479 'FIXED' => 'FIXED',
480 'DYNAMIC' => 'DYNAMIC',
481 'PAGE' => 'PAGE'
483 'MYISAM' => array(
484 'FIXED' => 'FIXED',
485 'DYNAMIC' => 'DYNAMIC'
487 'PBXT' => array(
488 'FIXED' => 'FIXED',
489 'DYNAMIC' => 'DYNAMIC'
491 'INNODB' => array(
492 'COMPACT' => 'COMPACT',
493 'REDUNDANT' => 'REDUNDANT')
496 $innodb_engine_plugin = PMA_StorageEngine::getEngine('innodb');
497 $innodb_plugin_version = $innodb_engine_plugin->getInnodbPluginVersion();
498 if (!empty($innodb_plugin_version)) {
499 $innodb_file_format = $innodb_engine_plugin->getInnodbFileFormat();
500 } else {
501 $innodb_file_format = '';
503 if ('Barracuda' == $innodb_file_format && $innodb_engine_plugin->supportsFilePerTable()) {
504 $possible_row_formats['INNODB']['DYNAMIC'] = 'DYNAMIC';
505 $possible_row_formats['INNODB']['COMPRESSED'] = 'COMPRESSED';
507 unset($innodb_engine_plugin, $innodb_plugin_version, $innodb_file_format);
509 // for MYISAM there is also COMPRESSED but it can be set only by the
510 // myisampack utility, so don't offer here the choice because if we
511 // try it inside an ALTER TABLE, MySQL (at least in 5.1.23-maria)
512 // does not return a warning
513 // (if the table was compressed, it can be seen on the Structure page)
515 if (isset($possible_row_formats[$tbl_type])) {
516 $current_row_format = strtoupper($showtable['Row_format']);
517 echo '<tr><td><label for="new_row_format">ROW_FORMAT</label></td>';
518 echo '<td>';
519 echo PMA_generate_html_dropdown('new_row_format', $possible_row_formats[$tbl_type], $current_row_format, 'new_row_format');
520 unset($possible_row_formats, $current_row_format);
521 echo '</td>';
522 echo '</tr>';
525 </table>
526 </fieldset>
527 <fieldset class="tblFooters">
528 <input type="submit" name="submitoptions" value="<?php echo __('Go'); ?>" />
529 </fieldset>
530 </form>
531 </div>
533 <!-- Copy table -->
534 <div class="operations_half_width">
535 <form method="post" action="tbl_operations.php"
536 onsubmit="return emptyFormElements(this, 'new_name')">
537 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
538 <input type="hidden" name="reload" value="1" />
539 <fieldset>
540 <legend><?php echo __('Copy table to (database<b>.</b>table):'); ?></legend>
541 <?php if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
543 <input type="text" maxlength="100" size="30" name="target_db" value="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
544 <?php
545 } else {
547 <select name="target_db">
548 <?php echo $GLOBALS['pma']->databases->getHtmlOptions(true, false); ?>
549 </select>
550 <?php
551 } // end if
553 &nbsp;<strong>.</strong>&nbsp;
554 <input type="text" size="20" name="new_name" onfocus="this.select()" value="<?php echo htmlspecialchars($GLOBALS['table']); ?>"/><br />
555 <?php
556 $choices = array(
557 'structure' => __('Structure only'),
558 'data' => __('Structure and data'),
559 'dataonly' => __('Data only'));
560 PMA_display_html_radio('what', $choices, 'data', true);
561 unset($choices);
564 <input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" />
565 <label for="checkbox_drop"><?php echo sprintf(__('Add %s'), 'DROP TABLE'); ?></label><br />
566 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_cp" />
567 <label for="checkbox_auto_increment_cp"><?php echo __('Add AUTO_INCREMENT value'); ?></label><br />
568 <?php
569 // display "Add constraints" choice only if there are
570 // foreign keys
571 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
573 <input type="checkbox" name="add_constraints" value="1" id="checkbox_constraints" />
574 <label for="checkbox_constraints"><?php echo __('Add constraints'); ?></label><br />
575 <?php
576 } // endif
577 if (isset($_COOKIE['pma_switch_to_new'])
578 && $_COOKIE['pma_switch_to_new'] == 'true') {
579 $pma_switch_to_new = 'true';
582 <input type="checkbox" name="switch_to_new" value="true"
583 id="checkbox_switch"<?php echo
584 isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
585 ? ' checked="checked"'
586 : ''; ?> />
587 <label for="checkbox_switch"><?php echo __('Switch to copied table'); ?></label>
588 </fieldset>
589 <fieldset class="tblFooters">
590 <input type="submit" name="submit_copy" value="<?php echo __('Go'); ?>" />
591 </fieldset>
592 </form>
593 </div>
595 <br class="clearfloat"/>
597 <div class="operations_half_width">
598 <fieldset>
599 <legend><?php echo __('Table maintenance'); ?></legend>
601 <ul>
602 <?php
603 // Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
604 if ($is_myisam_or_aria || $is_innodb || $is_berkeleydb) {
605 if ($is_myisam_or_aria || $is_innodb) {
606 $this_url_params = array_merge($url_params,
607 array(
608 'sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table']),
609 'table_maintenance' => 'Go',
612 <li><a href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
613 <?php echo __('Check table'); ?></a>
614 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?>
615 </li>
616 <?php
618 if ($is_innodb) {
619 $this_url_params = array_merge($url_params,
620 array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ENGINE = InnoDB'));
622 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
623 <?php echo __('Defragment table'); ?></a>
624 <?php echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?>
625 </li>
626 <?php
628 if ($is_myisam_or_aria || $is_berkeleydb) {
629 $this_url_params = array_merge($url_params,
630 array(
631 'sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table']),
632 'table_maintenance' => 'Go',
635 <li><a href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
636 <?php echo __('Analyze table'); ?></a>
637 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?>
638 </li>
639 <?php
641 if ($is_myisam_or_aria) {
642 $this_url_params = array_merge($url_params,
643 array(
644 'sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table']),
645 'table_maintenance' => 'Go',
648 <li><a href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
649 <?php echo __('Repair table'); ?></a>
650 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?>
651 </li>
652 <?php
654 if ($is_myisam_or_aria || $is_innodb || $is_berkeleydb) {
655 $this_url_params = array_merge($url_params,
656 array(
657 'sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table']),
658 'table_maintenance' => 'Go',
661 <li><a href="tbl_operations.php<?php echo PMA_generate_common_url($this_url_params); ?>">
662 <?php echo __('Optimize table'); ?></a>
663 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?>
664 </li>
665 <?php
667 } // end MYISAM or BERKELEYDB case
668 $this_url_params = array_merge($url_params,
669 array(
670 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
671 'message_to_show' => sprintf(__('Table %s has been flushed'),
672 htmlspecialchars($GLOBALS['table'])),
673 'reload' => 1,
676 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
677 <?php echo __('Flush the table (FLUSH)'); ?></a>
678 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?>
679 </li>
680 </ul>
681 </fieldset>
682 </div>
683 <?php if (! (isset($db_is_information_schema) && $db_is_information_schema)) { ?>
684 <div class="operations_half_width">
685 <fieldset class="caution">
686 <legend><?php echo __('Delete data or table'); ?></legend>
688 <ul>
689 <?php
690 if (! $tbl_is_view && ! (isset($db_is_information_schema) && $db_is_information_schema)) {
691 $this_sql_query = 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table']);
692 $this_url_params = array_merge($url_params,
693 array(
694 'sql_query' => $this_sql_query,
695 'goto' => 'tbl_structure.php',
696 'reload' => '1',
697 'message_to_show' => sprintf(__('Table %s has been emptied'), htmlspecialchars($table)),
700 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'id="truncate_tbl_anchor"' : ''); ?>>
701 <?php echo __('Empty the table (TRUNCATE)'); ?></a>
702 <?php echo PMA_showMySQLDocu('SQL-Syntax', 'TRUNCATE_TABLE'); ?>
703 </li>
704 <?php
706 if (! (isset($db_is_information_schema) && $db_is_information_schema)) {
707 $this_sql_query = 'DROP TABLE ' . PMA_backquote($GLOBALS['table']);
708 $this_url_params = array_merge($url_params,
709 array(
710 'sql_query' => $this_sql_query,
711 'goto' => 'db_operations.php',
712 'reload' => '1',
713 'purge' => '1',
714 'message_to_show' => sprintf(($tbl_is_view ? __('View %s has been dropped') : __('Table %s has been dropped')), htmlspecialchars($table)),
715 // table name is needed to avoid running
716 // PMA_relationsCleanupDatabase() on the whole db later
717 'table' => $GLOBALS['table'],
720 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'id="drop_tbl_anchor"' : ''); ?>>
721 <?php echo __('Delete the table (DROP)'); ?></a>
722 <?php echo PMA_showMySQLDocu('SQL-Syntax', 'DROP_TABLE'); ?>
723 </li>
724 <?php
727 </ul>
728 </fieldset>
729 </div>
730 <?php
733 <?php if (PMA_Partition::havePartitioning()) {
734 $partition_names = PMA_Partition::getPartitionNames($db, $table);
735 // show the Partition maintenance section only if we detect a partition
736 if (! is_null($partition_names[0])) {
738 <div class="operations_half_width">
739 <form method="post" action="tbl_operations.php">
740 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
741 <fieldset>
742 <legend><?php echo __('Partition maintenance'); ?></legend>
743 <?php
744 $html_select = '<select name="partition_name">' . "\n";
745 foreach ($partition_names as $one_partition) {
746 $one_partition = htmlspecialchars($one_partition);
747 $html_select .= '<option value="' . $one_partition . '">' . $one_partition . '</option>' . "\n";
749 $html_select .= '</select>' . "\n";
750 printf(__('Partition %s'), $html_select);
751 unset($partition_names, $one_partition, $html_select);
752 $choices = array(
753 'ANALYZE' => __('Analyze'),
754 'CHECK' => __('Check'),
755 'OPTIMIZE' => __('Optimize'),
756 'REBUILD' => __('Rebuild'),
757 'REPAIR' => __('Repair'));
758 PMA_display_html_radio('partition_operation', $choices, '', false);
759 unset($choices);
760 echo PMA_showMySQLDocu('partitioning_maintenance', 'partitioning_maintenance');
761 // I'm not sure of the best way to display that; this link does
762 // not depend on the Go button
763 $this_url_params = array_merge($url_params,
764 array(
765 'sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' REMOVE PARTITIONING'
768 <br /><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
769 <?php echo __('Remove partitioning'); ?></a>
770 </fieldset>
771 <fieldset class="tblFooters">
772 <input type="submit" name="submit_partition" value="<?php echo __('Go'); ?>" />
773 </fieldset>
774 </form>
775 </div>
776 <?php
777 } // end if
778 } // end if
780 // Referential integrity check
781 // The Referential integrity check was intended for the non-InnoDB
782 // tables for which the relations are defined in pmadb
783 // so I assume that if the current table is InnoDB, I don't display
784 // this choice (InnoDB maintains integrity by itself)
786 if ($cfgRelation['relwork'] && ! $is_innodb) {
787 PMA_DBI_select_db($GLOBALS['db']);
788 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
790 if ($foreign) {
792 <!-- Referential integrity check -->
793 <div class="operations_half_width">
794 <fieldset>
795 <legend><?php echo __('Check referential integrity:'); ?></legend>
796 <ul>
797 <?php
798 echo "\n";
799 foreach ($foreign AS $master => $arr) {
800 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
801 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
802 . PMA_backquote($arr['foreign_table']);
803 if ($arr['foreign_table'] == $GLOBALS['table']) {
804 $foreign_table = $GLOBALS['table'] . '1';
805 $join_query .= ' AS ' . PMA_backquote($foreign_table);
806 } else {
807 $foreign_table = $arr['foreign_table'];
809 $join_query .= ' ON '
810 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
811 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
812 . ' WHERE '
813 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
814 . ' IS NULL AND '
815 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
816 . ' IS NOT NULL';
817 $this_url_params = array_merge($url_params,
818 array('sql_query' => $join_query));
819 echo ' <li>'
820 . '<a href="sql.php'
821 . PMA_generate_common_url($this_url_params)
822 . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
823 . '</a></li>' . "\n";
824 } // foreach $foreign
825 unset($foreign_table, $join_query);
827 </ul>
828 </fieldset>
829 </div>
830 <?php
831 } // end if ($foreign)
833 } // end if (!empty($cfg['Server']['relation']))
837 * Displays the footer
839 require './libraries/footer.inc.php';
842 function PMA_set_global_variables_for_engine($tbl_type)
844 global $is_myisam_or_aria, $is_innodb, $is_isam, $is_berkeleydb, $is_aria, $is_pbxt;
846 $is_myisam_or_aria = $is_isam = $is_innodb = $is_berkeleydb = $is_aria = $is_pbxt = false;
847 $upper_tbl_type = strtoupper($tbl_type);
849 //Options that apply to MYISAM usually apply to ARIA
850 $is_myisam_or_aria = ($upper_tbl_type == 'MYISAM' || $upper_tbl_type == 'ARIA' || $upper_tbl_type == 'MARIA');
851 $is_aria = ($upper_tbl_type == 'ARIA');
853 $is_isam = ($upper_tbl_type == 'ISAM');
854 $is_innodb = ($upper_tbl_type == 'INNODB');
855 $is_berkeleydb = ($upper_tbl_type == 'BERKELEYDB');
856 $is_pbxt = ($upper_tbl_type == 'PBXT');