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[] = 'ENGINE = ' . $_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 <?php
if ($GLOBALS['PMA_List_Database']->count() > $GLOBALS['cfg']['MaxDbList']) {
214 <input type
="text" maxlength
="100" size
="30" name
="target_db" value
="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
218 <select name
="target_db">
219 <?php
echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true, false); ?
>
225 <input type
="text" size
="20" name
="new_name" onfocus
="this.select()"
226 value
="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br
/>
228 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
229 // next value but users can decide if they want it or not for the operation
231 <input type
="checkbox" name
="sql_auto_increment" value
="1" id
="checkbox_auto_increment_mv" checked
="checked" />
232 <label
for="checkbox_auto_increment_mv"><?php
echo $strAddAutoIncrement; ?
></label
><br
/>
234 <fieldset
class="tblFooters">
235 <input type
="submit" name
="submit_move" value
="<?php echo $strGo; ?>" />
241 if (strstr($show_comment, '; InnoDB free') === false) {
242 if (strstr($show_comment, 'InnoDB free') === false) {
243 // only user entered comment
244 $comment = $show_comment;
246 // here we have just InnoDB generated part
250 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
251 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
254 // PACK_KEYS: MyISAM or ISAM
255 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
256 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3
258 // nijel: Here should be version check for InnoDB, however it is supported
259 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
263 <!-- Table options
-->
264 <div id
="div_table_options">
265 <form method
="post" action
="tbl_operations.php">
266 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
267 <input type
="hidden" name
="reload" value
="1" />
269 <legend
><?php
echo $strTableOptions; ?
></legend
>
272 <!-- Change table name
-->
273 <tr
><td
><?php
echo $strRenameTable; ?
></td
>
274 <td
><input type
="text" size
="20" name
="new_name" onfocus
="this.select()"
275 value
="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
279 <!-- Table comments
-->
280 <tr
><td
><?php
echo $strTableComments; ?
></td
>
281 <td
><input type
="text" name
="comment" maxlength
="60" size
="30"
282 value
="<?php echo htmlspecialchars($comment); ?>" onfocus
="this.select()" />
283 <input type
="hidden" name
="prev_comment" value
="<?php echo urlencode($comment); ?>" />
287 <!-- Storage engine
-->
288 <tr
><td
><?php
echo $strStorageEngine; ?
>
289 <?php
echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?
>
291 <td
><?php
echo PMA_StorageEngine
::getHtmlSelect('new_tbl_type', null, $tbl_type); ?
>
295 <!-- Table character set
-->
296 <tr
><td
><?php
echo $strCollation; ?
></td
>
297 <td
><?php
echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION
,
298 'tbl_collation', null, $tbl_collation, false, 3); ?
>
302 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'ISAM') {
305 <td
><label
for="new_pack_keys">pack_keys
</label
></td
>
306 <td
><select name
="new_pack_keys" id
="new_pack_keys">
307 <option value
="DEFAULT"
308 <?php
if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?
>
311 <?php
if ($pack_keys == '0') echo 'selected="selected"'; ?
>
314 <?php
if ($pack_keys == '1') echo 'selected="selected"'; ?
>
320 } // end if (MYISAM|ISAM)
322 if ($tbl_type == 'MYISAM') {
324 <tr
><td
><label
for="new_checksum">checksum
</label
></td
>
325 <td
><input type
="checkbox" name
="new_checksum" id
="new_checksum"
327 <?php
echo (isset($checksum) && $checksum == 1)
328 ?
' checked="checked"'
333 <tr
><td
><label
for="new_delay_key_write">delay_key_write
</label
></td
>
334 <td
><input type
="checkbox" name
="new_delay_key_write" id
="new_delay_key_write"
336 <?php
echo (isset($delay_key_write) && $delay_key_write == 1)
337 ?
' checked="checked"'
345 if (isset($auto_increment) && strlen($auto_increment) > 0
346 && ($tbl_type == 'MYISAM' ||
$tbl_type == 'INNODB')) {
348 <tr
><td
><label
for="auto_increment_opt">auto_increment
</label
></td
>
349 <td
><input type
="text" name
="new_auto_increment" id
="auto_increment_opt"
350 value
="<?php echo $auto_increment; ?>" /></td
>
353 } // end if (MYISAM|INNODB)
357 <fieldset
class="tblFooters">
358 <input type
="submit" name
="submitoptions" value
="<?php echo $strGo; ?>" />
364 <div id
="div_table_copy">
365 <form method
="post" action
="tbl_move_copy.php"
366 onsubmit
="return emptyFormElements(this, 'new_name')">
367 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
368 <input type
="hidden" name
="reload" value
="1" />
370 <legend
><?php
echo $strCopyTable; ?
></legend
>
371 <?php
if ($GLOBALS['PMA_List_Database']->count() > $GLOBALS['cfg']['MaxDbList']) {
373 <input type
="text" maxlength
="100" size
="30" name
="target_db" value
="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
377 <select name
="target_db">
378 <?php
echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true, false); ?
>
384 <input type
="text" size
="20" name
="new_name" onfocus
="this.select()" /><br
/>
387 'structure' => $strStrucOnly,
388 'data' => $strStrucData,
389 'dataonly' => $strDataOnly);
390 PMA_generate_html_radio('what', $choices, 'data', true);
394 <input type
="checkbox" name
="drop_if_exists" value
="true" id
="checkbox_drop" />
395 <label
for="checkbox_drop"><?php
echo sprintf($strAddClause, 'DROP TABLE'); ?
></label
><br
/>
396 <input type
="checkbox" name
="sql_auto_increment" value
="1" id
="checkbox_auto_increment_cp" />
397 <label
for="checkbox_auto_increment_cp"><?php
echo $strAddAutoIncrement; ?
></label
><br
/>
399 // display "Add constraints" choice only if there are
401 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'innodb')) {
403 <input type
="checkbox" name
="add_constraints" value
="1" id
="checkbox_constraints" />
404 <label
for="checkbox_constraints"><?php
echo $strAddConstraints; ?
></label
><br
/>
407 if (isset($_COOKIE['pma_switch_to_new'])
408 && $_COOKIE['pma_switch_to_new'] == 'true') {
409 $pma_switch_to_new = 'true';
412 <input type
="checkbox" name
="switch_to_new" value
="true"
413 id
="checkbox_switch"<?php
echo
414 isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
415 ?
' checked="checked"'
417 <label
for="checkbox_switch"><?php
echo $strSwitchToTable; ?
></label
>
419 <fieldset
class="tblFooters">
420 <input type
="submit" name
="submit_copy" value
="<?php echo $strGo; ?>" />
425 <br
class="clearfloat"/>
427 <div id
="div_table_maintenance">
429 <legend
><?php
echo $strTableMaintenance; ?
></legend
>
433 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB' ||
$tbl_type == 'INNODB') {
434 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'INNODB') {
435 $this_url_params = array_merge($url_params,
436 array('sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table'])));
438 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
439 <?php
echo $strCheckTable; ?
></a
>
440 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?
>
444 if ($tbl_type == 'INNODB') {
445 $this_url_params = array_merge($url_params,
446 array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ENGINE = InnoDB'));
448 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
449 <?php
echo $strDefragment; ?
></a
>
450 <?php
echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?
>
454 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB') {
455 $this_url_params = array_merge($url_params,
456 array('sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table'])));
458 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
459 <?php
echo $strAnalyzeTable; ?
></a
>
460 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?
>
464 if ($tbl_type == 'MYISAM') {
465 $this_url_params = array_merge($url_params,
466 array('sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])));
468 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
469 <?php
echo $strRepairTable; ?
></a
>
470 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?
>
474 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB' ||
$tbl_type == 'INNODB') {
475 $this_url_params = array_merge($url_params,
476 array('sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table'])));
478 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
479 <?php
echo $strOptimizeTable; ?
></a
>
480 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?
>
484 } // end MYISAM or BERKELEYDB case
485 $this_url_params = array_merge($url_params,
487 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
488 'zero_rows' => sprintf($strTableHasBeenFlushed,
489 htmlspecialchars($GLOBALS['table'])),
493 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
494 <?php
echo $strFlushTable; ?
></a
>
495 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?
>
500 <?php
if (PMA_Partition
::havePartitioning()) {
501 $partition_names = PMA_Partition
::getPartitionNames($db, $table);
502 // show the Partition maintenance section only if we detect a partition
503 if (! is_null($partition_names[0])) {
505 <div id
="div_partition_maintenance">
506 <form method
="post" action
="tbl_operations.php">
507 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
509 <legend
><?php
echo $strPartitionMaintenance; ?
></legend
>
511 $html_select = '<select name="partition_name">' . "\n";
512 foreach($partition_names as $one_partition) {
513 $one_partition = htmlspecialchars($one_partition);
514 $html_select .= '<option value="' . $one_partition . '">' . $one_partition . '</option>' . "\n";
516 $html_select .= '</select>' . "\n";
517 printf($GLOBALS['strPartition'], $html_select);
518 unset($partition_names, $one_partition, $html_select);
520 'ANALYZE' => $strAnalyze,
521 'CHECK' => $strCheck,
522 'OPTIMIZE' => $strOptimize,
523 'REBUILD' => $strRebuild,
524 'REPAIR' => $strRepair);
525 PMA_generate_html_radio('partition_operation', $choices, '', false);
527 echo PMA_showMySQLDocu('partitioning_maintenance', 'partitioning_maintenance');
528 // I'm not sure of the best way to display that; this link does
529 // not depend on the Go button
530 $this_url_params = array_merge($url_params,
532 'sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' REMOVE PARTITIONING'
535 <br
/><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
536 <?php
echo $strRemovePartitioning; ?
></a
>
538 <fieldset
class="tblFooters">
539 <input type
="submit" name
="submit_partition" value
="<?php echo $strGo; ?>" />
547 // Referential integrity check
548 // The Referential integrity check was intended for the non-InnoDB
549 // tables for which the relations are defined in pmadb
550 // so I assume that if the current table is InnoDB, I don't display
551 // this choice (InnoDB maintains integrity by itself)
553 if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
554 PMA_DBI_select_db($GLOBALS['db']);
555 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
559 <!-- Referential integrity check
-->
560 <div id
="div_referential_integrity">
562 <legend
><?php
echo $strReferentialIntegrity; ?
></legend
>
566 foreach ($foreign AS $master => $arr) {
567 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
568 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
569 . PMA_backquote($arr['foreign_table']);
570 if ($arr['foreign_table'] == $GLOBALS['table']) {
571 $foreign_table = $GLOBALS['table'] . '1';
572 $join_query .= ' AS ' . PMA_backquote($foreign_table);
574 $foreign_table = $arr['foreign_table'];
576 $join_query .= ' ON '
577 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
578 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
580 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
582 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
584 $this_url_params = array_merge($url_params,
585 array('sql_query' => $join_query));
588 . PMA_generate_common_url($this_url_params)
589 . '">' . $master . ' -> ' . $arr['foreign_table'] . '.' . $arr['foreign_field']
590 . '</a></li>' . "\n";
591 } // foreach $foreign
592 unset($foreign_table, $join_query);
598 } // end if ($foreign)
600 } // end if (!empty($cfg['Server']['relation']))
604 * Displays the footer
606 require_once './libraries/footer.inc.php';