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;
This commit is contained in:
Sebastian Mendel
2008-05-07 12:35:00 +00:00
parent 14edea6b1a
commit 206f4add2f
7 changed files with 526 additions and 494 deletions

View File

@@ -33,6 +33,8 @@ danbarry
- bug #1845605 [i18n] translators.html still uses iso-8859-1 - bug #1845605 [i18n] translators.html still uses iso-8859-1
- bug #1823018 [charset] Edit(Delete) img-links pointing to wrong row - bug #1823018 [charset] Edit(Delete) img-links pointing to wrong row
- bug #1826205 [export] Problems with yaml text export - bug #1826205 [export] Problems with yaml text export
- bug #1344768 [database] create/alter table new field can not have empty string
as default
+ rfe #1840165 [interface] Enlarge column name field in vertical mode + rfe #1840165 [interface] Enlarge column name field in vertical mode
+ patch #1847534 [interface] New "Inside field" in db search, + patch #1847534 [interface] New "Inside field" in db search,
thanks to obiserver thanks to obiserver
@@ -63,6 +65,7 @@ danbarry
- bug #1955386 [session] Overriding session.hash_bits_per_character - bug #1955386 [session] Overriding session.hash_bits_per_character
- [interface] sanitize the table comments in table print view, - [interface] sanitize the table comments in table print view,
thanks to Norman Hippert thanks to Norman Hippert
- bug #1939031 Auto_Increment selected for TimeStamp by Default
- bug #1910621 [display] part 2: do not display a BINARY content as text - bug #1910621 [display] part 2: do not display a BINARY content as text
2.11.6.0 (2008-04-29) 2.11.6.0 (2008-04-29)

View File

