2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Various table operations
12 require_once 'libraries/common.inc.php';
15 * functions implementation for this script
17 require_once 'libraries/operations.lib.php';
19 $pma_table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
20 $response = PMA_Response
::getInstance();
25 require 'libraries/tbl_common.inc.php';
26 $url_query .= '&goto=tbl_operations.php&back=tbl_operations.php';
27 $url_params['goto'] = $url_params['back'] = 'tbl_operations.php';
30 * Gets relation settings
32 $cfgRelation = PMA_getRelationsParam();
35 * Gets available MySQL charsets and storage engines
37 require_once 'libraries/mysql_charsets.inc.php';
38 require_once 'libraries/StorageEngine.class.php';
41 * Class for partition management
43 require_once 'libraries/Partition.class.php';
45 // reselect current db (needed in some cases probably due to
46 // the calling of relation.lib.php)
47 $GLOBALS['dbi']->selectDb($GLOBALS['db']);
50 * Gets tables informations
52 require 'libraries/tbl_info.inc.php';
54 // define some variables here, for improved syntax in the conditionals
55 $is_myisam_or_aria = $is_isam = $is_innodb = $is_berkeleydb = false;
56 $is_aria = $is_pbxt = false;
57 // set initial value of these variables, based on the current table engine
58 list($is_myisam_or_aria, $is_innodb, $is_isam,
59 $is_berkeleydb, $is_aria, $is_pbxt
60 ) = PMA_setGlobalVariablesForEngine($tbl_storage_engine);
63 // the value for transactional can be implicit
64 // (no create option found, in this case it means 1)
65 // or explicit (option found with a value of 0 or 1)
66 // ($transactional may have been set by libraries/tbl_info.inc.php,
67 // from the $create_options)
68 $transactional = (isset($transactional) && $transactional == '0')
71 $page_checksum = (isset($page_checksum)) ?
$page_checksum : '';
75 $table_alters = array();
78 * If the table has to be moved to some other database
80 if (isset($_REQUEST['submit_move']) ||
isset($_REQUEST['submit_copy'])) {
82 include_once 'tbl_move_copy.php';
85 * If the table has to be maintained
87 if (isset($_REQUEST['table_maintenance'])) {
88 include_once 'sql.php';
92 * Updates table comment, type and options if required
94 if (isset($_REQUEST['submitoptions'])) {
96 $warning_messages = array();
98 if (isset($_REQUEST['new_name'])) {
99 if ($pma_table->rename($_REQUEST['new_name'])) {
100 $_message .= $pma_table->getLastMessage();
102 $GLOBALS['table'] = $pma_table->getName();
106 $_message .= $pma_table->getLastError();
111 if (! empty($_REQUEST['new_tbl_storage_engine'])
112 && strtolower($_REQUEST['new_tbl_storage_engine']) !== strtolower($tbl_storage_engine)
114 $new_tbl_storage_engine = $_REQUEST['new_tbl_storage_engine'];
115 // reset the globals for the new engine
116 list($is_myisam_or_aria, $is_innodb, $is_isam,
117 $is_berkeleydb, $is_aria, $is_pbxt
118 ) = PMA_setGlobalVariablesForEngine($new_tbl_storage_engine);
121 $transactional = (isset($transactional) && $transactional == '0')
124 $page_checksum = (isset($page_checksum)) ?
$page_checksum : '';
127 $new_tbl_storage_engine = '';
130 $table_alters = PMA_getTableAltersArray(
131 $is_myisam_or_aria, $is_isam, $pack_keys,
132 (empty($checksum) ?
'0' : '1'),
134 ((isset($page_checksum)) ?
$page_checksum : ''),
135 (empty($delay_key_write) ?
'0' : '1'),
136 $is_innodb, $is_pbxt, $row_format,
137 $new_tbl_storage_engine,
138 ((isset($transactional) && $transactional == '0') ?
'0' : '1'),
142 if (count($table_alters) > 0) {
143 $sql_query = 'ALTER TABLE '
144 . PMA_Util
::backquote($GLOBALS['table']);
145 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
147 $result .= $GLOBALS['dbi']->query($sql_query) ?
true : false;
149 unset($table_alters);
150 $warning_messages = PMA_getWarningMessagesArray();
154 * Reordering the table has been requested by the user
156 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
157 list($sql_query, $result) = PMA_getQueryAndResultForReorderingTable();
161 * A partition operation has been requested by the user
163 if (isset($_REQUEST['submit_partition'])
164 && ! empty($_REQUEST['partition_operation'])
166 list($sql_query, $result) = PMA_getQueryAndResultForPartition();
170 // to avoid showing the old value (for example the AUTO_INCREMENT) after
171 // a change, clear the cache
172 PMA_Table
::$cache = array();
173 $page_checksum = $checksum = $delay_key_write = 0;
174 include 'libraries/tbl_info.inc.php';
178 if (isset($result) && empty($message_to_show)) {
179 // set to success by default, because result set could be empty
180 // (for example, a table rename)
182 if (empty($_message)) {
184 ? PMA_Message
::success(
185 __('Your SQL query has been executed successfully')
187 : PMA_Message
::error(__('Error'));
188 // $result should exist, regardless of $_message
189 $_type = $result ?
'success' : 'error';
191 if (isset($GLOBALS['ajax_request'])
192 && $GLOBALS['ajax_request'] == true
194 $response = PMA_Response
::getInstance();
195 $response->isSuccess($_message->isSuccess());
196 $response->addJSON('message', $_message);
198 'sql_query', PMA_Util
::getMessage(null, $sql_query)
203 if (! empty($warning_messages)) {
204 $_message = new PMA_Message
;
205 $_message->addMessages($warning_messages);
206 $_message->isError(true);
207 if ($GLOBALS['ajax_request'] == true) {
208 $response = PMA_Response
::getInstance();
209 $response->isSuccess(false);
210 $response->addJSON('message', $_message);
213 unset($warning_messages);
217 PMA_Util
::getMessage($_message, $sql_query, $_type)
219 unset($_message, $_type);
223 = $url_params['back']
224 = 'tbl_operations.php';
229 $columns = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $GLOBALS['table']);
234 $response->addHTML('<div id="boxContainer" data-box-width="300">');
239 $response->addHTML(PMA_getHtmlForOrderTheTable($columns));
244 $response->addHTML(PMA_getHtmlForMoveTable());
246 if (strstr($show_comment, '; InnoDB free') === false) {
247 if (strstr($show_comment, 'InnoDB free') === false) {
248 // only user entered comment
249 $comment = $show_comment;
251 // here we have just InnoDB generated part
255 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
256 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
259 // PACK_KEYS: MyISAM or ISAM
260 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
261 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3, PBXT
263 // Here should be version check for InnoDB, however it is supported
264 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
268 PMA_getTableOptionDiv(
269 $comment, $tbl_collation, $tbl_storage_engine,
270 $is_myisam_or_aria, $is_isam, $pack_keys,
272 (empty($delay_key_write) ?
'0' : '1'),
273 ((isset($transactional) && $transactional == '0') ?
'0' : '1'),
274 ((isset($page_checksum)) ?
$page_checksum : ''),
275 $is_innodb, $is_pbxt, $is_aria, (empty($checksum) ?
'0' : '1')
282 $response->addHTML(PMA_getHtmlForCopytable());
288 PMA_getHtmlForTableMaintenance(
296 if (! (isset($db_is_information_schema) && $db_is_information_schema)) {
297 $truncate_table_url_params = array();
298 $drop_table_url_params = array();
301 && ! (isset($db_is_information_schema) && $db_is_information_schema)
303 $this_sql_query = 'TRUNCATE TABLE '
304 . PMA_Util
::backquote($GLOBALS['table']);
305 $truncate_table_url_params = array_merge(
308 'sql_query' => $this_sql_query,
309 'goto' => 'tbl_structure.php',
311 'message_to_show' => sprintf(
312 __('Table %s has been emptied'),
313 htmlspecialchars($table)
318 if (! (isset($db_is_information_schema) && $db_is_information_schema)) {
319 $this_sql_query = 'DROP TABLE '
320 . PMA_Util
::backquote($GLOBALS['table']);
321 $drop_table_url_params = array_merge(
324 'sql_query' => $this_sql_query,
325 'goto' => 'db_operations.php',
328 'message_to_show' => sprintf(
330 ?
__('View %s has been dropped')
331 : __('Table %s has been dropped')
333 htmlspecialchars($table)
335 // table name is needed to avoid running
336 // PMA_relationsCleanupDatabase() on the whole db later
337 'table' => $GLOBALS['table'],
342 PMA_getHtmlForDeleteDataOrTable(
343 $truncate_table_url_params,
344 $drop_table_url_params
349 if (PMA_Partition
::havePartitioning()) {
350 $partition_names = PMA_Partition
::getPartitionNames($db, $table);
351 // show the Partition maintenance section only if we detect a partition
352 if (! is_null($partition_names[0])) {
354 PMA_getHtmlForPartitionMaintenance($partition_names, $url_params)
358 unset($partition_names);
360 // Referential integrity check
361 // The Referential integrity check was intended for the non-InnoDB
362 // tables for which the relations are defined in pmadb
363 // so I assume that if the current table is InnoDB, I don't display
364 // this choice (InnoDB maintains integrity by itself)
366 if ($cfgRelation['relwork'] && ! $is_innodb) {
367 $GLOBALS['dbi']->selectDb($GLOBALS['db']);
368 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
372 PMA_getHtmlForReferentialIntegrityCheck($foreign, $url_params)
374 } // end if ($foreign)
376 } // end if (!empty($cfg['Server']['relation']))
378 $response->addHTML('</div>');