Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Mendel <cybot_tm@users.sourceforge.net>2008-05-07 16:35:00 +0400
committerSebastian Mendel <cybot_tm@users.sourceforge.net>2008-05-07 16:35:00 +0400
commit206f4add2f0bf1c331d9e2b1d7f6c06c27c90257 (patch)
tree13338ec2a3af281f6cbf551858157c0ef1af3b73 /tbl_addfield.php
parent14edea6b1a1525a10b60d0099d549445bdead52b (diff)
refactored complete table/column creation altering;
register_globals independent; fixed bug #1344768 [database] create/alter table new field can not have empty string as default; tweaked form layout to save space;
Diffstat (limited to 'tbl_addfield.php')
-rw-r--r--tbl_addfield.php237
1 files changed, 112 insertions, 125 deletions
diff --git a/tbl_addfield.php b/tbl_addfield.php
index 4316ff6c01..68a0436ce4 100644
--- a/tbl_addfield.php
+++ b/tbl_addfield.php
@@ -27,181 +27,169 @@ $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
* The form used to define the field to add has been submitted
*/
$abort = false;
-if (isset($submit_num_fields)) {
- if (isset($orig_after_field)) {
- $after_field = $orig_after_field;
+
+// check number of fields to be created
+if (isset($_REQUEST['submit_num_fields'])) {
+ if (isset($_REQUEST['orig_after_field'])) {
+ $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
}
- if (isset($orig_field_where)) {
- $field_where = $orig_field_where;
+ if (isset($_REQUEST['orig_field_where'])) {
+ $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
}
- $num_fields = $orig_num_fields + $added_fields;
- $regenerate = TRUE;
-} elseif (isset($do_save_data)) {
+ $num_fields = $_REQUEST['orig_num_fields'] + $_REQUEST['added_fields'];
+ $regenerate = true;
+} elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
+ $num_fields = (int) $_REQUEST['num_fields'];
+} else {
+ $num_fields = 1;
+}
+
+if (isset($_REQUEST['do_save_data'])) {
$query = '';
+ $definitions = array();
// Transforms the radio button field_key into 3 arrays
- $field_cnt = count($field_name);
+ $field_cnt = count($_REQUEST['field_name']);
+ $field_primary = array();
+ $field_index = array();
+ $field_unique = array();
for ($i = 0; $i < $field_cnt; ++$i) {
- if (isset(${'field_key_' . $i})) {
- if (${'field_key_' . $i} == 'primary_' . $i) {
+ if (isset($_REQUEST['field_key'][$i])
+ && strlen($_REQUEST['field_name'][$i])) {
+ if ($_REQUEST['field_key'][$i] == 'primary_' . $i) {
$field_primary[] = $i;
}
- if (${'field_key_' . $i} == 'index_' . $i) {
+ if ($_REQUEST['field_key'][$i] == 'index_' . $i) {
$field_index[] = $i;
}
- if (${'field_key_' . $i} == 'unique_' . $i) {
+ if ($_REQUEST['field_key'][$i] == 'unique_' . $i) {
$field_unique[] = $i;
}
} // end if
} // end for
+
// Builds the field creation statement and alters the table
-
for ($i = 0; $i < $field_cnt; ++$i) {
// '0' is also empty for php :-(
- if (empty($field_name[$i]) && $field_name[$i] != '0') {
+ if (empty($_REQUEST['field_name'][$i]) && $_REQUEST['field_name'][$i] != '0') {
continue;
}
- $query .= PMA_Table::generateFieldSpec($field_name[$i], $field_type[$i],
- $field_length[$i], $field_attribute[$i],
- isset($field_collation[$i]) ? $field_collation[$i] : '',
- isset($field_null[$i]) ? $field_null[$i] : 'NOT NULL',
- $field_default[$i],
- isset($field_default_current_timestamp[$i]), $field_extra[$i],
- isset($field_comments[$i]) ? $field_comments[$i] : '',
- $field_primary, $i);
-
- if ($field_where != 'last') {
+ $definition = ' ADD ' . PMA_Table::generateFieldSpec(
+ $_REQUEST['field_name'][$i],
+ $_REQUEST['field_type'][$i],
+ $_REQUEST['field_length'][$i],
+ $_REQUEST['field_attribute'][$i],
+ isset($_REQUEST['field_collation'][$i])
+ ? $_REQUEST['field_collation'][$i]
+ : '',
+ isset($_REQUEST['field_null'][$i])
+ ? $_REQUEST['field_null'][$i]
+ : 'NOT NULL',
+ $_REQUEST['field_default_type'][$i],
+ $_REQUEST['field_default_value'][$i],
+ $_REQUEST['field_extra'][$i],
+ isset($_REQUEST['field_comments'][$i])
+ ? $_REQUEST['field_comments'][$i]
+ : '',
+ $field_primary,
+ $i
+ );
+
+ if ($_REQUEST['field_where'] != 'last') {
// Only the first field can be added somewhere other than at the end
if ($i == 0) {
- if ($field_where == 'first') {
- $query .= ' FIRST';
+ if ($_REQUEST['field_where'] == 'first') {
+ $definition .= ' FIRST';
} else {
- $query .= ' AFTER ' . PMA_backquote(urldecode($after_field));
+ $definition .= ' AFTER ' . PMA_backquote($_REQUEST['after_field']);
}
} else {
- $query .= ' AFTER ' . PMA_backquote($field_name[$i-1]);
+ $definition .= ' AFTER ' . PMA_backquote($_REQUEST['field_name'][$i-1]);
}
}
- $query .= ', ADD ';
+ $definitions[] = $definition;
} // end for
- $query = preg_replace('@, ADD $@', '', $query);
+
+ // Builds the primary keys statements and updates the table
+ if (count($field_primary)) {
+ $fields = array();
+ foreach ($field_primary as $field_nr) {
+ $fields[] = $_REQUEST['field_name'][$field_nr];
+ }
+ $definitions[] = ' ADD PRIMARY KEY (' . implode(', ', $fields) . ') ';
+ }
+
+ // Builds the indexes statements and updates the table
+ if (count($field_index)) {
+ $fields = array();
+ foreach ($field_index as $field_nr) {
+ $fields[] = $_REQUEST['field_name'][$field_nr];
+ }
+ $definitions[] = ' ADD INDEX (' . implode(', ', $fields) . ') ';
+ }
+
+ // Builds the uniques statements and updates the table
+ if (count($field_unique)) {
+ $fields = array();
+ foreach ($field_unique as $field_nr) {
+ $fields[] = $_REQUEST['field_name'][$field_nr];
+ }
+ $definitions[] = ' ADD UNIQUE (' . implode(', ', $fields) . ') ';
+ }
+
+ // Builds the fulltext statements and updates the table
+ if (count($field_fulltext)) {
+ $fields = array();
+ foreach ($field_fulltext as $field_nr) {
+ $fields[] = $_REQUEST['field_name'][$field_nr];
+ }
+ $definitions[] = ' ADD FULLTEXT (' . implode(', ', $fields) . ') ';
+ }
// To allow replication, we first select the db to use and then run queries
// on this db.
PMA_DBI_select_db($db) or PMA_mysqlDie(PMA_getError(), 'USE ' . PMA_backquotes($db), '', $err_url);
- $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD ' . $query;
- $error_create = FALSE;
- PMA_DBI_try_query($sql_query) or $error_create = TRUE;
-
- if ($error_create == false) {
-
- $sql_query_cpy = $sql_query . ';';
-
- // Builds the primary keys statements and updates the table
- $primary = '';
- if (isset($field_primary)) {
- $primary_cnt = count($field_primary);
- for ($i = 0; $i < $primary_cnt; $i++) {
- $j = $field_primary[$i];
- if (isset($field_name[$j]) && strlen($field_name[$j])) {
- $primary .= PMA_backquote($field_name[$j]) . ', ';
- }
- } // end for
- $primary = preg_replace('@, $@', '', $primary);
- if (strlen($primary)) {
- $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD PRIMARY KEY (' . $primary . ');';
- $result = PMA_DBI_query($sql_query);
- $sql_query_cpy .= "\n" . $sql_query . ';';
- }
- } // end if
-
- // Builds the indexes statements and updates the table
- $index = '';
- if (isset($field_index)) {
- $index_cnt = count($field_index);
- for ($i = 0; $i < $index_cnt; $i++) {
- $j = $field_index[$i];
- if (isset($field_name[$j]) && strlen($field_name[$j])) {
- $index .= PMA_backquote($field_name[$j]) . ', ';
- }
- } // end for
- $index = preg_replace('@, $@', '', $index);
- if (strlen($index)) {
- $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX (' . $index . ')';
- $result = PMA_DBI_query($sql_query);
- $sql_query_cpy .= "\n" . $sql_query . ';';
- }
- } // end if
-
- // Builds the uniques statements and updates the table
- $unique = '';
- if (isset($field_unique)) {
- $unique_cnt = count($field_unique);
- for ($i = 0; $i < $unique_cnt; $i++) {
- $j = $field_unique[$i];
- if (isset($field_name[$j]) && strlen($field_name[$j])) {
- $unique .= PMA_backquote($field_name[$j]) . ', ';
- }
- } // end for
- $unique = preg_replace('@, $@', '', $unique);
- if (strlen($unique)) {
- $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE (' . $unique . ')';
- $result = PMA_DBI_query($sql_query);
- $sql_query_cpy .= "\n" . $sql_query . ';';
- }
- } // end if
-
-
- // Builds the fulltext statements and updates the table
- $fulltext = '';
- if (isset($field_fulltext)) {
- $fulltext_cnt = count($field_fulltext);
- for ($i = 0; $i < $fulltext_cnt; $i++) {
- $j = $field_fulltext[$i];
- $fulltext .= PMA_backquote($field_name[$j]) . ', ';
- } // end for
- $fulltext = preg_replace('@, $@', '', $fulltext);
- if (strlen($fulltext)) {
- $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT (' . $fulltext . ')';
- $result = PMA_DBI_query($sql_query);
- $sql_query_cpy .= "\n" . $sql_query . ';';
- }
- } // end if
+ $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ' . implode(', ', $definitions);
+ $result = PMA_DBI_try_query($sql_query);
+ if ($result === true) {
// garvin: If comments were sent, enable relation stuff
require_once './libraries/relation.lib.php';
require_once './libraries/transformations.lib.php';
- $cfgRelation = PMA_getRelationsParam();
-
// garvin: Update comment table for mime types [MIME]
- if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
- foreach ($field_mimetype AS $fieldindex => $mimetype) {
- if (isset($field_name[$fieldindex]) && strlen($field_name[$fieldindex])) {
- PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
+ if (isset($_REQUEST['field_mimetype'])
+ && is_array($_REQUEST['field_mimetype'])
+ && $cfg['BrowseMIME']) {
+ foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
+ if (isset($_REQUEST['field_name'][$fieldindex])
+ && strlen($_REQUEST['field_name'][$fieldindex])) {
+ PMA_setMIME($db, $table,
+ $_REQUEST['field_name'][$fieldindex],
+ $mimetype,
+ $_REQUEST['field_transformation'][$fieldindex],
+ $_REQUEST['field_transformation_options'][$fieldindex]);
}
}
}
// Go back to the structure sub-page
- $sql_query = $sql_query_cpy;
- unset($sql_query_cpy);
$message = PMA_Message::success('strTableAlteredSuccessfully');
$message->addParam($table);
$active_page = 'tbl_structure.php';
require './tbl_structure.php';
} else {
- PMA_mysqlDie('', '', '', $err_url, FALSE);
+ PMA_mysqlDie('', '', '', $err_url, false);
// garvin: An error happened while inserting/updating a table definition.
// to prevent total loss of that data, we embed the form once again.
// The variable $regenerate will be used to restore data in libraries/tbl_properties.inc.php
- $num_fields = $orig_num_fields;
- if (isset($orig_after_field)) {
- $after_field = $orig_after_field;
+ $num_fields = $_REQUEST['orig_num_fields'];
+ if (isset($_REQUEST['orig_after_field'])) {
+ $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
}
- if (isset($orig_field_where)) {
- $field_where = $orig_field_where;
+ if (isset($_REQUEST['orig_field_where'])) {
+ $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
}
$regenerate = true;
}
@@ -210,7 +198,7 @@ if (isset($submit_num_fields)) {
/**
* Displays the form used to define the new field
*/
-if ($abort == FALSE) {
+if ($abort == false) {
/**
* Gets tables informations
*/
@@ -228,7 +216,6 @@ if ($abort == FALSE) {
require_once './libraries/tbl_properties.inc.php';
// Diplays the footer
- echo "\n";
require_once './libraries/footer.inc.php';
}