1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Displays table structure infos like columns, indexes, size, rows
* and allows manipulation of indexes and columns
*
* @package PhpMyAdmin
*/
/**
*
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/mysql_charsets.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('TableStructure');
/**
* Function implementations for this script
*/
require_once 'libraries/check_user_privileges.lib.php';
require_once 'libraries/structure.lib.php';
require_once 'libraries/index.lib.php';
require_once 'libraries/sql.lib.php';
require_once 'libraries/bookmark.lib.php';
$response = PMA_Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('tbl_structure.js');
$scripts->addFile('indexes.js');
/**
* Handle column moving
*/
if (isset($_REQUEST['move_columns'])
&& is_array($_REQUEST['move_columns'])
&& $response->isAjax()
) {
PMA_moveColumns($db, $table);
exit;
}
/**
* handle MySQL reserved words columns check
*/
if (isset($_REQUEST['reserved_word_check'])) {
$response = PMA_Response::getInstance();
if ($GLOBALS['cfg']['ReservedWordDisableWarning'] === false) {
$columns_names = $_REQUEST['field_name'];
$reserved_keywords_names = array();
foreach ($columns_names as $column) {
if (SqlParser\Context::isKeyword(trim($column), true)) {
$reserved_keywords_names[] = trim($column);
}
}
if (SqlParser\Context::isKeyword(trim($table), true)) {
$reserved_keywords_names[] = trim($table);
}
if (count($reserved_keywords_names) == 0) {
$response->isSuccess(false);
}
$response->addJSON(
'message', sprintf(
_ngettext(
'The name \'%s\' is a MySQL reserved keyword.',
'The names \'%s\' are MySQL reserved keywords.',
count($reserved_keywords_names)
),
implode(',', $reserved_keywords_names)
)
);
} else {
$response->isSuccess(false);
}
exit;
}
/**
* A click on Change has been made for one column
*/
if (isset($_REQUEST['change_column'])) {
PMA_displayHtmlForColumnChange($db, $table, null, 'tbl_structure.php');
exit;
}
/**
* handle multiple field commands if required
*
* submit_mult_*_x comes from IE if <input type="img" ...> is used
*/
$submit_mult = PMA_getMultipleFieldCommandType();
if (! empty($submit_mult)) {
if (isset($_REQUEST['selected_fld'])) {
if ($submit_mult == 'browse') {
// browsing the table displaying only selected columns
PMA_displayTableBrowseForSelectedColumns(
$db, $table, $goto, $pmaThemeImage
);
} else {
// handle multiple field commands
// handle confirmation of deleting multiple columns
$action = 'tbl_structure.php';
include 'libraries/mult_submits.inc.php';
/**
* if $submit_mult == 'change', execution will have stopped
* at this point
*/
if (empty($message)) {
$message = PMA_Message::success();
}
}
} else {
$response = PMA_Response::getInstance();
$response->isSuccess(false);
$response->addJSON('message', __('No column selected.'));
}
}
// display secondary level tabs if necessary
$engine = PMA_Table::sGetStatusInfo($db, $table, 'ENGINE');
$response->addHTML(PMA_getStructureSecondaryTabs($engine));
$response->addHTML('<div id="structure_content">');
/**
* Modifications have been submitted -> updates the table
*/
if (isset($_REQUEST['do_save_data'])) {
$regenerate = PMA_updateColumns($db, $table);
if ($regenerate) {
// This happens when updating failed
// @todo: do something appropriate
} else {
// continue to show the table's structure
unset($_REQUEST['selected']);
}
}
/**
* Adding indexes
*/
if (isset($_REQUEST['add_key'])) {
include 'sql.php';
$GLOBALS['reload'] = true;
}
/**
* Gets the relation settings
*/
$cfgRelation = PMA_getRelationsParam();
/**
* Runs common work
*/
require_once 'libraries/tbl_common.inc.php';
$url_query .= '&goto=tbl_structure.php&back=tbl_structure.php';
$url_params['goto'] = 'tbl_structure.php';
$url_params['back'] = 'tbl_structure.php';
/**
* Prepares the table structure display
*/
/**
* Gets tables information
*/
require_once 'libraries/tbl_info.inc.php';
require_once 'libraries/Index.class.php';
// 2. Gets table keys and retains them
// @todo should be: $server->db($db)->table($table)->primary()
$primary = PMA_Index::getPrimary($table, $db);
$columns_with_index = PMA_getColumnsWithIndex(
$db, $table,
PMA_Index::UNIQUE | PMA_Index::INDEX | PMA_Index::SPATIAL | PMA_Index::FULLTEXT
);
$columns_with_unique_index = PMA_getColumnsWithIndex($db, $table, PMA_Index::UNIQUE);
// 3. Get fields
$fields = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true);
// Get more complete field information
// For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
// but later, if the analyser returns more information, it
// could be executed for any MySQL version and replace
// the info given by SHOW FULL COLUMNS FROM.
//
// We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
// SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
// and SHOW CREATE TABLE says NOT NULL (tested
// in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
$tableObj = new PMA_Table($table, $db);
$show_create_table = $tableObj->showCreate();
$parser = new SqlParser\Parser($show_create_table);
/**
* @var CreateStatement $stmt
*/
$stmt = $parser->statements[0];
$create_table_fields = SqlParser\Utils\Table::getFields($stmt);
/**
* prepare table infos
*/
// action titles (image or string)
$titles = PMA_getActionTitlesArray();
// hidden action titles (image and string)
$hidden_titles = PMA_getHiddenTitlesArray();
//display table structure
require_once 'libraries/display_structure.inc.php';
$response->addHTML('</div>');
|