@@ -259,27 +259,23 @@ class PMA_Table {
* @param string $attribute * @param string $attribute
* @param string $collation * @param string $collation
* @param string $null with 'NULL' or 'NOT NULL' * @param string $null with 'NULL' or 'NOT NULL'
* @param string $default default value * @param string $default_type whether default is CURRENT_TIMESTAMP,
* @param boolean $default_current_timestamp whether default value is * NULL, NONE, USER_DEFINED
* CURRENT_TIMESTAMP or not * @param boolean $default_value default value for USER_DEFINED default type
* this overrides $default value
* @param string $extra 'AUTO_INCREMENT' * @param string $extra 'AUTO_INCREMENT'
* @param string $comment field comment * @param string $comment field comment
* @param array &$field_primary list of fields for PRIMARY KEY * @param array &$field_primary list of fields for PRIMARY KEY
* @param string $index * @param string $index
* @param string $default_orig
* @return string field specification * @return string field specification
*/ */
static function generateFieldSpec($name, $type, $length = '', $attribute = '', static function generateFieldSpec($name, $type, $length = '', $attribute = '',
$collation = '', $null = false, $default = '', $collation = '', $null = false, $default_type = 'USER_DEFINED',
$default_current_timestamp = false, $extra = '', $comment = '', $default_value = '', $extra = '', $comment = '',
&$field_primary, $index, $default_orig = false) &$field_primary, $index, $default_orig = false)
{ {
$is_timestamp = strpos(' ' . strtoupper($type), 'TIMESTAMP') == 1; $is_timestamp = strpos(' ' . strtoupper($type), 'TIMESTAMP') == 1;
// $default_current_timestamp has priority over $default
/** /**
* @todo include db-name * @todo include db-name
*/ */
@@ -307,22 +303,25 @@ class PMA_Table {
} }
} }
if ($default_current_timestamp && $is_timestamp) { switch ($default_type) {
$query .= ' DEFAULT CURRENT_TIMESTAMP'; case 'USER_DEFINED' :
// auto_increment field cannot have a default value if ($is_timestamp && $default_value === '0') {
} elseif ($extra !== 'AUTO_INCREMENT'
&& $default !== false) {
if (strtoupper($default) == 'NULL') {
$query .= ' DEFAULT NULL';
} elseif ($is_timestamp && $default === '0') {
// a TIMESTAMP does not accept DEFAULT '0' // a TIMESTAMP does not accept DEFAULT '0'
// but DEFAULT 0 works // but DEFAULT 0 works
$query .= ' DEFAULT ' . PMA_sqlAddslashes($default); $query .= ' DEFAULT 0';
} elseif ($type == 'BIT') { } elseif ($type == 'BIT') {
$query .= ' DEFAULT b\'' . preg_replace('/[^01]/', '0', $default) . '\''; $query .= ' DEFAULT b\'' . preg_replace('/[^01]/', '0', $default_value) . '\'';
} else { } else {
$query .= ' DEFAULT \'' . PMA_sqlAddslashes($default) . '\''; $query .= ' DEFAULT \'' . PMA_sqlAddslashes($default_value) . '\'';
} }
break;
case 'NULL' :
case 'CURRENT_TIMESTAMP' :
$query .= ' DEFAULT ' . $default_type;
break;
case 'NONE' :
default :
break;
} }
if (!empty($extra)) { if (!empty($extra)) {
@@ -440,15 +439,15 @@ class PMA_Table {
} // end of the 'PMA_Table::countRecords()' function } // end of the 'PMA_Table::countRecords()' function
/** /**
* @todo add documentation * @see PMA_Table::generateFieldSpec()
*/ */
static public function generateAlter($oldcol, $newcol, $type, $length, static public function generateAlter($oldcol, $newcol, $type, $length,
$attribute, $collation, $null, $default, $default_current_timestamp, $attribute, $collation, $null, $default_type, $default_value,
$extra, $comment = '', &$field_primary, $index, $default_orig) $extra, $comment = '', &$field_primary, $index, $default_orig)
{ {
return PMA_backquote($oldcol) . ' ' return PMA_backquote($oldcol) . ' '
. PMA_Table::generateFieldSpec($newcol, $type, $length, $attribute, . PMA_Table::generateFieldSpec($newcol, $type, $length, $attribute,
$collation, $null, $default, $default_current_timestamp, $extra, $collation, $null, $default_type, $default_value, $extra,
$comment, $field_primary, $index, $default_orig); $comment, $field_primary, $index, $default_orig);
} // end function } // end function

View File

@@ -1,8 +1,9 @@
<?php <?php
/* vim: set expandtab sw=4 ts=4 sts=4: */ /* vim: set expandtab sw=4 ts=4 sts=4: */
/** /**
* Display form for changing/adding table field/columns * Display form for changing/adding table fields/columns
* *
* included by tbl_addfield.php, -_alter.php, -_create.php
* @version $Id$ * @version $Id$
*/ */
@@ -40,20 +41,20 @@ $_form_params = array(
if ($action == 'tbl_create.php') { if ($action == 'tbl_create.php') {
$_form_params['reload'] = 1; $_form_params['reload'] = 1;
} elseif ($action == 'tbl_addfield.php') { } elseif ($action == 'tbl_addfield.php') {
$_form_params['field_where'] = $field_where; $_form_params['field_where'] = $_REQUEST['field_where'];
$_form_params['after_field'] = $after_field; $_form_params['after_field'] = $_REQUEST['after_field'];
} }
if (isset($num_fields)) { if (isset($num_fields)) {
$_form_params['orig_num_fields'] = $num_fields; $_form_params['orig_num_fields'] = $num_fields;
} }
if (isset($field_where)) { if (isset($_REQUEST['field_where'])) {
$_form_params['orig_field_where'] = $field_where; $_form_params['orig_field_where'] = $_REQUEST['field_where'];
} }
if (isset($after_field)) { if (isset($_REQUEST['after_field'])) {
$_form_params['orig_after_field'] = $after_field; $_form_params['orig_after_field'] = $_REQUEST['after_field'];
} }
if (isset($selected) && is_array($selected)) { if (isset($selected) && is_array($selected)) {
@@ -69,12 +70,12 @@ if (isset($selected) && is_array($selected)) {
$_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val; $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
} }
} }
} elseif (isset($field)) { } elseif (isset($_REQUEST['field'])) {
$_form_params['orig_field'] = $field; $_form_params['orig_field'] = $_REQUEST['field'];
if (isset($orig_field)) { if (isset($orig_field)) {
$_form_params['true_selected[]'] = $orig_field; $_form_params['true_selected[]'] = $orig_field;
} else { } else {
$_form_params['true_selected[]'] = $field; $_form_params['true_selected[]'] = $_REQUEST['field'];
} }
} }
@@ -84,28 +85,27 @@ $header_cells = array();
$content_cells = array(); $content_cells = array();
$header_cells[] = $strField; $header_cells[] = $strField;
$header_cells[] = $strType . ($GLOBALS['cfg']['ReplaceHelpImg'] ? PMA_showMySQLDocu('SQL-Syntax', 'data-types') : '<br /><span style="font-weight: normal">' . PMA_showMySQLDocu('SQL-Syntax', 'data-types') . '</span>'); $header_cells[] = $strType
. ($GLOBALS['cfg']['ReplaceHelpImg']
? PMA_showMySQLDocu('SQL-Syntax', 'data-types')
: '<br /><span style="font-weight: normal">' . PMA_showMySQLDocu('SQL-Syntax', 'data-types')
. '</span>');
$header_cells[] = $strLengthSet . PMA_showHint($strSetEnumVal); $header_cells[] = $strLengthSet . PMA_showHint($strSetEnumVal);
$header_cells[] = $strDefault . PMA_showHint($strDefaultValueHelp);
$header_cells[] = $strCollation; $header_cells[] = $strCollation;
$header_cells[] = $strAttr; $header_cells[] = $strAttr;
$header_cells[] = $strNull; $header_cells[] = $strNull;
$header_cells[] = $strDefault . PMA_showHint($strDefaultValueHelp);
$header_cells[] = $strExtra;
// lem9: We could remove this 'if' and let the key information be shown and // lem9: We could remove this 'if' and let the key information be shown and
// editable. However, for this to work, tbl_alter must be modified to use the // editable. However, for this to work, tbl_alter must be modified to use the
// key fields, as tbl_addfield does. // key fields, as tbl_addfield does.
if (!$is_backup) { if (!$is_backup) {
$header_cells[] = $cfg['PropertiesIconic'] ? '<img class="icon" src="' . $pmaThemeImage . 'b_primary.png" width="16" height="16" alt="' . $strPrimary . '" title="' . $strPrimary . '" />' : $strPrimary; $header_cells[] = $strIndex;
$header_cells[] = $cfg['PropertiesIconic'] ? '<img class="icon" src="' . $pmaThemeImage . 'b_index.png" width="16" height="16" alt="' . $strIndex . '" title="' . $strIndex . '" />' : $strIndex;
$header_cells[] = $cfg['PropertiesIconic'] ? '<img class="icon" src="' . $pmaThemeImage . 'b_unique.png" width="16" height="16" alt="' . $strUnique . '" title="' . $strUnique . '" />' : $strUnique;
$header_cells[] = '---';
$header_cells[] = $cfg['PropertiesIconic'] ? '<img class="icon" src="' . $pmaThemeImage . 'b_ftext.png" width="16" height="16" alt="' . $strIdxFulltext . '" title="' . $strIdxFulltext . '" />' : $strIdxFulltext;
} }
$header_cells[] = '<abbr title="AUTO_INCREMENT">A_I</abbr>';
require_once './libraries/relation.lib.php'; require_once './libraries/relation.lib.php';
require_once './libraries/transformations.lib.php'; require_once './libraries/transformations.lib.php';
$cfgRelation = PMA_getRelationsParam(); $cfgRelation = PMA_getRelationsParam();
@@ -130,91 +130,138 @@ if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
$header_cells[] = $strMIME_MIMEtype; $header_cells[] = $strMIME_MIMEtype;
$header_cells[] = $strMIME_transformation; $header_cells[] = $strMIME_transformation;
$header_cells[] = $strMIME_transformation_options . PMA_showHint($strMIME_transformation_options_note . $hint); $header_cells[] = $strMIME_transformation_options
. PMA_showHint($strMIME_transformation_options_note . $hint);
} }
// garvin: workaround for field_fulltext, because its submitted indizes contain // garvin: workaround for field_fulltext, because its submitted indizes contain
// the index as a value, not a key. Inserted here for easier maintaineance // the index as a value, not a key. Inserted here for easier maintaineance
// and less code to change in existing files. // and less code to change in existing files.
if (isset($field_fulltext) && is_array($field_fulltext)) { if (isset($field_fulltext) && is_array($field_fulltext)) {
foreach ($field_fulltext AS $fulltext_nr => $fulltext_indexkey) { foreach ($field_fulltext as $fulltext_nr => $fulltext_indexkey) {
$submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey; $submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey;
} }
} }
for ($i = 0; $i <= $num_fields; $i++) { for ($i = 0; $i < $num_fields; $i++) {
if (! empty($regenerate)) { if (! empty($regenerate)) {
// An error happened with previous inputs, so we will restore the data // An error happened with previous inputs, so we will restore the data
// to embed it once again in this form. // to embed it once again in this form.
$row['Field'] = (isset($field_name[$i]) ? $field_name[$i] : FALSE); $row['Field'] = (isset($_REQUEST['field_name'][$i]) ? $_REQUEST['field_name'][$i] : false);
$row['Type'] = (isset($field_type[$i]) ? $field_type[$i] : FALSE); $row['Type'] = (isset($_REQUEST['field_type'][$i]) ? $_REQUEST['field_type'][$i] : false);
$row['Collation'] = (isset($field_collation[$i]) ? $field_collation[$i] : ''); $row['Collation'] = (isset($_REQUEST['field_collation'][$i]) ? $_REQUEST['field_collation'][$i] : '');
$row['Null'] = (isset($field_null[$i]) ? $field_null[$i] : ''); $row['Null'] = (isset($_REQUEST['field_null'][$i]) ? $_REQUEST['field_null'][$i] : '');
if (isset(${'field_key_' . $i}) && ${'field_key_' . $i} == 'primary_' . $i) { if (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'primary_' . $i) {
$row['Key'] = 'PRI'; $row['Key'] = 'PRI';
} elseif (isset(${'field_key_' . $i}) && ${'field_key_' . $i} == 'index_' . $i) { } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'index_' . $i) {
$row['Key'] = 'MUL'; $row['Key'] = 'MUL';
} elseif (isset(${'field_key_' . $i}) && ${'field_key_' . $i} == 'unique_' . $i) { } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'unique_' . $i) {
$row['Key'] = 'UNI'; $row['Key'] = 'UNI';
} elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'fulltext_' . $i) {
$row['Key'] = 'FULLTEXT';
} else { } else {
$row['Key'] = ''; $row['Key'] = '';
} }
$row['Default'] = (isset($field_default[$i]) ? $field_default[$i] : FALSE); $row['DefaultType'] = (isset($_REQUEST['field_default_type'][$i]) ? $_REQUEST['field_default_type'][$i] : 'USER_DEFINED');
$row['Extra'] = (isset($field_extra[$i]) ? $field_extra[$i] : FALSE); $row['DefaultValue'] = (isset($_REQUEST['field_default_value'][$i]) ? $_REQUEST['field_default_value'][$i] : '');
$row['Comment'] = (isset($submit_fulltext[$i]) && ($submit_fulltext[$i] == $i) ? 'FULLTEXT' : FALSE);
$submit_length = (isset($field_length[$i]) ? $field_length[$i] : FALSE); switch ($row['DefaultType']) {
$submit_attribute = (isset($field_attribute[$i]) ? $field_attribute[$i] : FALSE); case 'NONE' :
$row['Default'] = null;
$submit_default_current_timestamp = (isset($field_default_current_timestamp[$i]) ? TRUE : FALSE); break;
case 'USER_DEFINED' :
if (isset($field_comments[$i])) { $row['Default'] = $row['DefaultValue'];
$comments_map[$row['Field']] = $field_comments[$i]; break;
case 'NULL' :
case 'CURRENT_TIMESTAMP' :
$row['Default'] = $row['DefaultType'];
break;
} }
if (isset($field_mimetype[$i])) { $row['Extra'] = (isset($_REQUEST['field_extra'][$i]) ? $_REQUEST['field_extra'][$i] : false);
$mime_map[$row['Field']]['mimetype'] = $field_mimetype[$i]; $row['Comment'] = (isset($submit_fulltext[$i]) && ($submit_fulltext[$i] == $i) ? 'FULLTEXT' : false);
$submit_length = (isset($_REQUEST['field_length'][$i]) ? $_REQUEST['field_length'][$i] : false);
$submit_attribute = (isset($_REQUEST['field_attribute'][$i]) ? $_REQUEST['field_attribute'][$i] : false);
$submit_default_current_timestamp = (isset($_REQUEST['field_default_current_timestamp'][$i]) ? true : false);
if (isset($_REQUEST['field_comments'][$i])) {
$comments_map[$row['Field']] = $_REQUEST['field_comments'][$i];
} }
if (isset($field_transformation[$i])) { if (isset($_REQUEST['field_mimetype'][$i])) {
$mime_map[$row['Field']]['transformation'] = $field_transformation[$i]; $mime_map[$row['Field']]['mimetype'] = $_REQUEST['field_mimetype'][$i];
} }
if (isset($field_transformation_options[$i])) { if (isset($_REQUEST['field_transformation'][$i])) {
$mime_map[$row['Field']]['transformation_options'] = $field_transformation_options[$i]; $mime_map[$row['Field']]['transformation'] = $_REQUEST['field_transformation'][$i];
}
if (isset($_REQUEST['field_transformation_options'][$i])) {
$mime_map[$row['Field']]['transformation_options'] = $_REQUEST['field_transformation_options'][$i];
} }
} elseif (isset($fields_meta[$i])) { } elseif (isset($fields_meta[$i])) {
$row = $fields_meta[$i]; $row = $fields_meta[$i];
switch ($row['Default']) {
case null:
if ($row['Null'] == 'YES') {
$row['DefaultType'] = 'NULL';
} else {
$row['DefaultType'] = 'NONE';
}
$row['DefaultValue'] = '';
break;
case 'CURRENT_TIMESTAMP':
$row['DefaultType'] = 'CURRENT_TIMESTAMP';
$row['DefaultValue'] = '';
break;
default:
$row['DefaultType'] = 'USER_DEFINED';
$row['DefaultValue'] = $row['Default'];
break;
}
} }
if (isset($row) && isset($row['Type'])) { if (isset($row['Type'])) {
$type_and_length = PMA_extract_type_length($row['Type']); $type_and_length = PMA_extract_type_length($row['Type']);
if ($type_and_length['type'] == 'bit') { if ($type_and_length['type'] == 'bit') {
$row['Default'] = PMA_printable_bit_value($row['Default'], $type_and_length['length']); $row['Default'] = PMA_printable_bit_value($row['Default'], $type_and_length['length']);
} }
} }
// Cell index: If certain fields get left out, the counter shouldn't chage. // Cell index: If certain fields get left out, the counter shouldn't change.
$ci = 0; $ci = 0;
// Everytime a cell shall be left out the STRG-jumping feature, $ci_offset // Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
// has to be incremented ($ci_offset++) // has to be incremented ($ci_offset++)
$ci_offset = -1; $ci_offset = -1;
// old column name
if ($is_backup) { if ($is_backup) {
$backup_field = (isset($true_selected) && isset($true_selected[$i]) && $true_selected[$i] ? $true_selected[$i] : (isset($row) && isset($row['Field']) ? urlencode($row['Field']) : '')); if (! empty($true_selected[$i])) {
$content_cells[$i][$ci] = "\n" . '<input type="hidden" name="field_orig[]" value="' . $backup_field . '" />' . "\n"; $_form_params['field_orig[' . $i . ']'] = $true_selected[$i];
} elseif (isset($row['Field'])) {
$_form_params['field_orig[' . $i . ']'] = $row['Field'];
} else { } else {
$content_cells[$i][$ci] = ''; $_form_params['field_orig[' . $i . ']'] = '';
}
} }
$content_cells[$i][$ci] .= "\n" . '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '" type="text" name="field_name[' . $i . ']" size="' . ($GLOBALS['cfg']['DefaultPropDisplay'] == 'horizontal' ? '10' : '30') . '" maxlength="64" value="' . (isset($row) && isset($row['Field']) ? str_replace('"', '&quot;', $row['Field']) : '') . '" class="textfield" title="' . $strField . '" />'; // column name
$content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
. ' type="text" name="field_name[' . $i . ']"'
. ' maxlength="64" class="textfield" title="' . $strField . '"'
. ' size="' . ($GLOBALS['cfg']['DefaultPropDisplay'] == 'horizontal' ? '10' : '30') . '"'
. ' value="' . (isset($row['Field']) ? htmlspecialchars($row['Field']) : '') . '"'
. ' />';
$ci++; $ci++;
$content_cells[$i][$ci] = '<select name="field_type[' . $i . ']" id="field_' . $i . '_' . ($ci - $ci_offset) . '" ';
$content_cells[$i][$ci] .= 'onchange="display_field_options(this.options[this.selectedIndex].value,' . $i .')" '; // column type
$content_cells[$i][$ci] .= '>' . "\n"; $content_cells[$i][$ci] = '<select name="field_type[' . $i . ']"'
.' id="field_' . $i . '_' . ($ci - $ci_offset) . '" >';
if (empty($row['Type'])) { if (empty($row['Type'])) {
$row['Type'] = ''; $row['Type'] = '';
@@ -247,7 +294,7 @@ for ($i = 0; $i <= $num_fields; $i++) {
$type = substr($type, 0, $tmp - 1); $type = substr($type, 0, $tmp - 1);
} }
if (isset($submit_length) && $submit_length != FALSE) { if (isset($submit_length) && $submit_length != false) {
$length = $submit_length; $length = $submit_length;
} }
@@ -263,7 +310,7 @@ for ($i = 0; $i <= $num_fields; $i++) {
if ($type_upper == strtoupper($col_group_type)) { if ($type_upper == strtoupper($col_group_type)) {
$content_cells[$i][$ci] .= ' selected="selected"'; $content_cells[$i][$ci] .= ' selected="selected"';
} }
$content_cells[$i][$ci] .= '>' . $col_group_type . '</option>' . "\n"; $content_cells[$i][$ci] .= '>' . $col_group_type . '</option>';
} }
$content_cells[$i][$ci] .= '</optgroup>'; $content_cells[$i][$ci] .= '</optgroup>';
continue; continue;
@@ -273,18 +320,18 @@ for ($i = 0; $i <= $num_fields; $i++) {
if ($type_upper == strtoupper($column_type)) { if ($type_upper == strtoupper($column_type)) {
$content_cells[$i][$ci] .= ' selected="selected"'; $content_cells[$i][$ci] .= ' selected="selected"';
} }
$content_cells[$i][$ci] .= '>' . $column_type . '</option>' . "\n"; $content_cells[$i][$ci] .= '>' . $column_type . '</option>';
} // end for } // end for
$content_cells[$i][$ci] .= ' </select>'; $content_cells[$i][$ci] .= ' </select>';
$ci++; $ci++;
// old column length
if ($is_backup) { if ($is_backup) {
$content_cells[$i][$ci] = "\n" . '<input type="hidden" name="field_length_orig[' . $i . ']" value="' . urlencode($length) . '" />'; $_form_params['field_length_orig[' . $i . ']'] = $length;
} else {
$content_cells[$i][$ci] = '';
} }
// column length
if (preg_match('@^(set|enum)$@i', $type)) { if (preg_match('@^(set|enum)$@i', $type)) {
$binary = 0; $binary = 0;
$unsigned = 0; $unsigned = 0;
@@ -292,20 +339,75 @@ for ($i = 0; $i <= $num_fields; $i++) {
$length_to_display = htmlspecialchars($length); $length_to_display = htmlspecialchars($length);
} else { } else {
$length_to_display = $length; $length_to_display = $length;
$binary = FALSE; $binary = false;
$unsigned = stristr($row['Type'], 'unsigned'); $unsigned = stristr($row['Type'], 'unsigned');
$zerofill = stristr($row['Type'], 'zerofill'); $zerofill = stristr($row['Type'], 'zerofill');
} }
$content_cells[$i][$ci] .= "\n" . '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '" type="text" name="field_length[' . $i . ']" size="8" value="' . str_replace('"', '&quot;', $length_to_display) . '" class="textfield" />' . "\n"; $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
. ' type="text" name="field_length[' . $i . ']" size="8"'
. ' value="' . htmlspecialchars($length_to_display) . '"'
. ' class="textfield" />';
$ci++; $ci++;
// column default
/**
* having NULL enabled does not implicit having Default with NULL
*
if (isset($row)
&& !isset($row['Default']) && isset($row['Null']) && $row['Null'] == 'YES') {
$row['Default'] = 'NULL';
}
*/
// old column default
if ($is_backup) {
$_form_params['field_default_orig[' . $i . ']'] =
(isset($row['Default']) ? $row['Default'] : '');
}
$default_options = array(
'USER_DEFINED' => 'strUserDefined',
'NONE' => $strNone,
'NULL' => 'NULL',
'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
);
// for a TIMESTAMP, do not show CURRENT_TIMESTAMP as a default value
if ($type_upper == 'TIMESTAMP'
&& $default_current_timestamp
&& isset($row['Default'])) {
$row['Default'] = '';
}
$content_cells[$i][$ci] = '<select name="field_default_type[' . $i . ']">';
foreach ($default_options as $key => $value) {
$content_cells[$i][$ci] .= '<option value="' . $key . '"';
if (($row['DefaultType']) == $key) {
$content_cells[$i][$ci] .= ' selected="selected"';
}
$content_cells[$i][$ci] .= ' >' . $value . '</option>';
}
$content_cells[$i][$ci] .= '</select>';
$content_cells[$i][$ci] .= '<br />';
$content_cells[$i][$ci] .= '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
. ' type="text" name="field_default_value[' . $i . ']" size="12"'
. ' value="' . (isset($row['DefaultValue']) ? htmlspecialchars($row['DefaultValue']) : '') . '"'
. ' class="textfield" />';
$ci++;
// column collation
$tmp_collation = empty($row['Collation']) ? null : $row['Collation']; $tmp_collation = empty($row['Collation']) ? null : $row['Collation'];
$content_cells[$i][$ci] = PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $i . ']', 'field_' . $i . '_' . ($ci - $ci_offset), $tmp_collation, FALSE); $content_cells[$i][$ci] = PMA_generateCharsetDropdownBox(
PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $i . ']',
'field_' . $i . '_' . ($ci - $ci_offset), $tmp_collation, false);
unset($tmp_collation); unset($tmp_collation);
$ci++; $ci++;
$content_cells[$i][$ci] = '<select style="font-size: 70%;" name="field_attribute[' . $i . ']" id="field_' . $i . '_' . ($ci - $ci_offset) . '">' . "\n"; // column attribute
$content_cells[$i][$ci] = '<select style="font-size: 70%;"'
. ' name="field_attribute[' . $i . ']"'
. ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
$attribute = ''; $attribute = '';
if ($binary) { if ($binary) {
@@ -317,8 +419,11 @@ for ($i = 0; $i <= $num_fields; $i++) {
if ($zerofill) { if ($zerofill) {
$attribute = 'UNSIGNED ZEROFILL'; $attribute = 'UNSIGNED ZEROFILL';
} }
if (isset($row['Extra']) && $row['Extra'] == 'on update CURRENT_TIMESTAMP') {
$attribute = 'on update CURRENT_TIMESTAMP';
}
if (isset($submit_attribute) && $submit_attribute != FALSE) { if (isset($submit_attribute) && $submit_attribute != false) {
$attribute = $submit_attribute; $attribute = $submit_attribute;
} }
@@ -337,34 +442,29 @@ for ($i = 0; $i <= $num_fields; $i++) {
// (if on_update_current_timestamp is set, then it's TRUE) // (if on_update_current_timestamp is set, then it's TRUE)
if (isset($row['Field']) if (isset($row['Field'])
&& isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) { && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
$attribute = 'ON UPDATE CURRENT_TIMESTAMP'; $attribute = 'on update CURRENT_TIMESTAMP';
} }
if ((isset($row['Field']) if ((isset($row['Field'])
&& isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_current_timestamp'])) && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_current_timestamp']))
|| (isset($submit_default_current_timestamp) && $submit_default_current_timestamp)) { || (isset($submit_default_current_timestamp) && $submit_default_current_timestamp)) {
$default_current_timestamp = TRUE; $default_current_timestamp = true;
} else { } else {
$default_current_timestamp = FALSE; $default_current_timestamp = false;
} }
// Dynamically add ON UPDATE CURRENT_TIMESTAMP to the possible attributes
if (! in_array('ON UPDATE CURRENT_TIMESTAMP', $cfg['AttributeTypes'])) {
$cfg['AttributeTypes'][] = 'ON UPDATE CURRENT_TIMESTAMP';
}
$cnt_attribute_types = count($cfg['AttributeTypes']); $cnt_attribute_types = count($cfg['AttributeTypes']);
for ($j = 0; $j < $cnt_attribute_types; $j++) { for ($j = 0; $j < $cnt_attribute_types; $j++) {
$content_cells[$i][$ci] .= ' <option value="'. $cfg['AttributeTypes'][$j] . '"'; $content_cells[$i][$ci] .= ' <option value="'. $cfg['AttributeTypes'][$j] . '"';
if (strtoupper($attribute) == strtoupper($cfg['AttributeTypes'][$j])) { if (strtoupper($attribute) == strtoupper($cfg['AttributeTypes'][$j])) {
$content_cells[$i][$ci] .= ' selected="selected"'; $content_cells[$i][$ci] .= ' selected="selected"';
} }
$content_cells[$i][$ci] .= '>' . $cfg['AttributeTypes'][$j] . '</option>' . "\n"; $content_cells[$i][$ci] .= '>' . $cfg['AttributeTypes'][$j] . '</option>';
} }
$content_cells[$i][$ci] .= '</select>'; $content_cells[$i][$ci] .= '</select>';
$ci++; $ci++;
// column NULL
$content_cells[$i][$ci] = '<input name="field_null[' . $i . ']"' $content_cells[$i][$ci] = '<input name="field_null[' . $i . ']"'
. ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"'; . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
@@ -375,113 +475,67 @@ for ($i = 0; $i <= $num_fields; $i++) {
$content_cells[$i][$ci] .= ' type="checkbox" value="NULL" />'; $content_cells[$i][$ci] .= ' type="checkbox" value="NULL" />';
$ci++; $ci++;
if (isset($row) // column indexes
&& !isset($row['Default']) && isset($row['Null']) && $row['Null'] == 'YES') {
$row['Default'] = 'NULL';
}
if ($is_backup) {
$content_cells[$i][$ci] = "\n" . '<input type="hidden" name="field_default_orig[' . $i . ']" size="8" value="' . (isset($row) && isset($row['Default']) ? urlencode($row['Default']) : '') . '" />';
} else {
$content_cells[$i][$ci] = "\n";
}
// for a TIMESTAMP, do not show CURRENT_TIMESTAMP as a default value
if ($type_upper == 'TIMESTAMP'
&& $default_current_timestamp
&& isset($row['Default'])) {
$row['Default'] = '';
}
$content_cells[$i][$ci] .= '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '" type="text" name="field_default[' . $i . ']" size="12" value="' . (isset($row) && isset($row['Default']) ? str_replace('"', '&quot;', $row['Default']) : '') . '" class="textfield" />';
if ($type_upper == 'TIMESTAMP') {
$tmp_display_type = 'block';
} else {
$tmp_display_type = 'none';
$default_current_timestamp = FALSE;
}
$content_cells[$i][$ci] .= '<br /><div id="div_' . $i . '_' . ($ci - $ci_offset) . '" style="white-space: nowrap; display: ' . $tmp_display_type . '"><input id="field_' . $i . '_' . ($ci - $ci_offset) . 'a" type="checkbox" name="field_default_current_timestamp[' . $i . ']"';
if ($default_current_timestamp) {
$content_cells[$i][$ci] .= ' checked="checked" ';
}
$content_cells[$i][$ci] .= ' /><label for="field_' . $i . '_' . ($ci - $ci_offset) . 'a" style="font-size: 70%;">CURRENT_TIMESTAMP</label></div>';
$ci++;
$content_cells[$i][$ci] = '<select name="field_extra[' . $i . ']" id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
if (!isset($row) || empty($row['Extra'])) {
$content_cells[$i][$ci] .= "\n";
$content_cells[$i][$ci] .= '<option value="">&nbsp;</option>' . "\n";
$content_cells[$i][$ci] .= '<option value="AUTO_INCREMENT">auto_increment</option>' . "\n";
} else {
$content_cells[$i][$ci] .= "\n";
$content_cells[$i][$ci] .= '<option value="AUTO_INCREMENT">auto_increment</option>' . "\n";
$content_cells[$i][$ci] .= '<option value="">&nbsp;</option>' . "\n";
}
$content_cells[$i][$ci] .= "\n" . '</select>';
$ci++;
// lem9: See my other comment about removing this 'if'. // lem9: See my other comment about removing this 'if'.
if (!$is_backup) { if (!$is_backup) {
if (isset($row) && isset($row['Key']) && $row['Key'] == 'PRI') { $content_cells[$i][$ci] = '<select name="field_key[' . $i . ']"'
$checked_primary = ' checked="checked"'; . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
} else { $content_cells[$i][$ci] .= '<option value="none_' . $i . '">---</option>';
$checked_primary = '';
$content_cells[$i][$ci] .= '<option value="primary_' . $i . '" title="' . $strPrimary . '"';
if (isset($row['Key']) && $row['Key'] == 'PRI') {
$content_cells[$i][$ci] .= ' selected="selected"';
} }
if (isset($row) && isset($row['Key']) && $row['Key'] == 'MUL') { $content_cells[$i][$ci] .= '>PRIMARY</option>';
$checked_index = ' checked="checked"';
} else { $content_cells[$i][$ci] .= '<option value="unique_' . $i . '" title="' . $strUnique . '"';
$checked_index = ''; if (isset($row['Key']) && $row['Key'] == 'UNI') {
$content_cells[$i][$ci] .= ' selected="selected"';
} }
if (isset($row) && isset($row['Key']) && $row['Key'] == 'UNI') { $content_cells[$i][$ci] .= '>UNIQUE</option>';
$checked_unique = ' checked="checked"';
} else { $content_cells[$i][$ci] .= '<option value="index_' . $i . '" title="' . $strIndex . '"';
$checked_unique = ''; if (isset($row['Key']) && $row['Key'] == 'MUL') {
$content_cells[$i][$ci] .= ' selected="selected"';
} }
if (empty($checked_primary) $content_cells[$i][$ci] .= '>INDEX</option>';
&& empty($checked_index)
&& empty($checked_unique)) { $content_cells[$i][$ci] .= '<option value="fulltext_' . $i . '" title="' . $strIdxFulltext . '"';
$checked_none = ' checked="checked"'; if (isset($row['Key']) && $row['Key'] == 'FULLTEXT') {
} else { $content_cells[$i][$ci] .= ' selected="selected"';
$checked_none = '';
} }
$content_cells[$i][$ci] .= '>FULLTEXT</option>';
if ((isset($row) && isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) { $content_cells[$i][$ci] .= '</select>';
$checked_fulltext = ' checked="checked"';
} else {
$checked_fulltext = '';
}
$content_cells[$i][$ci] = "\n" . '<input type="radio" name="field_key_' . $i . '" value="primary_' . $i . '"' . $checked_primary . ' title="' . $strPrimary . '" />';
$ci++;
$content_cells[$i][$ci] = "\n" . '<input type="radio" name="field_key_' . $i . '" value="index_' . $i . '"' . $checked_index . ' title="' . $strIndex . '" />';
$ci++;
$content_cells[$i][$ci] = "\n" . '<input type="radio" name="field_key_' . $i . '" value="unique_' . $i . '"' . $checked_unique . ' title="' . $strUnique . '" />';
$ci++;
$content_cells[$i][$ci] = "\n" . '<input type="radio" name="field_key_' . $i . '" value="none_' . $i . '"' . $checked_none . ' title="---" />';
$ci++;
$content_cells[$i][$ci] = '<input type="checkbox" name="field_fulltext[' . $i . ']" value="' . $i . '"' . $checked_fulltext . ' title="' . $strIdxFulltext . '" />';
$ci++; $ci++;
} // end if ($action ==...) } // end if ($action ==...)
// garvin: comments // column auto_increment
$content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '" type="text" name="field_comments[' . $i . ']" size="12" value="' . (isset($row) && isset($row['Field']) && is_array($comments_map) && isset($comments_map[$row['Field']]) ? htmlspecialchars($comments_map[$row['Field']]) : '') . '" class="textfield" />'; $content_cells[$i][$ci] = '<input name="field_extra[' . $i . ']"'
. ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
if (isset($row['Extra']) && $row['Extra'] == 'auto_increment') {
$content_cells[$i][$ci] .= ' checked="checked"';
}
$content_cells[$i][$ci] .= ' type="checkbox" value="AUTO_INCREMENT" />';
$ci++; $ci++;
// garvin: MIME-types // column comments
$content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
. ' type="text" name="field_comments[' . $i . ']" size="12"'
. ' value="' . (isset($row['Field']) && is_array($comments_map) && isset($comments_map[$row['Field']]) ? htmlspecialchars($comments_map[$row['Field']]) : '') . '"'
. ' class="textfield" />';
$ci++;
// column MIME-types
if ($cfgRelation['mimework'] && $cfg['BrowseMIME'] && $cfgRelation['commwork']) { if ($cfgRelation['mimework'] && $cfg['BrowseMIME'] && $cfgRelation['commwork']) {
$content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_mimetype[' . $i . ']">' . "\n"; $content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_mimetype[' . $i . ']">';
$content_cells[$i][$ci] .= ' <option value="">&nbsp;</option>' . "\n"; $content_cells[$i][$ci] .= ' <option value="">&nbsp;</option>';
if (is_array($available_mime['mimetype'])) { if (is_array($available_mime['mimetype'])) {
foreach ($available_mime['mimetype'] AS $mimekey => $mimetype) { foreach ($available_mime['mimetype'] AS $mimekey => $mimetype) {
$checked = (isset($row) && isset($row['Field']) && isset($mime_map[$row['Field']]['mimetype']) && ($mime_map[$row['Field']]['mimetype'] == str_replace('/', '_', $mimetype)) ? 'selected ' : ''); $checked = (isset($row['Field']) && isset($mime_map[$row['Field']]['mimetype']) && ($mime_map[$row['Field']]['mimetype'] == str_replace('/', '_', $mimetype)) ? 'selected ' : '');
$content_cells[$i][$ci] .= ' <option value="' . str_replace('/', '_', $mimetype) . '" ' . $checked . '>' . htmlspecialchars($mimetype) . '</option>'; $content_cells[$i][$ci] .= ' <option value="' . str_replace('/', '_', $mimetype) . '" ' . $checked . '>' . htmlspecialchars($mimetype) . '</option>';
} }
} }
@@ -489,21 +543,25 @@ for ($i = 0; $i <= $num_fields; $i++) {
$content_cells[$i][$ci] .= '</select>'; $content_cells[$i][$ci] .= '</select>';
$ci++; $ci++;
$content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_transformation[' . $i . ']">' . "\n"; $content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_transformation[' . $i . ']">';
$content_cells[$i][$ci] .= ' <option value="" title="' . $strNone . '"></option>' . "\n"; $content_cells[$i][$ci] .= ' <option value="" title="' . $strNone . '"></option>';
if (is_array($available_mime['transformation'])) { if (is_array($available_mime['transformation'])) {
foreach ($available_mime['transformation'] AS $mimekey => $transform) { foreach ($available_mime['transformation'] AS $mimekey => $transform) {
$checked = (isset($row) && isset($row['Field']) && isset($mime_map[$row['Field']]['transformation']) && (preg_match('@' . preg_quote($available_mime['transformation_file'][$mimekey]) . '3?@i', $mime_map[$row['Field']]['transformation'])) ? 'selected ' : ''); $checked = (isset($row['Field']) && isset($mime_map[$row['Field']]['transformation']) && (preg_match('@' . preg_quote($available_mime['transformation_file'][$mimekey]) . '3?@i', $mime_map[$row['Field']]['transformation'])) ? 'selected ' : '');
$tooltip = 'strTransformation_' . strtolower(str_replace('.inc.php', '', $available_mime['transformation_file'][$mimekey])); $tooltip = 'strTransformation_' . strtolower(str_replace('.inc.php', '', $available_mime['transformation_file'][$mimekey]));
$tooltip = isset($$tooltip) ? $$tooltip : sprintf(str_replace('<br />', ' ', $strMIME_nodescription), 'PMA_transformation_' . $tooltip . '()'); $tooltip = isset($$tooltip) ? $$tooltip : sprintf(str_replace('<br />', ' ', $strMIME_nodescription), 'PMA_transformation_' . $tooltip . '()');
$content_cells[$i][$ci] .= '<option value="' . $available_mime['transformation_file'][$mimekey] . '" ' . $checked . ' title="' . htmlspecialchars($tooltip) . '">' . htmlspecialchars($transform) . '</option>' . "\n"; $content_cells[$i][$ci] .= '<option value="' . $available_mime['transformation_file'][$mimekey] . '" ' . $checked . ' title="' . htmlspecialchars($tooltip) . '">' . htmlspecialchars($transform) . '</option>';
} }
} }
$content_cells[$i][$ci] .= '</select>'; $content_cells[$i][$ci] .= '</select>';
$ci++; $ci++;
$content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '" type="text" name="field_transformation_options[' . $i . ']" size="16" value="' . (isset($row) && isset($row['Field']) && isset($mime_map[$row['Field']]['transformation_options']) ? htmlspecialchars($mime_map[$row['Field']]['transformation_options']) : '') . '" class="textfield" />'; $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
. ' type="text" name="field_transformation_options[' . $i . ']"'
. ' size="16" class="textfield"'
. ' value="' . (isset($row['Field']) && isset($mime_map[$row['Field']]['transformation_options']) ? htmlspecialchars($mime_map[$row['Field']]['transformation_options']) : '') . '"'
. ' />';
//$ci++; //$ci++;
} }
} // end for } // end for
@@ -519,24 +577,7 @@ document.onkeydown = onKeyDownArrowsHandler;
</script> </script>
<?php <?php
} }
// here, the div_x_7 represents a div id which contains
// the default CURRENT TIMESTAMP checkbox and label
// and, field_x_7a represents the checkbox itself
?> ?>
<script type="text/javascript">
// <![CDATA[
function display_field_options(field_type, i) {
if (field_type == 'TIMESTAMP') {
getElement('div_' + i + '_7').style.display = 'block';
} else {
getElement('div_' + i + '_7').style.display = 'none';
getElement('field_' + i + '_7a').checked = false;
}
return true;
}
// ]]>
</script>
<form method="post" action="<?php echo $action; ?>"> <form method="post" action="<?php echo $action; ?>">
<?php <?php
@@ -545,7 +586,7 @@ unset($_form_params);
if (is_array($content_cells) && is_array($header_cells)) { if (is_array($content_cells) && is_array($header_cells)) {
// last row is for javascript insert // last row is for javascript insert
$empty_row = array_pop($content_cells); //$empty_row = array_pop($content_cells);
echo '<table id="table_columns">'; echo '<table id="table_columns">';
if ($display_type == 'horizontal') { if ($display_type == 'horizontal') {
@@ -646,21 +687,21 @@ if ($action == 'tbl_create.php') {
<th><?php echo $strCollation ;?>:&nbsp;</th> <th><?php echo $strCollation ;?>:&nbsp;</th>
</tr> </tr>
<tr><td><input type="text" name="comment" size="40" maxlength="80" <tr><td><input type="text" name="comment" size="40" maxlength="80"
value="<?php echo (isset($comment) ? $comment : ''); ?>" value="<?php echo (isset($_REQUEST['comment']) ? htmlspecialchars($_REQUEST['comment']) : ''); ?>"
class="textfield" /> class="textfield" />
</td> </td>
<td width="25">&nbsp;</td> <td width="25">&nbsp;</td>
<td> <td>
<?php <?php
echo PMA_StorageEngine::getHtmlSelect('tbl_type', null, echo PMA_StorageEngine::getHtmlSelect('tbl_type', null,
(isset($GLOBALS['tbl_type']) ? $GLOBALS['tbl_type'] : null)); (isset($_REQUEST['tbl_type']) ? $_REQUEST['tbl_type'] : null));
?> ?>
</td> </td>
<td width="25">&nbsp;</td> <td width="25">&nbsp;</td>
<td> <td>
<?php <?php
echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation', echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation',
null, (isset($tbl_collation) ? $tbl_collation : null), FALSE, 3); null, (isset($_REQUEST['tbl_collation']) ? $_REQUEST['tbl_collation'] : null), false, 3);
?> ?>
</td> </td>
</tr> </tr>
@@ -673,7 +714,10 @@ if ($action == 'tbl_create.php') {
</tr> </tr>
<tr> <tr>
<td> <td>
<textarea name="partition_definition" id="partitiondefinition" cols="<?php echo $GLOBALS['cfg']['TextareaCols'];?>" rows="<?php echo $GLOBALS['cfg']['TextareaRows'];?>" dir="<?php echo $GLOBALS['text_dir'];?>"></textarea> <textarea name="partition_definition" id="partitiondefinition"
cols="<?php echo $GLOBALS['cfg']['TextareaCols'];?>"
rows="<?php echo $GLOBALS['cfg']['TextareaRows'];?>"
dir="<?php echo $GLOBALS['text_dir'];?>"><?php echo (isset($_REQUEST['partition_definition']) ? htmlspecialchars($_REQUEST['partition_definition']) : ''); ?></textarea>
</td> </td>
</tr> </tr>
<?php <?php
@@ -686,7 +730,8 @@ if ($action == 'tbl_create.php') {
?> ?>
<fieldset class="tblFooters"> <fieldset class="tblFooters">
<input type="submit" name="do_save_data" value="<?php echo $strSave; ?>" onclick="return checkTableEditForm(this.form, <?php echo $num_fields; ?>)" /> <input type="submit" name="do_save_data" value="<?php echo $strSave; ?>"
onclick="return checkTableEditForm(this.form, <?php echo $num_fields; ?>)" />
<?php if ($action == 'tbl_create.php' || $action == 'tbl_addfield.php') { ?> <?php if ($action == 'tbl_create.php' || $action == 'tbl_addfield.php') { ?>
<?php echo $GLOBALS['strOr']; ?> <?php echo $GLOBALS['strOr']; ?>
<?php echo sprintf($strAddFields, '<input type="text" id="added_fields" name="added_fields" size="2" value="1" onfocus="this.select()" />'); ?> <?php echo sprintf($strAddFields, '<input type="text" id="added_fields" name="added_fields" size="2" value="1" onfocus="this.select()" />'); ?>

View File

@@ -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 * The form used to define the field to add has been submitted
*/ */
$abort = false; $abort = false;
if (isset($submit_num_fields)) {
if (isset($orig_after_field)) { // check number of fields to be created
$after_field = $orig_after_field; if (isset($_REQUEST['submit_num_fields'])) {
if (isset($_REQUEST['orig_after_field'])) {
$_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
} }
if (isset($orig_field_where)) { if (isset($_REQUEST['orig_field_where'])) {
$field_where = $orig_field_where; $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
} }
$num_fields = $orig_num_fields + $added_fields; $num_fields = $_REQUEST['orig_num_fields'] + $_REQUEST['added_fields'];
$regenerate = TRUE; $regenerate = true;
} elseif (isset($do_save_data)) { } 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 = ''; $query = '';
$definitions = array();
// Transforms the radio button field_key into 3 arrays // 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) { for ($i = 0; $i < $field_cnt; ++$i) {
if (isset(${'field_key_' . $i})) { if (isset($_REQUEST['field_key'][$i])
if (${'field_key_' . $i} == 'primary_' . $i) { && strlen($_REQUEST['field_name'][$i])) {
if ($_REQUEST['field_key'][$i] == 'primary_' . $i) {
$field_primary[] = $i; $field_primary[] = $i;
} }
if (${'field_key_' . $i} == 'index_' . $i) { if ($_REQUEST['field_key'][$i] == 'index_' . $i) {
$field_index[] = $i; $field_index[] = $i;
} }
if (${'field_key_' . $i} == 'unique_' . $i) { if ($_REQUEST['field_key'][$i] == 'unique_' . $i) {
$field_unique[] = $i; $field_unique[] = $i;
} }
} // end if } // end if
} // end for } // end for
// Builds the field creation statement and alters the table
// Builds the field creation statement and alters the table
for ($i = 0; $i < $field_cnt; ++$i) { for ($i = 0; $i < $field_cnt; ++$i) {
// '0' is also empty for php :-( // '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; continue;
} }
$query .= PMA_Table::generateFieldSpec($field_name[$i], $field_type[$i], $definition = ' ADD ' . PMA_Table::generateFieldSpec(
$field_length[$i], $field_attribute[$i], $_REQUEST['field_name'][$i],
isset($field_collation[$i]) ? $field_collation[$i] : '', $_REQUEST['field_type'][$i],
isset($field_null[$i]) ? $field_null[$i] : 'NOT NULL', $_REQUEST['field_length'][$i],
$field_default[$i], $_REQUEST['field_attribute'][$i],
isset($field_default_current_timestamp[$i]), $field_extra[$i], isset($_REQUEST['field_collation'][$i])
isset($field_comments[$i]) ? $field_comments[$i] : '', ? $_REQUEST['field_collation'][$i]
$field_primary, $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 ($field_where != 'last') { if ($_REQUEST['field_where'] != 'last') {
// Only the first field can be added somewhere other than at the end // Only the first field can be added somewhere other than at the end
if ($i == 0) { if ($i == 0) {
if ($field_where == 'first') { if ($_REQUEST['field_where'] == 'first') {
$query .= ' FIRST'; $definition .= ' FIRST';
} else { } else {
$query .= ' AFTER ' . PMA_backquote(urldecode($after_field)); $definition .= ' AFTER ' . PMA_backquote($_REQUEST['after_field']);
} }
} else { } else {
$query .= ' AFTER ' . PMA_backquote($field_name[$i-1]); $definition .= ' AFTER ' . PMA_backquote($_REQUEST['field_name'][$i-1]);
} }
} }
$query .= ', ADD '; $definitions[] = $definition;
} // end for } // 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 // To allow replication, we first select the db to use and then run queries
// on this db. // on this db.
PMA_DBI_select_db($db) or PMA_mysqlDie(PMA_getError(), 'USE ' . PMA_backquotes($db), '', $err_url); 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; $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ' . implode(', ', $definitions);
$error_create = FALSE; $result = PMA_DBI_try_query($sql_query);
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
if ($result === true) {
// garvin: If comments were sent, enable relation stuff // garvin: If comments were sent, enable relation stuff
require_once './libraries/relation.lib.php'; require_once './libraries/relation.lib.php';
require_once './libraries/transformations.lib.php'; require_once './libraries/transformations.lib.php';
$cfgRelation = PMA_getRelationsParam();
// garvin: Update comment table for mime types [MIME] // garvin: Update comment table for mime types [MIME]
if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) { if (isset($_REQUEST['field_mimetype'])
foreach ($field_mimetype AS $fieldindex => $mimetype) { && is_array($_REQUEST['field_mimetype'])
if (isset($field_name[$fieldindex]) && strlen($field_name[$fieldindex])) { && $cfg['BrowseMIME']) {
PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]); 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 // Go back to the structure sub-page
$sql_query = $sql_query_cpy;
unset($sql_query_cpy);
$message = PMA_Message::success('strTableAlteredSuccessfully'); $message = PMA_Message::success('strTableAlteredSuccessfully');
$message->addParam($table); $message->addParam($table);
$active_page = 'tbl_structure.php'; $active_page = 'tbl_structure.php';
require './tbl_structure.php'; require './tbl_structure.php';
} else { } else {
PMA_mysqlDie('', '', '', $err_url, FALSE); PMA_mysqlDie('', '', '', $err_url, false);
// garvin: An error happened while inserting/updating a table definition. // garvin: An error happened while inserting/updating a table definition.
// to prevent total loss of that data, we embed the form once again. // 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 // The variable $regenerate will be used to restore data in libraries/tbl_properties.inc.php
$num_fields = $orig_num_fields; $num_fields = $_REQUEST['orig_num_fields'];
if (isset($orig_after_field)) { if (isset($_REQUEST['orig_after_field'])) {
$after_field = $orig_after_field; $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
} }
if (isset($orig_field_where)) { if (isset($_REQUEST['orig_field_where'])) {
$field_where = $orig_field_where; $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
} }
$regenerate = true; $regenerate = true;
} }
@@ -210,7 +198,7 @@ if (isset($submit_num_fields)) {
/** /**
* Displays the form used to define the new field * Displays the form used to define the new field
*/ */
if ($abort == FALSE) { if ($abort == false) {
/** /**
* Gets tables informations * Gets tables informations
*/ */
@@ -228,7 +216,6 @@ if ($abort == FALSE) {
require_once './libraries/tbl_properties.inc.php'; require_once './libraries/tbl_properties.inc.php';
// Diplays the footer // Diplays the footer
echo "\n";
require_once './libraries/footer.inc.php'; require_once './libraries/footer.inc.php';
} }

View File

@@ -26,13 +26,8 @@ PMA_checkParameters(array('db', 'table'));
*/ */
require_once './libraries/tbl_common.php'; require_once './libraries/tbl_common.php';
require_once './libraries/tbl_info.inc.php'; require_once './libraries/tbl_info.inc.php';
/**
* Displays top menu links
*/
$active_page = 'tbl_structure.php';
// I don't see the need to display the links here, they will be displayed later
//require './libraries/tbl_links.inc.php';
$active_page = 'tbl_structure.php';
/** /**
* Defines the url to return to in case of error in a sql statement * Defines the url to return to in case of error in a sql statement
@@ -44,47 +39,65 @@ $err_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
* Modifications have been submitted -> updates the table * Modifications have been submitted -> updates the table
*/ */
$abort = false; $abort = false;
if (isset($do_save_data)) { if (isset($_REQUEST['do_save_data'])) {
$field_cnt = count($field_orig); var_dump($_POST);
for ($i = 0; $i < $field_cnt; $i++) { $field_cnt = count($_REQUEST['field_orig']);
// to "&quot;" in tbl_sql.php $key_fields = array();
$field_orig[$i] = urldecode($field_orig[$i]); $changes = array();
if (strcmp(str_replace('"', '&quot;', $field_orig[$i]), $field_name[$i]) == 0) {
$field_name[$i] = $field_orig[$i];
}
$field_default_orig[$i] = urldecode($field_default_orig[$i]);
if (strcmp(str_replace('"', '&quot;', $field_default_orig[$i]), $field_default[$i]) == 0) {
$field_default[$i] = $field_default_orig[$i];
}
$field_length_orig[$i] = urldecode($field_length_orig[$i]);
if (strcmp(str_replace('"', '&quot;', $field_length_orig[$i]), $field_length[$i]) == 0) {
$field_length[$i] = $field_length_orig[$i];
}
if (!isset($query)) {
$query = '';
} else {
$query .= ', CHANGE ';
}
$query .= PMA_Table::generateAlter($field_orig[$i], $field_name[$i], for ($i = 0; $i < $field_cnt; $i++) {
$field_type[$i], $field_length[$i], $field_attribute[$i], $changes[] = 'CHANGE ' . PMA_Table::generateAlter(
isset($field_collation[$i]) ? $field_collation[$i] : '', $_REQUEST['field_orig'][$i],
isset($field_null[$i]) ? $field_null[$i] : 'NOT NULL', $_REQUEST['field_name'][$i],
$field_default[$i], $_REQUEST['field_type'][$i],
isset($field_default_current_timestamp[$i]), $field_extra[$i], $_REQUEST['field_length'][$i],
isset($field_comments[$i]) ? $field_comments[$i] : '', $_REQUEST['field_attribute'][$i],
$field_default_orig[$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]
: '',
$key_fields,
$i,
$_REQUEST['field_default_orig'][$i]
);
} // end for } // end for
// Builds the primary keys statements and updates the table
$key_query = '';
/**
* this is a little bit more complex
*
* @todo if someone selects A_I when altering a column we need to check:
* - no other column with A_I
* - the column has an index, if not create one
*
if (count($key_fields)) {
$fields = array();
foreach ($key_fields as $each_field) {
if (isset($_REQUEST['field_name'][$each_field]) && strlen($_REQUEST['field_name'][$each_field])) {
$fields[] = PMA_backquote($_REQUEST['field_name'][$each_field]);
}
} // end for
$key_query = ', ADD KEY (' . implode(', ', $fields) . ') ';
}
*/
// To allow replication, we first select the db to use and then run queries // To allow replication, we first select the db to use and then run queries
// on this db. // on this db.
PMA_DBI_select_db($db) or PMA_mysqlDie(PMA_DBI_getError(), 'USE ' . PMA_backquote($db) . ';', '', $err_url); PMA_DBI_select_db($db) or PMA_mysqlDie(PMA_DBI_getError(), 'USE ' . PMA_backquote($db) . ';', '', $err_url);
// Optimization fix - 2 May 2001 - Robbat2 // Optimization fix - 2 May 2001 - Robbat2
$sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . $query; $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ' . implode(', ', $changes) . $key_query;
$error_create = FALSE; $result = PMA_DBI_try_query($sql_query);
$result = PMA_DBI_try_query($sql_query) or $error_create = TRUE;
if ($error_create == FALSE) { if ($result !== false) {
$message = PMA_Message::success('strTableAlteredSuccessfully'); $message = PMA_Message::success('strTableAlteredSuccessfully');
$message->addParam($table); $message->addParam($table);
$btnDrop = 'Fake'; $btnDrop = 'Fake';
@@ -93,51 +106,27 @@ if (isset($do_save_data)) {
require_once './libraries/relation.lib.php'; require_once './libraries/relation.lib.php';
require_once './libraries/transformations.lib.php'; require_once './libraries/transformations.lib.php';
$cfgRelation = PMA_getRelationsParam(); // updaet field names in relation
if (isset($_REQUEST['field_orig']) && is_array($_REQUEST['field_orig'])) {
// garvin: Rename relations&display fields, if altered. foreach ($_REQUEST['field_orig'] as $fieldindex => $fieldcontent) {
if (($cfgRelation['displaywork'] || $cfgRelation['relwork']) && isset($field_orig) && is_array($field_orig)) { if ($_REQUEST['field_name'][$fieldindex] != $fieldcontent) {
foreach ($field_orig AS $fieldindex => $fieldcontent) { PMA_REL_renameField($db, $table, $fieldcontent,
if ($field_name[$fieldindex] != $fieldcontent) { $_REQUEST['field_name'][$fieldindex]);
if ($cfgRelation['displaywork']) { }
$table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) }
. ' SET display_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND display_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
$tb_rs = PMA_query_as_cu($table_query);
unset($table_query);
unset($tb_rs);
} }
if ($cfgRelation['relwork']) { // update mime types
$table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) if (isset($_REQUEST['field_mimetype'])
. ' SET master_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\'' && is_array($_REQUEST['field_mimetype'])
. ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\'' && $cfg['BrowseMIME']) {
. ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\'' foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
. ' AND master_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\''; if (isset($_REQUEST['field_name'][$fieldindex])
$tb_rs = PMA_query_as_cu($table_query); && strlen($_REQUEST['field_name'][$fieldindex])) {
unset($table_query); PMA_setMIME($db, $table, $_REQUEST['field_name'][$fieldindex],
unset($tb_rs); $mimetype,
$_REQUEST['field_transformation'][$fieldindex],
$table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) $_REQUEST['field_transformation_options'][$fieldindex]);
. ' SET foreign_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
. ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
. ' AND foreign_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
$tb_rs = PMA_query_as_cu($table_query);
unset($table_query);
unset($tb_rs);
} // end if relwork
} // end if fieldname has changed
} // end while check fieldnames
} // end if relations/display has to be changed
// 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]);
} }
} }
} }
@@ -145,12 +134,12 @@ if (isset($do_save_data)) {
$active_page = 'tbl_structure.php'; $active_page = 'tbl_structure.php';
require './tbl_structure.php'; require './tbl_structure.php';
} else { } else {
PMA_mysqlDie('', '', '', $err_url, FALSE); PMA_mysqlDie('', '', '', $err_url, false);
// garvin: An error happened while inserting/updating a table definition. // garvin: An error happened while inserting/updating a table definition.
// to prevent total loss of that data, we embed the form once again. // 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 // The variable $regenerate will be used to restore data in libraries/tbl_properties.inc.php
if (isset($orig_field)) { if (isset($_REQUEST['orig_field'])) {
$field = $orig_field; $_REQUEST['field'] = $_REQUEST['orig_field'];
} }
$regenerate = true; $regenerate = true;
@@ -159,11 +148,13 @@ if (isset($do_save_data)) {
/** /**
* No modifications yet required -> displays the table fields * No modifications yet required -> displays the table fields
*
* $selected comes from multi_submits.inc.php
*/ */
if ($abort == FALSE) { if ($abort == false) {
if (! isset($selected)) { if (! isset($selected)) {
PMA_checkParameters(array('field')); PMA_checkParameters(array('field'));
$selected[] = $field; $selected[] = $_REQUEST['field'];
$selected_cnt = 1; $selected_cnt = 1;
} else { // from a multiple submit } else { // from a multiple submit
$selected_cnt = count($selected); $selected_cnt = count($selected);
@@ -173,12 +164,8 @@ if ($abort == FALSE) {
* @todo optimize in case of multiple fields to modify * @todo optimize in case of multiple fields to modify
*/ */
for ($i = 0; $i < $selected_cnt; $i++) { for ($i = 0; $i < $selected_cnt; $i++) {
if (!empty($submit_mult)) { $_REQUEST['field'] = PMA_sqlAddslashes($selected[$i], true);
$field = PMA_sqlAddslashes(urldecode($selected[$i]), TRUE); $result = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ' LIKE \'' . $_REQUEST['field'] . '\';');
} else {
$field = PMA_sqlAddslashes($selected[$i], TRUE);
}
$result = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ' LIKE \'' . $field . '\';');
$fields_meta[] = PMA_DBI_fetch_assoc($result); $fields_meta[] = PMA_DBI_fetch_assoc($result);
PMA_DBI_free_result($result); PMA_DBI_free_result($result);
} }

View File

@@ -63,6 +63,16 @@ if (! strlen($table)) {
$err_url = 'tbl_create.php?' . PMA_generate_common_url($db, $table); $err_url = 'tbl_create.php?' . PMA_generate_common_url($db, $table);
// check number of fields to be created
if (isset($_REQUEST['submit_num_fields'])) {
$regenerate = true; // for libraries/tbl_properties.inc.php
$num_fields = $_REQUEST['orig_num_fields'] + $_REQUEST['added_fields'];
} elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
$num_fields = (int) $_REQUEST['num_fields'];
} else {
$num_fields = 2;
}
/** /**
* Selects the database to work with * Selects the database to work with
*/ */
@@ -75,35 +85,47 @@ if (isset($_REQUEST['do_save_data'])) {
$sql_query = ''; $sql_query = '';
// Transforms the radio button field_key into 3 arrays // Transforms the radio button field_key into 3 arrays
$field_cnt = count($field_name); $field_cnt = count($_REQUEST['field_name']);
for ($i = 0; $i < $field_cnt; ++$i) { for ($i = 0; $i < $field_cnt; ++$i) {
if (isset(${'field_key_' . $i})) { if (isset($_REQUEST['field_key'][$i])) {
if (${'field_key_' . $i} == 'primary_' . $i) { if ($_REQUEST['field_key'][$i] == 'primary_' . $i) {
$field_primary[] = $i; $field_primary[] = $i;
} }
if (${'field_key_' . $i} == 'index_' . $i) { if ($_REQUEST['field_key'][$i] == 'index_' . $i) {
$field_index[] = $i; $field_index[] = $i;
} }
if (${'field_key_' . $i} == 'unique_' . $i) { if ($_REQUEST['field_key'][$i] == 'unique_' . $i) {
$field_unique[] = $i; $field_unique[] = $i;
} }
} // end if } // end if
} // end for } // end for
// Builds the fields creation statements // Builds the fields creation statements
for ($i = 0; $i < $field_cnt; $i++) { for ($i = 0; $i < $field_cnt; $i++) {
// '0' is also empty for php :-( // '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; continue;
} }
$query = PMA_Table::generateFieldSpec($field_name[$i], $field_type[$i], $query = PMA_Table::generateFieldSpec(
$field_length[$i], $field_attribute[$i], $_REQUEST['field_name'][$i],
isset($field_collation[$i]) ? $field_collation[$i] : '', $_REQUEST['field_type'][$i],
isset($field_null[$i]) ? $field_null[$i] : 'NOT NULL', $_REQUEST['field_length'][$i],
$field_default[$i], $_REQUEST['field_attribute'][$i],
isset($field_default_current_timestamp[$i]), $field_extra[$i], isset($_REQUEST['field_collation'][$i])
isset($field_comments[$i]) ? $field_comments[$i] : '', ? $_REQUEST['field_collation'][$i]
$field_primary, $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);
$query .= ', '; $query .= ', ';
$sql_query .= $query; $sql_query .= $query;
@@ -116,8 +138,8 @@ if (isset($_REQUEST['do_save_data'])) {
$primary_cnt = (isset($field_primary) ? count($field_primary) : 0); $primary_cnt = (isset($field_primary) ? count($field_primary) : 0);
for ($i = 0; $i < $primary_cnt; $i++) { for ($i = 0; $i < $primary_cnt; $i++) {
$j = $field_primary[$i]; $j = $field_primary[$i];
if (isset($field_name[$j]) && strlen($field_name[$j])) { if (isset($_REQUEST['field_name'][$j]) && strlen($_REQUEST['field_name'][$j])) {
$primary .= PMA_backquote($field_name[$j]) . ', '; $primary .= PMA_backquote($_REQUEST['field_name'][$j]) . ', ';
} }
} // end for } // end for
unset($primary_cnt); unset($primary_cnt);
@@ -132,8 +154,8 @@ if (isset($_REQUEST['do_save_data'])) {
$index_cnt = (isset($field_index) ? count($field_index) : 0); $index_cnt = (isset($field_index) ? count($field_index) : 0);
for ($i = 0;$i < $index_cnt; $i++) { for ($i = 0;$i < $index_cnt; $i++) {
$j = $field_index[$i]; $j = $field_index[$i];
if (isset($field_name[$j]) && strlen($field_name[$j])) { if (isset($_REQUEST['field_name'][$j]) && strlen($_REQUEST['field_name'][$j])) {
$index .= PMA_backquote($field_name[$j]) . ', '; $index .= PMA_backquote($_REQUEST['field_name'][$j]) . ', ';
} }
} // end for } // end for
unset($index_cnt); unset($index_cnt);
@@ -148,8 +170,8 @@ if (isset($_REQUEST['do_save_data'])) {
$unique_cnt = (isset($field_unique) ? count($field_unique) : 0); $unique_cnt = (isset($field_unique) ? count($field_unique) : 0);
for ($i = 0; $i < $unique_cnt; $i++) { for ($i = 0; $i < $unique_cnt; $i++) {
$j = $field_unique[$i]; $j = $field_unique[$i];
if (isset($field_name[$j]) && strlen($field_name[$j])) { if (isset($_REQUEST['field_name'][$j]) && strlen($_REQUEST['field_name'][$j])) {
$unique .= PMA_backquote($field_name[$j]) . ', '; $unique .= PMA_backquote($_REQUEST['field_name'][$j]) . ', ';
} }
} // end for } // end for
unset($unique_cnt); unset($unique_cnt);
@@ -164,8 +186,8 @@ if (isset($_REQUEST['do_save_data'])) {
$fulltext_cnt = (isset($field_fulltext) ? count($field_fulltext) : 0); $fulltext_cnt = (isset($field_fulltext) ? count($field_fulltext) : 0);
for ($i = 0; $i < $fulltext_cnt; $i++) { for ($i = 0; $i < $fulltext_cnt; $i++) {
$j = $field_fulltext[$i]; $j = $field_fulltext[$i];
if (isset($field_name[$j]) && strlen($field_name[$j])) { if (isset($_REQUEST['field_name'][$j]) && strlen($_REQUEST['field_name'][$j])) {
$fulltext .= PMA_backquote($field_name[$j]) . ', '; $fulltext .= PMA_backquote($_REQUEST['field_name'][$j]) . ', ';
} }
} // end for } // end for
@@ -180,17 +202,17 @@ if (isset($_REQUEST['do_save_data'])) {
. ' (' . $sql_query . ')'; . ' (' . $sql_query . ')';
// Adds table type, character set, comments and partition definition // Adds table type, character set, comments and partition definition
if (!empty($tbl_type) && ($tbl_type != 'Default')) { if (!empty($_REQUEST['tbl_type']) && ($_REQUEST['tbl_type'] != 'Default')) {
$sql_query .= ' ENGINE = ' . $tbl_type; $sql_query .= ' ENGINE = ' . $_REQUEST['tbl_type'];
} }
if (!empty($tbl_collation)) { if (!empty($_REQUEST['tbl_collation'])) {
$sql_query .= PMA_generateCharsetQueryPart($tbl_collation); $sql_query .= PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
} }
if (!empty($comment)) { if (!empty($_REQUEST['comment'])) {
$sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\''; $sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($_REQUEST['comment']) . '\'';
} }
if (!empty($partition_definition)) { if (!empty($_REQUEST['partition_definition'])) {
$sql_query .= ' ' . PMA_sqlAddslashes($partition_definition); $sql_query .= ' ' . PMA_sqlAddslashes($_REQUEST['partition_definition']);
} }
// Executes the query // Executes the query
@@ -202,17 +224,16 @@ if (isset($_REQUEST['do_save_data'])) {
require_once './libraries/relation.lib.php'; require_once './libraries/relation.lib.php';
require_once './libraries/transformations.lib.php'; require_once './libraries/transformations.lib.php';
$cfgRelation = PMA_getRelationsParam();
// garvin: Update comment table for mime types [MIME] // garvin: Update comment table for mime types [MIME]
if (isset($field_mimetype) && is_array($field_mimetype) if (isset($_REQUEST['field_mimetype'])
&& $cfgRelation['commwork'] && $cfgRelation['mimework'] && is_array($_REQUEST['field_mimetype'])
&& $cfg['BrowseMIME']) { && $cfg['BrowseMIME']) {
foreach ($field_mimetype as $fieldindex => $mimetype) { foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
if (isset($field_name[$fieldindex]) && strlen($field_name[$fieldindex])) { if (isset($_REQUEST['field_name'][$fieldindex])
PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, && strlen($_REQUEST['field_name'][$fieldindex])) {
$field_transformation[$fieldindex], PMA_setMIME($db, $table, $_REQUEST['field_name'][$fieldindex], $mimetype,
$field_transformation_options[$fieldindex]); $_REQUEST['field_transformation'][$fieldindex],
$_REQUEST['field_transformation_options'][$fieldindex]);
} }
} }
} }
@@ -235,23 +256,13 @@ if (isset($_REQUEST['do_save_data'])) {
// garvin: An error happened while inserting/updating a table definition. // garvin: An error happened while inserting/updating a table definition.
// to prevent total loss of that data, we embed the form once again. // 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 // The variable $regenerate will be used to restore data in libraries/tbl_properties.inc.php
$num_fields = $orig_num_fields; $num_fields = $_REQUEST['orig_num_fields'];
} }
} // end do create table } // end do create table
/** /**
* Displays the form used to define the structure of the table * Displays the form used to define the structure of the table
*/ */
// check number of fields to be created
if (isset($_REQUEST['submit_num_fields'])) {
$regenerate = true; // for libraries/tbl_properties.inc.php
$num_fields = $_REQUEST['orig_num_fields'] + $_REQUEST['added_fields'];
} elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
$num_fields = (int) $_REQUEST['num_fields'];
} else {
$num_fields = 1;
}
$action = 'tbl_create.php'; $action = 'tbl_create.php';
require './libraries/tbl_properties.inc.php'; require './libraries/tbl_properties.inc.php';
// Displays the footer // Displays the footer

View File

@@ -294,7 +294,7 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
// MySQL 4.1.2+ TIMESTAMP options // MySQL 4.1.2+ TIMESTAMP options
// (if on_update_current_timestamp is set, then it's TRUE) // (if on_update_current_timestamp is set, then it's TRUE)
if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) { if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
$attribute = 'ON UPDATE CURRENT_TIMESTAMP'; $attribute = 'on update CURRENT_TIMESTAMP';
} }
// here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the