Skip to content
Newer
Older
100644 233 lines (205 sloc) 7.29 KB
7ff8fed Initial revision
Olivier Müller authored May 3, 2001
1 <?php
817e790 synced/fixed vim line
Sebastian Mendel authored Mar 19, 2007
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
374abd5 fixed/added page level docblock
Sebastian Mendel authored Mar 20, 2007
3 /**
caa9844 @lem9 conform to relational terminology regarding columns and rows
lem9 authored May 31, 2010
4 * Alter one or more table columns
d7ecf57 replaced NULL/NOT NULL selectbox with checkbox (preserver space)
Sebastian Mendel authored Dec 14, 2007
5 *
6 * linked from table_structure, uses libraries/tbl_properties.inc.php to display
7 * form and handles this form data
374abd5 fixed/added page level docblock
Sebastian Mendel authored Mar 20, 2007
8 *
e56949f @nijel Use package name PhpMyAdmin
nijel authored Oct 25, 2011
9 * @package PhpMyAdmin
374abd5 fixed/added page level docblock
Sebastian Mendel authored Mar 20, 2007
10 */
7ff8fed Initial revision
Olivier Müller authored May 3, 2001
11
0ab0ad6 @lem9 merge Loic's version
lem9 authored Jul 30, 2001
12 /**
13 * Gets some core libraries
14 */
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored Mar 16, 2012
15 require_once 'libraries/common.inc.php';
fcf387b common.lib.php should REALLY REALLY and ALWAYS be the first include
Sebastian Mendel authored Nov 18, 2005
16
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored Mar 16, 2012
17 require_once 'libraries/header.inc.php';
0ab0ad6 @lem9 merge Loic's version
lem9 authored Jul 30, 2001
18
1c50bea @lem9 No longer depend on grab_globals.lib.php for $_GET variables
lem9 authored Mar 4, 2012
19 if (isset($_REQUEST['field'])) {
20 $GLOBALS['field'] = $_REQUEST['field'];
21 }
22
fc1c463 @lem9 path disclosure
lem9 authored Jul 19, 2003
23 // Check parameters
24 PMA_checkParameters(array('db', 'table'));
0ab0ad6 @lem9 merge Loic's version
lem9 authored Jul 30, 2001
25
26 /**
3f258cf @nijel Cleanup of message displaying and navigation reloading.
nijel authored Oct 21, 2004
27 * Gets tables informations
28 */
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored Mar 16, 2012
29 require_once 'libraries/tbl_common.php';
30 require_once 'libraries/tbl_info.inc.php';
3f258cf @nijel Cleanup of message displaying and navigation reloading.
nijel authored Oct 21, 2004
31
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
32 $active_page = 'tbl_structure.php';
3f258cf @nijel Cleanup of message displaying and navigation reloading.
nijel authored Oct 21, 2004
33
34 /**
e726fe7 Fixed bug #444352 (Data Missing/POST Error)
Loïc Chapeaux authored Sep 23, 2001
35 * Defines the url to return to in case of error in a sql statement
36 */
ad06b4a @nijel Rename tbl_* files to drop useless _properties part.
nijel authored Oct 25, 2006
37 $err_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
e726fe7 Fixed bug #444352 (Data Missing/POST Error)
Loïc Chapeaux authored Sep 23, 2001
38
39
40 /**
0ab0ad6 @lem9 merge Loic's version
lem9 authored Jul 30, 2001
41 * Modifications have been submitted -> updates the table
42 */
3ae253e Do not waste the data for table-field creation, if MySQL shows an error.
Garvin Hicking authored Mar 10, 2003
43 $abort = false;
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
44 if (isset($_REQUEST['do_save_data'])) {
45 $field_cnt = count($_REQUEST['field_orig']);
46 $key_fields = array();
47 $changes = array();
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
48
bbef63f Merged part 2 of patch #458014: multi-column editing
Loïc Chapeaux authored Sep 6, 2001
49 for ($i = 0; $i < $field_cnt; $i++) {
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
50 $changes[] = 'CHANGE ' . PMA_Table::generateAlter(
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
51 $_REQUEST['field_orig'][$i],
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
52 $_REQUEST['field_name'][$i],
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
53 $_REQUEST['field_type'][$i],
54 $_REQUEST['field_length'][$i],
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
55 $_REQUEST['field_attribute'][$i],
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
56 isset($_REQUEST['field_collation'][$i])
57 ? $_REQUEST['field_collation'][$i]
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
58 : '',
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
59 isset($_REQUEST['field_null'][$i])
60 ? $_REQUEST['field_null'][$i]
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
61 : 'NOT NULL',
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
62 $_REQUEST['field_default_type'][$i],
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
63 $_REQUEST['field_default_value'][$i],
a20d062 fixed NOTICE
Sebastian Mendel authored May 7, 2008
64 isset($_REQUEST['field_extra'][$i])
65 ? $_REQUEST['field_extra'][$i]
66 : false,
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
67 isset($_REQUEST['field_comments'][$i])
68 ? $_REQUEST['field_comments'][$i]
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
69 : '',
70 $key_fields,
71 $i,
72 $_REQUEST['field_default_orig'][$i]
73 );
bbef63f Merged part 2 of patch #458014: multi-column editing
Loïc Chapeaux authored Sep 6, 2001
74 } // end for
0ab0ad6 @lem9 merge Loic's version
lem9 authored Jul 30, 2001
75
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
76 // Builds the primary keys statements and updates the table
77 $key_query = '';
78 /**
79 * this is a little bit more complex
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
80 *
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
81 * @todo if someone selects A_I when altering a column we need to check:
82 * - no other column with A_I
83 * - the column has an index, if not create one
84 *
85 if (count($key_fields)) {
86 $fields = array();
87 foreach ($key_fields as $each_field) {
88 if (isset($_REQUEST['field_name'][$each_field]) && strlen($_REQUEST['field_name'][$each_field])) {
89 $fields[] = PMA_backquote($_REQUEST['field_name'][$each_field]);
90 }
91 } // end for
92 $key_query = ', ADD KEY (' . implode(', ', $fields) . ') ';
93 }
94 */
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
95
f7ef2d4 Fixed bug #548495 - Alter table not replicate
Loïc Chapeaux authored Apr 28, 2002
96 // To allow replication, we first select the db to use and then run queries
97 // on this db.
091daa3 @ruleant clarify code
ruleant authored Apr 6, 2012
98 if (! PMA_DBI_select_db($db)) {
99 PMA_mysqlDie(
100 PMA_DBI_getError(),
101 'USE ' . PMA_backquote($db) . ';',
102 '',
103 $err_url
104 );
105 }
106 $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ';
107 $sql_query .= implode(', ', $changes) . $key_query;
03cb361 @nijel Add trailing ; after ALTER TABLE (rfe #2009500)
nijel authored Apr 19, 2012
108 $sql_query .= ';';
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
109 $result = PMA_DBI_try_query($sql_query);
30b1873 Update and display column comments in Add/Edit Fieldmode and CREATE t…
Garvin Hicking authored Feb 24, 2003
110
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
111 if ($result !== false) {
76ce885 @ruleant improve coding style
ruleant authored Apr 6, 2012
112 $message = PMA_Message::success(
113 __('Table %1$s has been altered successfully')
114 );
26599a4 fixed call to PMA_Message::addParam()
Sebastian Mendel authored Oct 18, 2007
115 $message->addParam($table);
65fea8c make use of PMA_Message
Sebastian Mendel authored Oct 12, 2007
116 $btnDrop = 'Fake';
a1875b0 @derrabus Improved MySQL 4.1 support
derrabus authored Jun 7, 2003
117
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
118 /**
119 * If comments were sent, enable relation stuff
120 */
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored Mar 16, 2012
121 include_once 'libraries/transformations.lib.php';
a1875b0 @derrabus Improved MySQL 4.1 support
derrabus authored Jun 7, 2003
122
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
123 // updaet field names in relation
124 if (isset($_REQUEST['field_orig']) && is_array($_REQUEST['field_orig'])) {
125 foreach ($_REQUEST['field_orig'] as $fieldindex => $fieldcontent) {
126 if ($_REQUEST['field_name'][$fieldindex] != $fieldcontent) {
76ce885 @ruleant improve coding style
ruleant authored Apr 6, 2012
127 PMA_REL_renameField(
128 $db, $table, $fieldcontent,
129 $_REQUEST['field_name'][$fieldindex]
130 );
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
131 }
132 }
133 }
134
135 // update mime types
136 if (isset($_REQUEST['field_mimetype'])
4b8d52d @madhuracj Fix CheckStyle warnings, Type:CloseBracketNewLine (Closing parenthesi…
madhuracj authored Apr 22, 2012
137 && is_array($_REQUEST['field_mimetype'])
138 && $cfg['BrowseMIME']
139 ) {
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
140 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
141 if (isset($_REQUEST['field_name'][$fieldindex])
76ce885 @ruleant improve coding style
ruleant authored Apr 6, 2012
142 && strlen($_REQUEST['field_name'][$fieldindex])
143 ) {
144 PMA_setMIME(
145 $db, $table, $_REQUEST['field_name'][$fieldindex],
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
146 $mimetype,
147 $_REQUEST['field_transformation'][$fieldindex],
76ce885 @ruleant improve coding style
ruleant authored Apr 6, 2012
148 $_REQUEST['field_transformation_options'][$fieldindex]
149 );
db21962 @nijel Do not try to set comment and MIME transformation if field not named.
nijel authored Oct 8, 2005
150 }
3ae253e Do not waste the data for table-field creation, if MySQL shows an error.
Garvin Hicking authored Mar 10, 2003
151 }
152 }
a1875b0 @derrabus Improved MySQL 4.1 support
derrabus authored Jun 7, 2003
153
66fbb2d @lgtkaushalya Fixed the bugs in table copy of table operations
lgtkaushalya authored Jul 31, 2011
154 if ( $_REQUEST['ajax_request'] == true) {
13adb5a @madhuracj Use lower case for true, false and null
madhuracj authored Sep 23, 2011
155 $extra_data['sql_query'] = PMA_showMessage(null, $sql_query);
66fbb2d @lgtkaushalya Fixed the bugs in table copy of table operations
lgtkaushalya authored Jul 31, 2011
156 PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
23c8cf4 This page can now handle ajax requests
ninadsp authored Jul 22, 2010
157 }
158
ad06b4a @nijel Rename tbl_* files to drop useless _properties part.
nijel authored Oct 25, 2006
159 $active_page = 'tbl_structure.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored Mar 16, 2012
160 include 'tbl_structure.php';
3ae253e Do not waste the data for table-field creation, if MySQL shows an error.
Garvin Hicking authored Mar 10, 2003
161 } else {
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
162 PMA_mysqlDie('', '', '', $err_url, false);
9785bbc @lem9 remove author names
lem9 authored Mar 26, 2010
163 // An error happened while inserting/updating a table definition.
3ae253e Do not waste the data for table-field creation, if MySQL shows an error.
Garvin Hicking authored Mar 10, 2003
164 // to prevent total loss of that data, we embed the form once again.
c40b663 @nijel Move tbl_properties{.inc,_links,_table_info}.php to libraries folder …
nijel authored Nov 24, 2005
165 // The variable $regenerate will be used to restore data in libraries/tbl_properties.inc.php
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
166 if (isset($_REQUEST['orig_field'])) {
167 $_REQUEST['field'] = $_REQUEST['orig_field'];
dba8ecc Display MIME types to transform any table cell. You can only choose f…
Garvin Hicking authored Feb 24, 2003
168 }
169
3ae253e Do not waste the data for table-field creation, if MySQL shows an error.
Garvin Hicking authored Mar 10, 2003
170 $regenerate = true;
171 }
7ff8fed Initial revision
Olivier Müller authored May 3, 2001
172 }
0ab0ad6 @lem9 merge Loic's version
lem9 authored Jul 30, 2001
173
174 /**
175 * No modifications yet required -> displays the table fields
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
176 *
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
177 * $selected comes from multi_submits.inc.php
0ab0ad6 @lem9 merge Loic's version
lem9 authored Jul 30, 2001
178 */
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
179 if ($abort == false) {
4130b9b Fix PHP notices
Jo Michael authored Apr 9, 2012
180 if (!isset($_REQUEST['ajax_request']) || $_REQUEST['ajax_request'] != true) {
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored Mar 16, 2012
181 include_once 'libraries/tbl_links.inc.php';
f607d8a @roccivic table structure: Do not send #topmenucontainer in ajax requests
roccivic authored Oct 31, 2011
182 }
f2ebfe1 @nijel Show links only when editing
nijel authored Feb 2, 2011
183
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
184 if (! isset($selected)) {
fc1c463 @lem9 path disclosure
lem9 authored Jul 19, 2003
185 PMA_checkParameters(array('field'));
206f4ad refactored complete table/column creation altering;
Sebastian Mendel authored May 7, 2008
186 $selected[] = $_REQUEST['field'];
bbef63f Merged part 2 of patch #458014: multi-column editing
Loïc Chapeaux authored Sep 6, 2001
187 $selected_cnt = 1;
518aca0 Fixed bug #543365 - Can't change field properties when name contains …
Loïc Chapeaux authored Apr 13, 2002
188 } else { // from a multiple submit
bbef63f Merged part 2 of patch #458014: multi-column editing
Loïc Chapeaux authored Sep 6, 2001
189 $selected_cnt = count($selected);
0ab0ad6 @lem9 merge Loic's version
lem9 authored Jul 30, 2001
190 }
bbef63f Merged part 2 of patch #458014: multi-column editing
Loïc Chapeaux authored Sep 6, 2001
191
1eadc0a use @todo tag for todo items, to show up in generated documentation
Sebastian Mendel authored Sep 21, 2006
192 /**
193 * @todo optimize in case of multiple fields to modify
194 */
bbef63f Merged part 2 of patch #458014: multi-column editing
Loïc Chapeaux authored Sep 6, 2001
195 for ($i = 0; $i < $selected_cnt; $i++) {
be6e210 @Crack Use new PMA_DBI_get_columns in column alter form
Crack authored Jun 28, 2011
196 $fields_meta[] = PMA_DBI_get_columns($db, $table, $selected[$i], true);
bbef63f Merged part 2 of patch #458014: multi-column editing
Loïc Chapeaux authored Sep 6, 2001
197 }
198 $num_fields = count($fields_meta);
6884f97 @nijel no more support for php3
nijel authored Nov 18, 2003
199 $action = 'tbl_alter.php';
b8b9334 @lem9 experimental support in table structure editing for MySQL 4.1.2+ TIME…
lem9 authored Mar 16, 2005
200
ad48d9f @lem9 bug #2895894 [structure] Empty default value not set properly
lem9 authored Nov 13, 2009
201 // Get more complete field information.
202 // For now, this is done to obtain MySQL 4.1.2+ new TIMESTAMP options
203 // and to know when there is an empty DEFAULT value.
204 // Later, if the analyser returns more information, it
12f70e8 @Crack Replace all SHOW FIELDS calls with PMA_DBI_get_columns() or PMA_DBI_g…
Crack authored Jun 17, 2011
205 // could be executed to replace the info given by SHOW FULL COLUMNS FROM.
1eadc0a use @todo tag for todo items, to show up in generated documentation
Sebastian Mendel authored Sep 21, 2006
206 /**
207 * @todo put this code into a require()
18c6832 @lem9 Comment adjusted to reflect a previous change of function name
lem9 authored Jan 2, 2012
208 * or maybe make it part of PMA_DBI_get_columns();
1eadc0a use @todo tag for todo items, to show up in generated documentation
Sebastian Mendel authored Sep 21, 2006
209 */
b8b9334 @lem9 experimental support in table structure editing for MySQL 4.1.2+ TIME…
lem9 authored Mar 16, 2005
210
ad48d9f @lem9 bug #2895894 [structure] Empty default value not set properly
lem9 authored Nov 13, 2009
211 // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
12f70e8 @Crack Replace all SHOW FIELDS calls with PMA_DBI_get_columns() or PMA_DBI_g…
Crack authored Jun 16, 2011
212 // SHOW FULL COLUMNS says NULL and SHOW CREATE TABLE says NOT NULL (tested
ad48d9f @lem9 bug #2895894 [structure] Empty default value not set properly
lem9 authored Nov 13, 2009
213 // in MySQL 4.0.25).
b8b9334 @lem9 experimental support in table structure editing for MySQL 4.1.2+ TIME…
lem9 authored Mar 16, 2005
214
76ce885 @ruleant improve coding style
ruleant authored Apr 6, 2012
215 $show_create_table = PMA_DBI_fetch_value(
216 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
217 0, 1
218 );
ad48d9f @lem9 bug #2895894 [structure] Empty default value not set properly
lem9 authored Nov 13, 2009
219 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
220 unset($show_create_table);
37315b0 @nijel Document some require/includes as phpdoc otherwise takes random block…
nijel authored Nov 24, 2008
221 /**
222 * Form for changing properties.
223 */
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored Mar 16, 2012
224 include 'libraries/tbl_properties.inc.php';
7ff8fed Initial revision
Olivier Müller authored May 3, 2001
225 }
226
0ab0ad6 @lem9 merge Loic's version
lem9 authored Jul 30, 2001
227
228 /**
229 * Displays the footer
230 */
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored Mar 16, 2012
231 require 'libraries/footer.inc.php';
37d50c1 @derrabus Huge set of optimizations, please test!
derrabus authored Nov 26, 2003
232 ?>
Something went wrong with that request. Please try again.