2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays table structure infos like fields/columns, indexes, size, rows
5 * and allows manipulation of indexes and columns/fields
13 require_once 'libraries/common.inc.php';
14 require_once 'libraries/mysql_charsets.lib.php';
17 * Function implementations for this script
19 require_once 'libraries/structure.lib.php';
20 require_once 'libraries/index.lib.php';
22 $response = PMA_Response
::getInstance();
23 $header = $response->getHeader();
24 $scripts = $header->getScripts();
25 $scripts->addFile('tbl_structure.js');
26 $scripts->addFile('indexes.js');
29 * Handle column moving
31 if (isset($_REQUEST['move_columns'])
32 && is_array($_REQUEST['move_columns'])
33 && $response->isAjax()
35 PMA_moveColumns($db, $table);
40 * A click on Change has been made for one column
42 if (isset($_REQUEST['change_column'])) {
43 PMA_displayHtmlForColumnChange($db, $table, null, 'tbl_structure.php');
47 * Modifications have been submitted -> updates the table
49 if (isset($_REQUEST['do_save_data'])) {
50 $regenerate = PMA_updateColumns($db, $table);
52 // This happens when updating failed
53 // @todo: do something appropriate
55 // continue to show the table's structure
56 unset($_REQUEST['selected']);
57 unset($_REQUEST['true_selected']);
62 * handle multiple field commands if required
64 * submit_mult_*_x comes from IE if <input type="img" ...> is used
66 if (isset($_REQUEST['submit_mult_change_x'])) {
67 $submit_mult = 'change';
68 } elseif (isset($_REQUEST['submit_mult_drop_x'])) {
69 $submit_mult = 'drop';
70 } elseif (isset($_REQUEST['submit_mult_primary_x'])) {
71 $submit_mult = 'primary';
72 } elseif (isset($_REQUEST['submit_mult_index_x'])) {
73 $submit_mult = 'index';
74 } elseif (isset($_REQUEST['submit_mult_unique_x'])) {
75 $submit_mult = 'unique';
76 } elseif (isset($_REQUEST['submit_mult_spatial_x'])) {
77 $submit_mult = 'spatial';
78 } elseif (isset($_REQUEST['submit_mult_fulltext_x'])) {
79 $submit_mult = 'ftext';
80 } elseif (isset($_REQUEST['submit_mult_browse_x'])) {
81 $submit_mult = 'browse';
82 } elseif (isset($_REQUEST['submit_mult'])) {
83 $submit_mult = $_REQUEST['submit_mult'];
84 } elseif (isset($_REQUEST['mult_btn']) && $_REQUEST['mult_btn'] == __('Yes')) {
85 $submit_mult = 'row_delete';
86 if (isset($_REQUEST['selected'])) {
87 $_REQUEST['selected_fld'] = $_REQUEST['selected'];
90 if (! empty($submit_mult)) {
91 if (isset($_REQUEST['selected_fld'])) {
92 $err_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
93 if ($submit_mult == 'browse') {
94 // browsing the table displaying only selected fields/columns
95 $GLOBALS['active_page'] = 'sql.php';
97 foreach ($_REQUEST['selected_fld'] as $idx => $sval) {
98 if ($sql_query == '') {
99 $sql_query .= 'SELECT ' . PMA_Util
::backquote($sval);
101 $sql_query .= ', ' . PMA_Util
::backquote($sval);
104 $sql_query .= ' FROM ' . PMA_Util
::backquote($db)
105 . '.' . PMA_Util
::backquote($table);
109 // handle multiple field commands
110 // handle confirmation of deleting multiple fields/columns
111 $action = 'tbl_structure.php';
112 include 'libraries/mult_submits.inc.php';
114 * if $submit_mult == 'change', execution will have stopped
118 if (empty($message)) {
119 $message = PMA_Message
::success();
123 $response = PMA_Response
::getInstance();
124 $response->isSuccess(false);
125 $response->addJSON('message', __('No column selected.'));
130 * Gets the relation settings
132 $cfgRelation = PMA_getRelationsParam();
137 require_once 'libraries/tbl_common.inc.php';
138 $url_query .= '&goto=tbl_structure.php&back=tbl_structure.php';
139 $url_params['goto'] = 'tbl_structure.php';
140 $url_params['back'] = 'tbl_structure.php';
142 // Check column names for MySQL reserved words
143 $reserved_word_column_messages = PMA_getReservedWordColumnNameMessages($db, $table);
144 $response->addHTML($reserved_word_column_messages);
147 * Prepares the table structure display
152 * Gets tables informations
154 require_once 'libraries/tbl_info.inc.php';
156 require_once 'libraries/Index.class.php';
158 // 2. Gets table keys and retains them
159 // @todo should be: $server->db($db)->table($table)->primary()
160 $primary = PMA_Index
::getPrimary($table, $db);
162 $columns_with_unique_index = PMA_getColumnsWithUniqueIndex($db, $table);
165 $fields = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true);
167 // Get more complete field information
168 // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
169 // but later, if the analyser returns more information, it
170 // could be executed for any MySQL version and replace
171 // the info given by SHOW FULL COLUMNS FROM.
173 // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
174 // SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
175 // and SHOW CREATE TABLE says NOT NULL (tested
176 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
178 $show_create_table = $GLOBALS['dbi']->fetchValue(
179 'SHOW CREATE TABLE ' . PMA_Util
::backquote($db) . '.'
180 . PMA_Util
::backquote($table),
183 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
186 * prepare table infos
188 // action titles (image or string)
189 $titles = PMA_getActionTitlesArray();
191 // hidden action titles (image and string)
192 $hidden_titles = PMA_getHiddenTitlesArray();
194 //display table structure
195 require_once 'libraries/display_structure.lib.php';