Use common code for CREATE/ALTER TABLE, set comments on creating table, so that user can see it in the query.
This commit is contained in:
@@ -51,54 +51,13 @@ if (isset($submit_num_fields)) {
|
||||
} // end for
|
||||
// Builds the field creation statement and alters the table
|
||||
|
||||
// TODO: check to see if this logic is exactly the same
|
||||
// as in tbl_create.php, and move to an include file
|
||||
|
||||
for ($i = 0; $i < $field_cnt; ++$i) {
|
||||
// '0' is also empty for php :-(
|
||||
if (empty($field_name[$i]) && $field_name[$i] != '0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$query .= PMA_backquote($field_name[$i]) . ' ' . $field_type[$i];
|
||||
if ($field_length[$i] != ''
|
||||
&& !preg_match('@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$@i', $field_type[$i])) {
|
||||
$query .= '(' . $field_length[$i] . ')';
|
||||
}
|
||||
if ($field_attribute[$i] != '') {
|
||||
$query .= ' ' . $field_attribute[$i];
|
||||
} else if (PMA_MYSQL_INT_VERSION >= 40100 && isset($field_collation[$i]) && $field_collation[$i] != '') {
|
||||
list($tmp_charset) = explode('_', $field_collation[$i]);
|
||||
$query .= ' CHARACTER SET ' . $tmp_charset . ' COLLATE ' . $field_collation[$i];
|
||||
unset($tmp_charset);
|
||||
}
|
||||
|
||||
if (isset($field_default_current_timestamp[$i]) && $field_default_current_timestamp[$i]) {
|
||||
$query .= ' DEFAULT CURRENT_TIMESTAMP';
|
||||
} elseif ($field_default[$i] != '') {
|
||||
if (strtoupper($field_default[$i]) == 'NULL') {
|
||||
$query .= ' DEFAULT NULL';
|
||||
} else {
|
||||
$query .= ' DEFAULT \'' . PMA_sqlAddslashes($field_default[$i]) . '\'';
|
||||
}
|
||||
}
|
||||
if ($field_null[$i] != '') {
|
||||
$query .= ' ' . $field_null[$i];
|
||||
}
|
||||
if ($field_extra[$i] != '') {
|
||||
$query .= ' ' . $field_extra[$i];
|
||||
// An auto_increment field must be use as a primary key
|
||||
if ($field_extra[$i] == 'AUTO_INCREMENT' && isset($field_primary)) {
|
||||
$primary_cnt = count($field_primary);
|
||||
for ($j = 0; $j < $primary_cnt && $field_primary[$j] != $i; $j++) {
|
||||
// void
|
||||
} // end for
|
||||
if ($field_primary[$j] == $i) {
|
||||
$query .= ' PRIMARY KEY';
|
||||
unset($field_primary[$j]);
|
||||
} // end if
|
||||
} // end if (auto_increment)
|
||||
}
|
||||
$query .= PMA_generateFieldSpec($field_name[$i], $field_type[$i], $field_length[$i], $field_attribute[$i], $field_collation[$i], $field_null[$i], $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') {
|
||||
// Only the first field can be added somewhere other than at the end
|
||||
@@ -205,13 +164,9 @@ if (isset($submit_num_fields)) {
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
// garvin: Update comment table, if a comment was set.
|
||||
// lem9: FIXME: here we take care of native comments and
|
||||
// pmadb-style comments, however, in the case of
|
||||
// native comments, users do not see the COMMENT clause
|
||||
// when SQL query is displayed
|
||||
if (isset($field_comments) && is_array($field_comments) && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) {
|
||||
if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork'] && PMA_MYSQL_INT_VERSION < 40100) {
|
||||
foreach ($field_comments AS $fieldindex => $fieldcomment) {
|
||||
PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment);
|
||||
PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment, '', 'pmadb');
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user