Merge remote-tracking branch 'origin/master'
[phpmyadmin.git] / tbl_structure.php
blob1a210cf22d06536e508680fbe48c19745d7768b6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays table structure infos like columns, indexes, size, rows
5 * and allows manipulation of indexes and columns
7 * @package PhpMyAdmin
8 */
10 /**
13 require_once 'libraries/common.inc.php';
14 require_once 'libraries/mysql_charsets.inc.php';
16 /**
17 * Function implementations for this script
19 require_once 'libraries/structure.lib.php';
20 require_once 'libraries/index.lib.php';
21 require_once 'libraries/sql.lib.php';
22 require_once 'libraries/bookmark.lib.php';
24 $response = PMA_Response::getInstance();
25 $header = $response->getHeader();
26 $scripts = $header->getScripts();
27 $scripts->addFile('tbl_structure.js');
28 $scripts->addFile('indexes.js');
30 /**
31 * Handle column moving
33 if (isset($_REQUEST['move_columns'])
34 && is_array($_REQUEST['move_columns'])
35 && $response->isAjax()
36 ) {
37 PMA_moveColumns($db, $table);
38 exit;
41 /**
42 * A click on Change has been made for one column
44 if (isset($_REQUEST['change_column'])) {
45 PMA_displayHtmlForColumnChange($db, $table, null, 'tbl_structure.php');
46 exit;
48 /**
49 * Modifications have been submitted -> updates the table
51 if (isset($_REQUEST['do_save_data'])) {
52 $regenerate = PMA_updateColumns($db, $table);
53 if ($regenerate) {
54 // This happens when updating failed
55 // @todo: do something appropriate
56 } else {
57 // continue to show the table's structure
58 unset($_REQUEST['selected']);
59 unset($_REQUEST['true_selected']);
63 /**
64 * handle multiple field commands if required
66 * submit_mult_*_x comes from IE if <input type="img" ...> is used
68 if (isset($_REQUEST['submit_mult_change_x'])) {
69 $submit_mult = 'change';
70 } elseif (isset($_REQUEST['submit_mult_drop_x'])) {
71 $submit_mult = 'drop';
72 } elseif (isset($_REQUEST['submit_mult_primary_x'])) {
73 $submit_mult = 'primary';
74 } elseif (isset($_REQUEST['submit_mult_index_x'])) {
75 $submit_mult = 'index';
76 } elseif (isset($_REQUEST['submit_mult_unique_x'])) {
77 $submit_mult = 'unique';
78 } elseif (isset($_REQUEST['submit_mult_spatial_x'])) {
79 $submit_mult = 'spatial';
80 } elseif (isset($_REQUEST['submit_mult_fulltext_x'])) {
81 $submit_mult = 'ftext';
82 } elseif (isset($_REQUEST['submit_mult_browse_x'])) {
83 $submit_mult = 'browse';
84 } elseif (isset($_REQUEST['submit_mult'])) {
85 $submit_mult = $_REQUEST['submit_mult'];
86 } elseif (isset($_REQUEST['mult_btn']) && $_REQUEST['mult_btn'] == __('Yes')) {
87 $submit_mult = 'row_delete';
88 if (isset($_REQUEST['selected'])) {
89 $_REQUEST['selected_fld'] = $_REQUEST['selected'];
92 if (! empty($submit_mult)) {
93 if (isset($_REQUEST['selected_fld'])) {
94 $err_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
95 if ($submit_mult == 'browse') {
96 // browsing the table displaying only selected columns
97 $GLOBALS['active_page'] = 'sql.php';
98 $sql_query = '';
99 foreach ($_REQUEST['selected_fld'] as $idx => $sval) {
100 if ($sql_query == '') {
101 $sql_query .= 'SELECT ' . PMA_Util::backquote($sval);
102 } else {
103 $sql_query .= ', ' . PMA_Util::backquote($sval);
106 $sql_query .= ' FROM ' . PMA_Util::backquote($db)
107 . '.' . PMA_Util::backquote($table);
109 // Parse and analyze the query
110 require_once 'libraries/parse_analyze.inc.php';
112 PMA_executeQueryAndSendQueryResponse(
113 $analyzed_sql_results, false, $db, $table, null, null, null, false, null,
114 null, null, null, $goto, $pmaThemeImage, null, null, null, $sql_query,
115 null, null
117 } else {
118 // handle multiple field commands
119 // handle confirmation of deleting multiple columns
120 $action = 'tbl_structure.php';
121 include 'libraries/mult_submits.inc.php';
123 * if $submit_mult == 'change', execution will have stopped
124 * at this point
127 if (empty($message)) {
128 $message = PMA_Message::success();
131 } else {
132 $response = PMA_Response::getInstance();
133 $response->isSuccess(false);
134 $response->addJSON('message', __('No column selected.'));
139 * Gets the relation settings
141 $cfgRelation = PMA_getRelationsParam();
144 * Runs common work
146 require_once 'libraries/tbl_common.inc.php';
147 $url_query .= '&amp;goto=tbl_structure.php&amp;back=tbl_structure.php';
148 $url_params['goto'] = 'tbl_structure.php';
149 $url_params['back'] = 'tbl_structure.php';
151 // Check column names for MySQL reserved words
152 $reserved_word_column_messages = PMA_getReservedWordColumnNameMessages($db, $table);
153 $response->addHTML($reserved_word_column_messages);
156 * Prepares the table structure display
161 * Gets tables informations
163 require_once 'libraries/tbl_info.inc.php';
165 require_once 'libraries/Index.class.php';
167 // 2. Gets table keys and retains them
168 // @todo should be: $server->db($db)->table($table)->primary()
169 $primary = PMA_Index::getPrimary($table, $db);
171 $columns_with_unique_index = PMA_getColumnsWithUniqueIndex($db, $table);
173 // 3. Get fields
174 $fields = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true);
176 // Get more complete field information
177 // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
178 // but later, if the analyser returns more information, it
179 // could be executed for any MySQL version and replace
180 // the info given by SHOW FULL COLUMNS FROM.
182 // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
183 // SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
184 // and SHOW CREATE TABLE says NOT NULL (tested
185 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
187 $show_create_table = $GLOBALS['dbi']->fetchValue(
188 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.'
189 . PMA_Util::backquote($table),
190 0, 1
192 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
195 * prepare table infos
197 // action titles (image or string)
198 $titles = PMA_getActionTitlesArray();
200 // hidden action titles (image and string)
201 $hidden_titles = PMA_getHiddenTitlesArray();
203 //display table structure
204 require_once 'libraries/display_structure.lib.php';