2 /* vim: set expandtab sw=4 ts=4 sts=4: */
11 require_once 'libraries/common.inc.php';
14 * functions implementation for this script
16 require_once 'libraries/operations.lib.php';
18 $pma_table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
19 $response = PMA_Response
::getInstance();
24 require 'libraries/tbl_common.inc.php';
25 $url_query .= '&goto=tbl_operations.php&back=tbl_operations.php';
26 $url_params['goto'] = $url_params['back'] = 'tbl_operations.php';
29 * Gets relation settings
31 $cfgRelation = PMA_getRelationsParam();
34 * Gets available MySQL charsets and storage engines
36 require_once 'libraries/mysql_charsets.lib.php';
37 require_once 'libraries/StorageEngine.class.php';
40 * Class for partition management
42 require_once 'libraries/Partition.class.php';
44 // reselect current db (needed in some cases probably due to
45 // the calling of relation.lib.php)
46 PMA_DBI_select_db($GLOBALS['db']);
49 * Gets tables informations
51 require 'libraries/tbl_info.inc.php';
53 // define some variables 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 variables, based on the current table engine
56 list($is_myisam_or_aria, $is_innodb, $is_isam,
57 $is_berkeleydb, $is_aria, $is_pbxt
58 ) = PMA_setGlobalVariablesForEngine($tbl_storage_engine);
61 // the value for transactional can be implicit
62 // (no create option found, in this case it means 1)
63 // or explicit (option found with a value of 0 or 1)
64 // ($transactional may have been set by libraries/tbl_info.inc.php,
65 // from the $create_options)
66 $transactional = (isset($transactional) && $transactional == '0')
69 $page_checksum = (isset($page_checksum)) ?
$page_checksum : '';
73 $table_alters = array();
76 * If the table has to be moved to some other database
78 if (isset($_REQUEST['submit_move']) ||
isset($_REQUEST['submit_copy'])) {
80 include_once 'tbl_move_copy.php';
83 * If the table has to be maintained
85 if (isset($_REQUEST['table_maintenance'])) {
86 include_once 'sql.php';
90 * Updates table comment, type and options if required
92 if (isset($_REQUEST['submitoptions'])) {
94 $warning_messages = array();
96 if (isset($_REQUEST['new_name'])) {
97 if ($pma_table->rename($_REQUEST['new_name'])) {
98 $_message .= $pma_table->getLastMessage();
100 $GLOBALS['table'] = $pma_table->getName();
104 $_message .= $pma_table->getLastError();
109 if (! empty($_REQUEST['new_tbl_storage_engine'])
110 && strtolower($_REQUEST['new_tbl_storage_engine'])
111 !== strtolower($tbl_storage_engine)
113 $new_tbl_storage_engine = $_REQUEST['new_tbl_storage_engine'];
114 // reset the globals for the new engine
115 list($is_myisam_or_aria, $is_innodb, $is_isam,
116 $is_berkeleydb, $is_aria, $is_pbxt
117 ) = PMA_setGlobalVariablesForEngine($new_tbl_storage_engine);
120 $transactional = (isset($transactional) && $transactional == '0')
123 $page_checksum = (isset($page_checksum)) ?
$page_checksum : '';
126 $new_tbl_storage_engine = '';
129 $table_alters = PMA_getTableAltersArray(
130 $is_myisam_or_aria, $is_isam, $pack_keys,
131 (empty($checksum) ?
'0' : '1'),
133 ((isset($page_checksum)) ?
$page_checksum : ''),
134 (empty($delay_key_write) ?
'0' : '1'),
135 $is_innodb, $is_pbxt, $row_format,
136 $new_tbl_storage_engine,
137 ((isset($transactional) && $transactional == '0') ?
'0' : '1'),
141 if (count($table_alters) > 0) {
142 $sql_query = 'ALTER TABLE '
143 . PMA_Util
::backquote($GLOBALS['table']);
144 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
146 $result .= PMA_DBI_query($sql_query) ?
true : false;
148 unset($table_alters);
149 $warning_messages = PMA_getWarningMessagesArray();
153 * Reordering the table has been requested by the user
155 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
156 list($sql_query, $result) = PMA_getQueryAndResultForReorderingTable();
160 * A partition operation has been requested by the user
162 if (isset($_REQUEST['submit_partition'])
163 && ! empty($_REQUEST['partition_operation'])
165 list($sql_query, $result) = PMA_getQueryAndResultForPartition();
169 // to avoid showing the old value (for example the AUTO_INCREMENT) after
170 // a change, clear the cache
171 PMA_Table
::$cache = array();
172 $page_checksum = $checksum = $delay_key_write = 0;
173 include 'libraries/tbl_info.inc.php';
177 if (isset($result) && empty($message_to_show)) {
178 // set to success by default, because result set could be empty
179 // (for example, a table rename)
181 if (empty($_message)) {
183 ? PMA_Message
::success(
184 __('Your SQL query has been executed successfully')
186 : PMA_Message
::error(__('Error'));
187 // $result should exist, regardless of $_message
188 $_type = $result ?
'success' : 'error';
190 if (isset($GLOBALS['ajax_request'])
191 && $GLOBALS['ajax_request'] == true
193 $response = PMA_Response
::getInstance();
194 $response->isSuccess($_message->isSuccess());
195 $response->addJSON('message', $_message);
197 'sql_query', PMA_Util
::getMessage(null, $sql_query)
202 if (! empty($warning_messages)) {
203 $_message = new PMA_Message
;
204 $_message->addMessages($warning_messages);
205 $_message->isError(true);
206 if ($GLOBALS['ajax_request'] == true) {
207 $response = PMA_Response
::getInstance();
208 $response->isSuccess(false);
209 $response->addJSON('message', $_message);
212 unset($warning_messages);
216 PMA_Util
::getMessage($_message, $sql_query, $_type)
218 unset($_message, $_type);
222 = $url_params['back']
223 = 'tbl_operations.php';
228 $columns = PMA_DBI_get_columns($GLOBALS['db'], $GLOBALS['table']);
236 $hideOrderTable = false;
237 // `ALTER TABLE ORDER BY` does not make sense for InnoDB tables that contain
238 // a user-defined clustered index (PRIMARY KEY or NOT NULL UNIQUE index).
239 // InnoDB always orders table rows according to such an index if one is present.
240 if ($tbl_storage_engine == 'INNODB') {
241 include_once 'libraries/Index.class.php';
242 $indexes = PMA_Index
::getFromTable($GLOBALS['table'], $GLOBALS['db']);
243 foreach ($indexes as $name => $idx) {
244 if ($name == 'PRIMARY') {
245 $hideOrderTable = true;
247 } elseif (! $idx->getNonUnique()) {
249 foreach ($idx->getColumns() as $column) {
250 if ($column->getNull()) {
256 $hideOrderTable = true;
262 if (! $hideOrderTable) {
263 $response->addHTML(PMA_getHtmlForOrderTheTable($columns));
269 $response->addHTML(PMA_getHtmlForMoveTable());
271 if (strstr($show_comment, '; InnoDB free') === false) {
272 if (strstr($show_comment, 'InnoDB free') === false) {
273 // only user entered comment
274 $comment = $show_comment;
276 // here we have just InnoDB generated part
280 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
281 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
284 // PACK_KEYS: MyISAM or ISAM
285 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
286 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3, PBXT
288 // Here should be version check for InnoDB, however it is supported
289 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
293 PMA_getTableOptionDiv(
294 $comment, $tbl_collation, $tbl_storage_engine,
295 $is_myisam_or_aria, $is_isam, $pack_keys,
297 (empty($delay_key_write) ?
'0' : '1'),
298 ((isset($transactional) && $transactional == '0') ?
'0' : '1'),
299 ((isset($page_checksum)) ?
$page_checksum : ''),
300 $is_innodb, $is_pbxt, $is_aria, (empty($checksum) ?
'0' : '1')
307 $response->addHTML(PMA_getHtmlForCopytable());
309 $response->addHTML('<br class="clearfloat"/>');
315 PMA_getHtmlForTableMaintenance(
323 if (! (isset($db_is_information_schema) && $db_is_information_schema)) {
324 $truncate_table_url_params = array();
325 $drop_table_url_params = array();
328 && ! (isset($db_is_information_schema) && $db_is_information_schema)
330 $this_sql_query = 'TRUNCATE TABLE '
331 . PMA_Util
::backquote($GLOBALS['table']);
332 $truncate_table_url_params = array_merge(
335 'sql_query' => $this_sql_query,
336 'goto' => 'tbl_structure.php',
338 'message_to_show' => sprintf(
339 __('Table %s has been emptied'),
340 htmlspecialchars($table)
345 if (! (isset($db_is_information_schema) && $db_is_information_schema)) {
346 $this_sql_query = 'DROP TABLE '
347 . PMA_Util
::backquote($GLOBALS['table']);
348 $drop_table_url_params = array_merge(
351 'sql_query' => $this_sql_query,
352 'goto' => 'db_operations.php',
355 'message_to_show' => sprintf(
357 ?
__('View %s has been dropped')
358 : __('Table %s has been dropped')
360 htmlspecialchars($table)
362 // table name is needed to avoid running
363 // PMA_relationsCleanupDatabase() on the whole db later
364 'table' => $GLOBALS['table'],
369 PMA_getHtmlForDeleteDataOrTable(
370 $truncate_table_url_params,
371 $drop_table_url_params
375 $response->addHTML('<br class="clearfloat">');
377 if (PMA_Partition
::havePartitioning()) {
378 $partition_names = PMA_Partition
::getPartitionNames($db, $table);
379 // show the Partition maintenance section only if we detect a partition
380 if (! is_null($partition_names[0])) {
382 PMA_getHtmlForPartitionMaintenance($partition_names, $url_params)
386 unset($partition_names);
388 // Referential integrity check
389 // The Referential integrity check was intended for the non-InnoDB
390 // tables for which the relations are defined in pmadb
391 // so I assume that if the current table is InnoDB, I don't display
392 // this choice (InnoDB maintains integrity by itself)
394 if ($cfgRelation['relwork'] && ! $is_innodb) {
395 PMA_DBI_select_db($GLOBALS['db']);
396 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
400 PMA_getHtmlForReferentialIntegrityCheck($foreign, $url_params)
402 } // end if ($foreign)
404 } // end if (!empty($cfg['Server']['relation']))