diff --git a/ChangeLog b/ChangeLog index 9d7362b3e..362855e3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -33,6 +33,8 @@ danbarry - bug #1845605 [i18n] translators.html still uses iso-8859-1 - bug #1823018 [charset] Edit(Delete) img-links pointing to wrong row - 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 + patch #1847534 [interface] New "Inside field" in db search, thanks to obiserver @@ -63,6 +65,7 @@ danbarry - bug #1955386 [session] Overriding session.hash_bits_per_character - [interface] sanitize the table comments in table print view, 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 2.11.6.0 (2008-04-29) diff --git a/libraries/Table.class.php b/libraries/Table.class.php index 28898dad1..682102691 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -259,27 +259,23 @@ class PMA_Table { * @param string $attribute * @param string $collation * @param string $null with 'NULL' or 'NOT NULL' - * @param string $default default value - * @param boolean $default_current_timestamp whether default value is - * CURRENT_TIMESTAMP or not - * this overrides $default value + * @param string $default_type whether default is CURRENT_TIMESTAMP, + * NULL, NONE, USER_DEFINED + * @param boolean $default_value default value for USER_DEFINED default type * @param string $extra 'AUTO_INCREMENT' * @param string $comment field comment * @param array &$field_primary list of fields for PRIMARY KEY * @param string $index - * @param string $default_orig * @return string field specification */ static function generateFieldSpec($name, $type, $length = '', $attribute = '', - $collation = '', $null = false, $default = '', - $default_current_timestamp = false, $extra = '', $comment = '', + $collation = '', $null = false, $default_type = 'USER_DEFINED', + $default_value = '', $extra = '', $comment = '', &$field_primary, $index, $default_orig = false) { $is_timestamp = strpos(' ' . strtoupper($type), 'TIMESTAMP') == 1; - // $default_current_timestamp has priority over $default - /** * @todo include db-name */ @@ -307,22 +303,25 @@ class PMA_Table { } } - if ($default_current_timestamp && $is_timestamp) { - $query .= ' DEFAULT CURRENT_TIMESTAMP'; - // auto_increment field cannot have a default value - } 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' - // but DEFAULT 0 works - $query .= ' DEFAULT ' . PMA_sqlAddslashes($default); - } elseif ($type == 'BIT') { - $query .= ' DEFAULT b\'' . preg_replace('/[^01]/', '0', $default) . '\''; - } else { - $query .= ' DEFAULT \'' . PMA_sqlAddslashes($default) . '\''; - } + switch ($default_type) { + case 'USER_DEFINED' : + if ($is_timestamp && $default_value === '0') { + // a TIMESTAMP does not accept DEFAULT '0' + // but DEFAULT 0 works + $query .= ' DEFAULT 0'; + } elseif ($type == 'BIT') { + $query .= ' DEFAULT b\'' . preg_replace('/[^01]/', '0', $default_value) . '\''; + } else { + $query .= ' DEFAULT \'' . PMA_sqlAddslashes($default_value) . '\''; + } + break; + case 'NULL' : + case 'CURRENT_TIMESTAMP' : + $query .= ' DEFAULT ' . $default_type; + break; + case 'NONE' : + default : + break; } if (!empty($extra)) { @@ -440,15 +439,15 @@ class PMA_Table { } // end of the 'PMA_Table::countRecords()' function /** - * @todo add documentation + * @see PMA_Table::generateFieldSpec() */ static public function generateAlter($oldcol, $newcol, $type, $length, - $attribute, $collation, $null, $default, $default_current_timestamp, - $extra, $comment='', &$field_primary, $index, $default_orig) + $attribute, $collation, $null, $default_type, $default_value, + $extra, $comment = '', &$field_primary, $index, $default_orig) { return PMA_backquote($oldcol) . ' ' . 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); } // end function diff --git a/libraries/tbl_properties.inc.php b/libraries/tbl_properties.inc.php index adbbbcd28..d00b8e82e 100644 --- a/libraries/tbl_properties.inc.php +++ b/libraries/tbl_properties.inc.php @@ -1,8 +1,9 @@ ' . PMA_showMySQLDocu('SQL-Syntax', 'data-types') . ''); +$header_cells[] = $strType + . ($GLOBALS['cfg']['ReplaceHelpImg'] + ? PMA_showMySQLDocu('SQL-Syntax', 'data-types') + : '
' . PMA_showMySQLDocu('SQL-Syntax', 'data-types') + . ''); $header_cells[] = $strLengthSet . PMA_showHint($strSetEnumVal); +$header_cells[] = $strDefault . PMA_showHint($strDefaultValueHelp); $header_cells[] = $strCollation; $header_cells[] = $strAttr; $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 // editable. However, for this to work, tbl_alter must be modified to use the // key fields, as tbl_addfield does. if (!$is_backup) { - $header_cells[] = $cfg['PropertiesIconic'] ? '' . $strPrimary . '' : $strPrimary; - $header_cells[] = $cfg['PropertiesIconic'] ? '' . $strIndex . '' : $strIndex; - $header_cells[] = $cfg['PropertiesIconic'] ? '' . $strUnique . '' : $strUnique; - $header_cells[] = '---'; - $header_cells[] = $cfg['PropertiesIconic'] ? '' . $strIdxFulltext . '' : $strIdxFulltext; + $header_cells[] = $strIndex; } +$header_cells[] = 'A_I'; + require_once './libraries/relation.lib.php'; require_once './libraries/transformations.lib.php'; $cfgRelation = PMA_getRelationsParam(); @@ -130,91 +130,138 @@ if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) { $header_cells[] = $strMIME_MIMEtype; $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 // the index as a value, not a key. Inserted here for easier maintaineance // and less code to change in existing files. 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; } } -for ($i = 0; $i <= $num_fields; $i++) { +for ($i = 0; $i < $num_fields; $i++) { if (! empty($regenerate)) { // An error happened with previous inputs, so we will restore the data // to embed it once again in this form. - $row['Field'] = (isset($field_name[$i]) ? $field_name[$i] : FALSE); - $row['Type'] = (isset($field_type[$i]) ? $field_type[$i] : FALSE); - $row['Collation'] = (isset($field_collation[$i]) ? $field_collation[$i] : ''); - $row['Null'] = (isset($field_null[$i]) ? $field_null[$i] : ''); + $row['Field'] = (isset($_REQUEST['field_name'][$i]) ? $_REQUEST['field_name'][$i] : false); + $row['Type'] = (isset($_REQUEST['field_type'][$i]) ? $_REQUEST['field_type'][$i] : false); + $row['Collation'] = (isset($_REQUEST['field_collation'][$i]) ? $_REQUEST['field_collation'][$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'; - } 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'; - } 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'; + } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'fulltext_' . $i) { + $row['Key'] = 'FULLTEXT'; } else { $row['Key'] = ''; } - $row['Default'] = (isset($field_default[$i]) ? $field_default[$i] : FALSE); - $row['Extra'] = (isset($field_extra[$i]) ? $field_extra[$i] : FALSE); - $row['Comment'] = (isset($submit_fulltext[$i]) && ($submit_fulltext[$i] == $i) ? 'FULLTEXT' : FALSE); + $row['DefaultType'] = (isset($_REQUEST['field_default_type'][$i]) ? $_REQUEST['field_default_type'][$i] : 'USER_DEFINED'); + $row['DefaultValue'] = (isset($_REQUEST['field_default_value'][$i]) ? $_REQUEST['field_default_value'][$i] : ''); - $submit_length = (isset($field_length[$i]) ? $field_length[$i] : FALSE); - $submit_attribute = (isset($field_attribute[$i]) ? $field_attribute[$i] : FALSE); + switch ($row['DefaultType']) { + case 'NONE' : + $row['Default'] = null; + break; + case 'USER_DEFINED' : + $row['Default'] = $row['DefaultValue']; + break; + case 'NULL' : + case 'CURRENT_TIMESTAMP' : + $row['Default'] = $row['DefaultType']; + break; + } + + $row['Extra'] = (isset($_REQUEST['field_extra'][$i]) ? $_REQUEST['field_extra'][$i] : false); + $row['Comment'] = (isset($submit_fulltext[$i]) && ($submit_fulltext[$i] == $i) ? 'FULLTEXT' : false); - $submit_default_current_timestamp = (isset($field_default_current_timestamp[$i]) ? TRUE : 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); - if (isset($field_comments[$i])) { - $comments_map[$row['Field']] = $field_comments[$i]; + $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_mimetype[$i])) { - $mime_map[$row['Field']]['mimetype'] = $field_mimetype[$i]; + if (isset($_REQUEST['field_mimetype'][$i])) { + $mime_map[$row['Field']]['mimetype'] = $_REQUEST['field_mimetype'][$i]; } - if (isset($field_transformation[$i])) { - $mime_map[$row['Field']]['transformation'] = $field_transformation[$i]; + if (isset($_REQUEST['field_transformation'][$i])) { + $mime_map[$row['Field']]['transformation'] = $_REQUEST['field_transformation'][$i]; } - if (isset($field_transformation_options[$i])) { - $mime_map[$row['Field']]['transformation_options'] = $field_transformation_options[$i]; + if (isset($_REQUEST['field_transformation_options'][$i])) { + $mime_map[$row['Field']]['transformation_options'] = $_REQUEST['field_transformation_options'][$i]; } } elseif (isset($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']); if ($type_and_length['type'] == 'bit') { $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; // Everytime a cell shall be left out the STRG-jumping feature, $ci_offset // has to be incremented ($ci_offset++) $ci_offset = -1; + // old column name 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']) : '')); - $content_cells[$i][$ci] = "\n" . '' . "\n"; - } else { - $content_cells[$i][$ci] = ''; + if (! empty($true_selected[$i])) { + $_form_params['field_orig[' . $i . ']'] = $true_selected[$i]; + } elseif (isset($row['Field'])) { + $_form_params['field_orig[' . $i . ']'] = $row['Field']; + } else { + $_form_params['field_orig[' . $i . ']'] = ''; + } } - $content_cells[$i][$ci] .= "\n" . ''; + // column name + $content_cells[$i][$ci] = ''; $ci++; - $content_cells[$i][$ci] = ''; $ci++; + // old column length if ($is_backup) { - $content_cells[$i][$ci] = "\n" . ''; - } else { - $content_cells[$i][$ci] = ''; + $_form_params['field_length_orig[' . $i . ']'] = $length; } + // column length if (preg_match('@^(set|enum)$@i', $type)) { $binary = 0; $unsigned = 0; @@ -292,20 +339,75 @@ for ($i = 0; $i <= $num_fields; $i++) { $length_to_display = htmlspecialchars($length); } else { $length_to_display = $length; - $binary = FALSE; + $binary = false; $unsigned = stristr($row['Type'], 'unsigned'); $zerofill = stristr($row['Type'], 'zerofill'); } - $content_cells[$i][$ci] .= "\n" . '' . "\n"; + $content_cells[$i][$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] = ''; + $content_cells[$i][$ci] .= '
'; + $content_cells[$i][$ci] .= ''; + $ci++; + + // column 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); $ci++; - $content_cells[$i][$ci] = ''; $attribute = ''; if ($binary) { @@ -317,8 +419,11 @@ for ($i = 0; $i <= $num_fields; $i++) { if ($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; } @@ -337,34 +442,29 @@ for ($i = 0; $i <= $num_fields; $i++) { // (if on_update_current_timestamp is set, then it's TRUE) if (isset($row['Field']) && 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']) && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_current_timestamp'])) || (isset($submit_default_current_timestamp) && $submit_default_current_timestamp)) { - $default_current_timestamp = TRUE; + $default_current_timestamp = true; } 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']); - for ($j = 0;$j < $cnt_attribute_types; $j++) { + for ($j = 0; $j < $cnt_attribute_types; $j++) { $content_cells[$i][$ci] .= ' '; } $content_cells[$i][$ci] .= ''; $ci++; + // column NULL $content_cells[$i][$ci] = ''; - } 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] .= ''; - if ($type_upper == 'TIMESTAMP') { - $tmp_display_type = 'block'; - } else { - $tmp_display_type = 'none'; - $default_current_timestamp = FALSE; - } - $content_cells[$i][$ci] .= '
CURRENT_TIMESTAMP
'; - $ci++; - - $content_cells[$i][$ci] = ''; - $ci++; - - + // column indexes // lem9: See my other comment about removing this 'if'. if (!$is_backup) { - if (isset($row) && isset($row['Key']) && $row['Key'] == 'PRI') { - $checked_primary = ' checked="checked"'; - } else { - $checked_primary = ''; + $content_cells[$i][$ci] = ''; - $ci++; - - $content_cells[$i][$ci] = "\n" . ''; - $ci++; - - $content_cells[$i][$ci] = "\n" . ''; - $ci++; - - $content_cells[$i][$ci] = ''; + $content_cells[$i][$ci] .= ''; $ci++; } // end if ($action ==...) - // garvin: comments - $content_cells[$i][$ci] = ''; + // column auto_increment + $content_cells[$i][$ci] = ''; + $ci++; + + // column MIME-types if ($cfgRelation['mimework'] && $cfg['BrowseMIME'] && $cfgRelation['commwork']) { - $content_cells[$i][$ci] = ''; + $content_cells[$i][$ci] .= ' '; if (is_array($available_mime['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] .= ' '; } } @@ -489,21 +543,25 @@ for ($i = 0; $i <= $num_fields; $i++) { $content_cells[$i][$ci] .= ''; $ci++; - $content_cells[$i][$ci] = ''; + $content_cells[$i][$ci] .= ' '; if (is_array($available_mime['transformation'])) { 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 = isset($$tooltip) ? $$tooltip : sprintf(str_replace('
', ' ', $strMIME_nodescription), 'PMA_transformation_' . $tooltip . '()'); - $content_cells[$i][$ci] .= '' . "\n"; + $content_cells[$i][$ci] .= ''; } } $content_cells[$i][$ci] .= ''; $ci++; - $content_cells[$i][$ci] = ''; + $content_cells[$i][$ci] = ''; //$ci++; } } // end for @@ -519,24 +577,7 @@ document.onkeydown = onKeyDownArrowsHandler; -
'; if ($display_type == 'horizontal') { @@ -646,21 +687,21 @@ if ($action == 'tbl_create.php') {     @@ -673,7 +714,10 @@ if ($action == 'tbl_create.php') { - +
- + '); ?> diff --git a/tbl_addfield.php b/tbl_addfield.php index 4316ff6c0..68a0436ce 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); + $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 ($field_where != 'last') { + 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'; } diff --git a/tbl_alter.php b/tbl_alter.php index c69ee2666..0b5b5baed 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -26,13 +26,8 @@ PMA_checkParameters(array('db', 'table')); */ require_once './libraries/tbl_common.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 @@ -44,47 +39,65 @@ $err_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table); * Modifications have been submitted -> updates the table */ $abort = false; -if (isset($do_save_data)) { - $field_cnt = count($field_orig); +if (isset($_REQUEST['do_save_data'])) { + var_dump($_POST); + $field_cnt = count($_REQUEST['field_orig']); + $key_fields = array(); + $changes = array(); + for ($i = 0; $i < $field_cnt; $i++) { - // to """ in tbl_sql.php - $field_orig[$i] = urldecode($field_orig[$i]); - if (strcmp(str_replace('"', '"', $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('"', '"', $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('"', '"', $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], - $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_default_orig[$i]); + $changes[] = 'CHANGE ' . PMA_Table::generateAlter( + $_REQUEST['field_orig'][$i], + $_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] + : '', + $key_fields, + $i, + $_REQUEST['field_default_orig'][$i] + ); } // 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 // on this db. PMA_DBI_select_db($db) or PMA_mysqlDie(PMA_DBI_getError(), 'USE ' . PMA_backquote($db) . ';', '', $err_url); // Optimization fix - 2 May 2001 - Robbat2 - $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . $query; - $error_create = FALSE; - $result = PMA_DBI_try_query($sql_query) or $error_create = TRUE; + $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ' . implode(', ', $changes) . $key_query; + $result = PMA_DBI_try_query($sql_query); - if ($error_create == FALSE) { + if ($result !== false) { $message = PMA_Message::success('strTableAlteredSuccessfully'); $message->addParam($table); $btnDrop = 'Fake'; @@ -93,51 +106,27 @@ if (isset($do_save_data)) { require_once './libraries/relation.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'])) { + foreach ($_REQUEST['field_orig'] as $fieldindex => $fieldcontent) { + if ($_REQUEST['field_name'][$fieldindex] != $fieldcontent) { + PMA_REL_renameField($db, $table, $fieldcontent, + $_REQUEST['field_name'][$fieldindex]); + } + } + } - // garvin: Rename relations&display fields, if altered. - if (($cfgRelation['displaywork'] || $cfgRelation['relwork']) && isset($field_orig) && is_array($field_orig)) { - foreach ($field_orig AS $fieldindex => $fieldcontent) { - if ($field_name[$fieldindex] != $fieldcontent) { - 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']) { - $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) - . ' SET master_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\'' - . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\'' - . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\'' - . ' AND master_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\''; - $tb_rs = PMA_query_as_cu($table_query); - unset($table_query); - unset($tb_rs); - - $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) - . ' 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]); + // update mime types + 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]); } } } @@ -145,12 +134,12 @@ if (isset($do_save_data)) { $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 - if (isset($orig_field)) { - $field = $orig_field; + if (isset($_REQUEST['orig_field'])) { + $_REQUEST['field'] = $_REQUEST['orig_field']; } $regenerate = true; @@ -159,11 +148,13 @@ if (isset($do_save_data)) { /** * No modifications yet required -> displays the table fields + * + * $selected comes from multi_submits.inc.php */ -if ($abort == FALSE) { - if (!isset($selected)) { +if ($abort == false) { + if (! isset($selected)) { PMA_checkParameters(array('field')); - $selected[] = $field; + $selected[] = $_REQUEST['field']; $selected_cnt = 1; } else { // from a multiple submit $selected_cnt = count($selected); @@ -173,12 +164,8 @@ if ($abort == FALSE) { * @todo optimize in case of multiple fields to modify */ for ($i = 0; $i < $selected_cnt; $i++) { - if (!empty($submit_mult)) { - $field = PMA_sqlAddslashes(urldecode($selected[$i]), TRUE); - } else { - $field = PMA_sqlAddslashes($selected[$i], TRUE); - } - $result = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ' LIKE \'' . $field . '\';'); + $_REQUEST['field'] = PMA_sqlAddslashes($selected[$i], true); + $result = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ' LIKE \'' . $_REQUEST['field'] . '\';'); $fields_meta[] = PMA_DBI_fetch_assoc($result); PMA_DBI_free_result($result); } diff --git a/tbl_create.php b/tbl_create.php index 3da4b3a14..b385952e9 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -63,6 +63,16 @@ if (! strlen($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 */ @@ -75,35 +85,47 @@ if (isset($_REQUEST['do_save_data'])) { $sql_query = ''; // 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) { - if (isset(${'field_key_' . $i})) { - if (${'field_key_' . $i} == 'primary_' . $i) { + if (isset($_REQUEST['field_key'][$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 fields creation statements 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); + $query = 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); $query .= ', '; $sql_query .= $query; @@ -116,8 +138,8 @@ if (isset($_REQUEST['do_save_data'])) { $primary_cnt = (isset($field_primary) ? count($field_primary) : 0); 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]) . ', '; + if (isset($_REQUEST['field_name'][$j]) && strlen($_REQUEST['field_name'][$j])) { + $primary .= PMA_backquote($_REQUEST['field_name'][$j]) . ', '; } } // end for unset($primary_cnt); @@ -132,8 +154,8 @@ if (isset($_REQUEST['do_save_data'])) { $index_cnt = (isset($field_index) ? count($field_index) : 0); 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]) . ', '; + if (isset($_REQUEST['field_name'][$j]) && strlen($_REQUEST['field_name'][$j])) { + $index .= PMA_backquote($_REQUEST['field_name'][$j]) . ', '; } } // end for unset($index_cnt); @@ -148,8 +170,8 @@ if (isset($_REQUEST['do_save_data'])) { $unique_cnt = (isset($field_unique) ? count($field_unique) : 0); 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]) . ', '; + if (isset($_REQUEST['field_name'][$j]) && strlen($_REQUEST['field_name'][$j])) { + $unique .= PMA_backquote($_REQUEST['field_name'][$j]) . ', '; } } // end for unset($unique_cnt); @@ -164,8 +186,8 @@ if (isset($_REQUEST['do_save_data'])) { $fulltext_cnt = (isset($field_fulltext) ? count($field_fulltext) : 0); for ($i = 0; $i < $fulltext_cnt; $i++) { $j = $field_fulltext[$i]; - if (isset($field_name[$j]) && strlen($field_name[$j])) { - $fulltext .= PMA_backquote($field_name[$j]) . ', '; + if (isset($_REQUEST['field_name'][$j]) && strlen($_REQUEST['field_name'][$j])) { + $fulltext .= PMA_backquote($_REQUEST['field_name'][$j]) . ', '; } } // end for @@ -180,17 +202,17 @@ if (isset($_REQUEST['do_save_data'])) { . ' (' . $sql_query . ')'; // Adds table type, character set, comments and partition definition - if (!empty($tbl_type) && ($tbl_type != 'Default')) { - $sql_query .= ' ENGINE = ' . $tbl_type; + if (!empty($_REQUEST['tbl_type']) && ($_REQUEST['tbl_type'] != 'Default')) { + $sql_query .= ' ENGINE = ' . $_REQUEST['tbl_type']; } - if (!empty($tbl_collation)) { - $sql_query .= PMA_generateCharsetQueryPart($tbl_collation); + if (!empty($_REQUEST['tbl_collation'])) { + $sql_query .= PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']); } - if (!empty($comment)) { - $sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\''; + if (!empty($_REQUEST['comment'])) { + $sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($_REQUEST['comment']) . '\''; } - if (!empty($partition_definition)) { - $sql_query .= ' ' . PMA_sqlAddslashes($partition_definition); + if (!empty($_REQUEST['partition_definition'])) { + $sql_query .= ' ' . PMA_sqlAddslashes($_REQUEST['partition_definition']); } // Executes the query @@ -202,17 +224,16 @@ if (isset($_REQUEST['do_save_data'])) { 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'] + if (isset($_REQUEST['field_mimetype']) + && is_array($_REQUEST['field_mimetype']) && $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]); + 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]); } } } @@ -235,23 +256,13 @@ if (isset($_REQUEST['do_save_data'])) { // 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; + $num_fields = $_REQUEST['orig_num_fields']; } } // end do create 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'; require './libraries/tbl_properties.inc.php'; // Displays the footer diff --git a/tbl_structure.php b/tbl_structure.php index fafdeef29..948a0b0cf 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -294,7 +294,7 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { // MySQL 4.1.2+ TIMESTAMP options // (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'])) { - $attribute = 'ON UPDATE CURRENT_TIMESTAMP'; + $attribute = 'on update CURRENT_TIMESTAMP'; } // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the