2 /* vim: set expandtab sw=4 ts=4 sts=4: */
11 require_once './libraries/common.inc.php';
12 require_once './libraries/Table.class.php';
14 $pma_table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
19 require './libraries/tbl_common.php';
20 $url_query .= '&goto=tbl_operations.php&back=tbl_operations.php';
21 $url_params['goto'] = $url_params['back'] = 'tbl_operations.php';
24 * Gets relation settings
26 require_once './libraries/relation.lib.php';
27 $cfgRelation = PMA_getRelationsParam();
30 * Gets available MySQL charsets and storage engines
32 require_once './libraries/mysql_charsets.lib.php';
33 require_once './libraries/StorageEngine.class.php';
36 * Class for partition management
38 require_once './libraries/Partition.class.php';
40 // reselect current db (needed in some cases probably due to
41 // the calling of relation.lib.php)
42 PMA_DBI_select_db($GLOBALS['db']);
45 * Gets tables informations
48 require './libraries/tbl_info.inc.php';
51 $table_alters = array();
54 * Updates table comment, type and options if required
56 if (isset($_REQUEST['submitoptions'])) {
58 if (isset($_REQUEST['new_name'])) {
59 if ($pma_table->rename($_REQUEST['new_name'])) {
60 $_message .= $pma_table->getLastMessage();
62 $GLOBALS['table'] = $pma_table->getName();
66 $_message .= $pma_table->getLastError();
70 if (isset($_REQUEST['comment'])
71 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']) {
72 $table_alters[] = 'COMMENT = \'' . PMA_sqlAddslashes($_REQUEST['comment']) . '\'';
74 if (! empty($_REQUEST['new_tbl_type'])
75 && strtolower($_REQUEST['new_tbl_type']) !== strtolower($tbl_type)) {
76 $table_alters[] = PMA_ENGINE_KEYWORD
. ' = ' . $_REQUEST['new_tbl_type'];
77 $tbl_type = $_REQUEST['new_tbl_type'];
80 if (! empty($_REQUEST['tbl_collation'])
81 && $_REQUEST['tbl_collation'] !== $tbl_collation) {
82 $table_alters[] = 'DEFAULT ' . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
85 $l_tbl_type = strtolower($tbl_type);
87 if (($l_tbl_type === 'myisam' ||
$l_tbl_type === 'isam')
88 && isset($_REQUEST['new_pack_keys'])
89 && $_REQUEST['new_pack_keys'] != (string)$pack_keys) {
90 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
93 $checksum = empty($checksum) ?
'0' : '1';
94 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ?
'0' : '1';
95 if (($l_tbl_type === 'myisam')
96 && $_REQUEST['new_checksum'] !== $checksum) {
97 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
100 $delay_key_write = empty($delay_key_write) ?
'0' : '1';
101 $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ?
'0' : '1';
102 if (($l_tbl_type === 'myisam')
103 && $_REQUEST['new_delay_key_write'] !== $delay_key_write) {
104 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
107 if (($l_tbl_type === 'myisam' ||
$l_tbl_type === 'innodb')
108 && ! empty($_REQUEST['new_auto_increment'])
109 && (! isset($auto_increment) ||
$_REQUEST['new_auto_increment'] !== $auto_increment)) {
110 $table_alters[] = 'auto_increment = ' . PMA_sqlAddslashes($_REQUEST['new_auto_increment']);
113 if (count($table_alters) > 0) {
114 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']);
115 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
116 $result .= PMA_DBI_query($sql_query) ?
true : false;
118 unset($table_alters);
122 * Reordering the table has been requested by the user
124 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
126 ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
127 ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
128 if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
129 $sql_query .= ' DESC';
131 $result = PMA_DBI_query($sql_query);
135 * A partition operation has been requested by the user
137 if (isset($_REQUEST['submit_partition']) && ! empty($_REQUEST['partition_operation'])) {
138 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . $_REQUEST['partition_operation'] . ' PARTITION ' . $_REQUEST['partition_name'];
139 $result = PMA_DBI_query($sql_query);
143 $checksum = $delay_key_write = 0;
144 require './libraries/tbl_info.inc.php';
149 * Displays top menu links
151 require_once './libraries/tbl_links.inc.php';
153 if (isset($result)) {
154 if (empty($_message)) {
155 $_message = $result ?
$strSuccess : $strError;
157 // $result should exist, regardless of $_message
158 $_type = $result ?
'success' : 'error';
159 PMA_showMessage($_message, $sql_query, $_type);
162 $url_params['goto'] = 'tbl_operations.php';
163 $url_params['back'] = 'tbl_operations.php';
170 FROM ' . PMA_backquote($GLOBALS['table']) . '
171 FROM ' . PMA_backquote($GLOBALS['db']);
172 $columns = PMA_DBI_fetch_result($local_query, null, 'Field');
179 <!-- Order the table
-->
180 <div id
="div_table_order">
181 <form method
="post" action
="tbl_operations.php">
182 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
183 <fieldset id
="fieldset_table_order">
184 <legend
><?php
echo $strAlterOrderBy; ?
></legend
>
185 <select name
="order_field">
187 foreach ($columns as $fieldname) {
188 echo ' <option value="' . htmlspecialchars($fieldname) . '">'
189 . htmlspecialchars($fieldname) . '</option>' . "\n";
193 </select
> <?php
echo $strSingly; ?
>
194 <select name
="order_order">
195 <option value
="asc"><?php
echo $strAscending; ?
></option
>
196 <option value
="desc"><?php
echo $strDescending; ?
></option
>
198 <input type
="submit" name
="submitorderby" value
="<?php echo $strGo; ?>" />
204 <div id
="div_table_rename">
205 <form method
="post" action
="tbl_move_copy.php"
206 onsubmit
="return emptyFormElements(this, 'new_name')">
207 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
208 <input type
="hidden" name
="reload" value
="1" />
209 <input type
="hidden" name
="what" value
="data" />
210 <fieldset id
="fieldset_table_rename">
211 <legend
><?php
echo $strMoveTable; ?
></legend
>
212 <select name
="target_db">
213 <?php
echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true, false); ?
>
216 <input type
="text" size
="20" name
="new_name" onfocus
="this.select()"
217 value
="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br
/>
219 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
220 // next value but users can decide if they want it or not for the operation
222 <input type
="checkbox" name
="sql_auto_increment" value
="1" id
="checkbox_auto_increment_mv" checked
="checked" />
223 <label
for="checkbox_auto_increment_mv"><?php
echo $strAddAutoIncrement; ?
></label
><br
/>
225 <fieldset
class="tblFooters">
226 <input type
="submit" name
="submit_move" value
="<?php echo $strGo; ?>" />
232 if (strstr($show_comment, '; InnoDB free') === false) {
233 if (strstr($show_comment, 'InnoDB free') === false) {
234 // only user entered comment
235 $comment = $show_comment;
237 // here we have just InnoDB generated part
241 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
242 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
245 // PACK_KEYS: MyISAM or ISAM
246 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
247 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3
249 // nijel: Here should be version check for InnoDB, however it is supported
250 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
254 <!-- Table options
-->
255 <div id
="div_table_options">
256 <form method
="post" action
="tbl_operations.php">
257 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
258 <input type
="hidden" name
="reload" value
="1" />
260 <legend
><?php
echo $strTableOptions; ?
></legend
>
263 <!-- Change table name
-->
264 <tr
><td
><?php
echo $strRenameTable; ?
></td
>
265 <td
><input type
="text" size
="20" name
="new_name" onfocus
="this.select()"
266 value
="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
270 <!-- Table comments
-->
271 <tr
><td
><?php
echo $strTableComments; ?
></td
>
272 <td
><input type
="text" name
="comment" maxlength
="60" size
="30"
273 value
="<?php echo htmlspecialchars($comment); ?>" onfocus
="this.select()" />
274 <input type
="hidden" name
="prev_comment" value
="<?php echo urlencode($comment); ?>" />
278 <!-- Storage engine
-->
279 <tr
><td
><?php
echo $strStorageEngine; ?
>
280 <?php
echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?
>
282 <td
><?php
echo PMA_StorageEngine
::getHtmlSelect('new_tbl_type', null, $tbl_type); ?
>
286 <!-- Table character set
-->
287 <tr
><td
><?php
echo $strCollation; ?
></td
>
288 <td
><?php
echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION
,
289 'tbl_collation', null, $tbl_collation, false, 3); ?
>
293 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'ISAM') {
296 <td
><label
for="new_pack_keys">pack_keys
</label
></td
>
297 <td
><select name
="new_pack_keys" id
="new_pack_keys">
298 <option value
="DEFAULT"
299 <?php
if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?
>
302 <?php
if ($pack_keys == '0') echo 'selected="selected"'; ?
>
305 <?php
if ($pack_keys == '1') echo 'selected="selected"'; ?
>
311 } // end if (MYISAM|ISAM)
313 if ($tbl_type == 'MYISAM') {
315 <tr
><td
><label
for="new_checksum">checksum
</label
></td
>
316 <td
><input type
="checkbox" name
="new_checksum" id
="new_checksum"
318 <?php
echo (isset($checksum) && $checksum == 1)
319 ?
' checked="checked"'
324 <tr
><td
><label
for="new_delay_key_write">delay_key_write
</label
></td
>
325 <td
><input type
="checkbox" name
="new_delay_key_write" id
="new_delay_key_write"
327 <?php
echo (isset($delay_key_write) && $delay_key_write == 1)
328 ?
' checked="checked"'
336 if (isset($auto_increment) && strlen($auto_increment) > 0
337 && ($tbl_type == 'MYISAM' ||
$tbl_type == 'INNODB')) {
339 <tr
><td
><label
for="auto_increment_opt">auto_increment
</label
></td
>
340 <td
><input type
="text" name
="new_auto_increment" id
="auto_increment_opt"
341 value
="<?php echo $auto_increment; ?>" /></td
>
344 } // end if (MYISAM|INNODB)
348 <fieldset
class="tblFooters">
349 <input type
="submit" name
="submitoptions" value
="<?php echo $strGo; ?>" />
355 <div id
="div_table_copy">
356 <form method
="post" action
="tbl_move_copy.php"
357 onsubmit
="return emptyFormElements(this, 'new_name')">
358 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
359 <input type
="hidden" name
="reload" value
="1" />
361 <legend
><?php
echo $strCopyTable; ?
></legend
>
362 <select name
="target_db">
363 <?php
echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true, false); ?
>
366 <input type
="text" size
="20" name
="new_name" onfocus
="this.select()" /><br
/>
368 <input type
="radio" name
="what" value
="structure" id
="radio_copy_structure" />
369 <label
for="radio_copy_structure"><?php
echo $strStrucOnly; ?
></label
><br
/>
370 <input type
="radio" name
="what" value
="data" id
="radio_copy_data" checked
="checked" />
371 <label
for="radio_copy_data"><?php
echo $strStrucData; ?
></label
><br
/>
372 <input type
="radio" name
="what" value
="dataonly" id
="radio_copy_dataonly" />
373 <label
for="radio_copy_dataonly"><?php
echo $strDataOnly; ?
></label
><br
/>
375 <input type
="checkbox" name
="drop_if_exists" value
="true" id
="checkbox_drop" />
376 <label
for="checkbox_drop"><?php
echo sprintf($strAddClause, 'DROP TABLE'); ?
></label
><br
/>
377 <input type
="checkbox" name
="sql_auto_increment" value
="1" id
="checkbox_auto_increment_cp" />
378 <label
for="checkbox_auto_increment_cp"><?php
echo $strAddAutoIncrement; ?
></label
><br
/>
380 // display "Add constraints" choice only if there are
382 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'innodb')) {
384 <input type
="checkbox" name
="add_constraints" value
="1" id
="checkbox_constraints" />
385 <label
for="checkbox_constraints"><?php
echo $strAddConstraints; ?
></label
><br
/>
388 if (isset($_COOKIE['pma_switch_to_new'])
389 && $_COOKIE['pma_switch_to_new'] == 'true') {
390 $pma_switch_to_new = 'true';
393 <input type
="checkbox" name
="switch_to_new" value
="true"
394 id
="checkbox_switch"<?php
echo
395 isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
396 ?
' checked="checked"'
398 <label
for="checkbox_switch"><?php
echo $strSwitchToTable; ?
></label
>
400 <fieldset
class="tblFooters">
401 <input type
="submit" name
="submit_copy" value
="<?php echo $strGo; ?>" />
406 <br
class="clearfloat"/>
408 <div id
="div_table_maintenance">
410 <legend
><?php
echo $strTableMaintenance; ?
></legend
>
414 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB' ||
$tbl_type == 'INNODB') {
415 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'INNODB') {
416 $this_url_params = array_merge($url_params,
417 array('sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table'])));
419 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
420 <?php
echo $strCheckTable; ?
></a
>
421 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?
>
425 if ($tbl_type == 'INNODB') {
426 $this_url_params = array_merge($url_params,
427 array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . PMA_ENGINE_KEYWORD
. '=InnoDB'));
429 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
430 <?php
echo $strDefragment; ?
></a
>
431 <?php
echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?
>
435 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB') {
436 $this_url_params = array_merge($url_params,
437 array('sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table'])));
439 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
440 <?php
echo $strAnalyzeTable; ?
></a
>
441 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?
>
445 if ($tbl_type == 'MYISAM') {
446 $this_url_params = array_merge($url_params,
447 array('sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])));
449 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
450 <?php
echo $strRepairTable; ?
></a
>
451 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?
>
455 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB' ||
$tbl_type == 'INNODB') {
456 $this_url_params = array_merge($url_params,
457 array('sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table'])));
459 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
460 <?php
echo $strOptimizeTable; ?
></a
>
461 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?
>
465 } // end MYISAM or BERKELEYDB case
466 $this_url_params = array_merge($url_params,
468 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
469 'zero_rows' => sprintf($strTableHasBeenFlushed,
470 htmlspecialchars($GLOBALS['table'])),
474 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
475 <?php
echo $strFlushTable; ?
></a
>
476 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?
>
481 <?php
if (PMA_Partition
::havePartitioning()) {
482 $partition_names = PMA_Partition
::getPartitionNames($db, $table);
483 // show the Partition maintenance section only if we detect a partition
484 if (! is_null($partition_names[0])) {
486 <div id
="div_partition_maintenance">
487 <form method
="post" action
="tbl_operations.php">
488 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
490 <legend
><?php
echo $strPartitionMaintenance; ?
></legend
>
492 $html_select = '<select name="partition_name">' . "\n";
493 foreach($partition_names as $one_partition) {
494 $one_partition = htmlspecialchars($one_partition);
495 $html_select .= '<option value="' . $one_partition . '">' . $one_partition . '</option>' . "\n";
497 $html_select .= '</select>' . "\n";
498 printf($GLOBALS['strPartition'], $html_select);
499 unset($partition_names, $one_partition, $html_select);
501 'ANALYZE' => $strAnalyze,
502 'CHECK' => $strCheck,
503 'OPTIMIZE' => $strOptimize,
504 'REBUILD' => $strRebuild,
505 'REPAIR' => $strRepair);
506 PMA_generate_html_radio('partition_operation', $choices, '', false);
508 echo PMA_showMySQLDocu('partitioning_maintenance', 'partitioning_maintenance');
509 // I'm not sure of the best way to display that; this link does
510 // not depend on the Go button
511 $this_url_params = array_merge($url_params,
513 'sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' REMOVE PARTITIONING'
516 <br
/><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
517 <?php
echo $strRemovePartitioning; ?
></a
>
519 <fieldset
class="tblFooters">
520 <input type
="submit" name
="submit_partition" value
="<?php echo $strGo; ?>" />
528 // Referential integrity check
529 // The Referential integrity check was intended for the non-InnoDB
530 // tables for which the relations are defined in pmadb
531 // so I assume that if the current table is InnoDB, I don't display
532 // this choice (InnoDB maintains integrity by itself)
534 if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
535 PMA_DBI_select_db($GLOBALS['db']);
536 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
540 <!-- Referential integrity check
-->
542 <?php
echo $strReferentialIntegrity; ?
><br
/>
545 foreach ($foreign AS $master => $arr) {
546 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
547 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
548 . PMA_backquote($arr['foreign_table']);
549 if ($arr['foreign_table'] == $GLOBALS['table']) {
550 $foreign_table = $GLOBALS['table'] . '1';
551 $join_query .= ' AS ' . PMA_backquote($foreign_table);
553 $foreign_table = $arr['foreign_table'];
555 $join_query .= ' ON '
556 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
557 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
559 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
561 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
563 $this_url_params = array_merge($url_params,
564 array('sql_query' => $join_query));
567 . PMA_generate_common_url($this_url_params)
568 . '">' . $master . ' -> ' . $arr['foreign_table'] . '.' . $arr['foreign_field']
569 . '</a></li>' . "\n";
570 } // foreach $foreign
571 unset($foreign_table, $join_query);
575 } // end if ($foreign)
577 } // end if (!empty($cfg['Server']['relation']))
581 * Displays the footer
583 require_once './libraries/footer.inc.php';