From ad48d9f31cd21a42e08a0b06f14b78b6be8660fb Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Fri, 13 Nov 2009 11:14:10 +0000 Subject: [PATCH] bug #2895894 [structure] Empty default value not set properly --- ChangeLog | 1 + libraries/sqlparser.lib.php | 4 +++- libraries/tbl_properties.inc.php | 12 +++++++++--- tbl_alter.php | 26 +++++++++++--------------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1fcd1baa62..48cb769901 100644 --- a/ChangeLog +++ b/ChangeLog @@ -56,6 +56,7 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA - bug #2893931 [lang] Typo and empty message + [lang] Russian update, thanks to Victor Volkov - bug #2823599 [edit] UUID Primary Key wrongly updated +- bug #2895894 [structure] Empty default value not set properly 3.2.3.0 (2009-10-30) - patch #2856664 [export] Date, time, and datetime column types now export correctly to diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index b9d9da8767..581062aac2 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -922,8 +922,9 @@ if (! defined('PMA_MINIMUM_COMMON')) { * create_table_fields * ------------------- * - * For now, mostly used to detect the DEFAULT CURRENT_TIMESTAMP and + * Used to detect the DEFAULT CURRENT_TIMESTAMP and * ON UPDATE CURRENT_TIMESTAMP clauses of the CREATE TABLE query. + * Also used to store the default value of the field. * An array, each element is the identifier name. * Note that for now, the timestamp_not_null element is created * even for non-TIMESTAMP fields. @@ -1898,6 +1899,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { if ($seen_create_table && $in_create_table_fields) { if ($upper_data == 'DEFAULT') { $seen_default = TRUE; + $create_table_fields[$current_identifier]['default_value'] = $arr[$i + 1]['data']; } } } diff --git a/libraries/tbl_properties.inc.php b/libraries/tbl_properties.inc.php index 3e3a5fe3f4..43b4fe027b 100644 --- a/libraries/tbl_properties.inc.php +++ b/libraries/tbl_properties.inc.php @@ -222,10 +222,16 @@ for ($i = 0; $i < $num_fields; $i++) { case null: if ($row['Null'] == 'YES') { $row['DefaultType'] = 'NULL'; + $row['DefaultValue'] = ''; + // SHOW FULL FIELDS does not report the case when there is a DEFAULT value + // which is empty so we need to use the results of SHOW CREATE TABLE + } elseif (isset($row) && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_value'])) { + $row['DefaultType'] = 'USER_DEFINED'; + $row['DefaultValue'] = $row['Default']; } else { $row['DefaultType'] = 'NONE'; + $row['DefaultValue'] = ''; } - $row['DefaultValue'] = ''; break; case 'CURRENT_TIMESTAMP': $row['DefaultType'] = 'CURRENT_TIMESTAMP'; @@ -388,9 +394,9 @@ for ($i = 0; $i < $num_fields; $i++) { 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP', ); - // for a TIMESTAMP, do not show CURRENT_TIMESTAMP as a default value + // for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default value if ($type_upper == 'TIMESTAMP' - && $default_current_timestamp + && ! empty($default_current_timestamp) && isset($row['Default'])) { $row['Default'] = ''; } diff --git a/tbl_alter.php b/tbl_alter.php index 53a1628c2a..a399073c8c 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -176,27 +176,23 @@ if ($abort == false) { $num_fields = count($fields_meta); $action = 'tbl_alter.php'; - // Get more complete field information - // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options - // but later, if the analyser returns more information, it - // could be executed for any MySQL version and replace - // the info given by SHOW FULL FIELDS FROM. + // Get more complete field information. + // For now, this is done to obtain MySQL 4.1.2+ new TIMESTAMP options + // and to know when there is an empty DEFAULT value. + // Later, if the analyser returns more information, it + // could be executed to replace the info given by SHOW FULL FIELDS FROM. /** * @todo put this code into a require() * or maybe make it part of PMA_DBI_get_fields(); */ - if (PMA_MYSQL_INT_VERSION < 50025) { - // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since - // SHOW FULL FIELDS says NULL and SHOW CREATE TABLE says NOT NULL (tested - // in MySQL 4.0.25). - - $show_create_table = PMA_DBI_fetch_value( - 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), - 0, 1); - $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); - } + // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since + // SHOW FULL FIELDS says NULL and SHOW CREATE TABLE says NOT NULL (tested + // in MySQL 4.0.25). + $show_create_table = PMA_DBI_fetch_value('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), 0, 1); + $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); + unset($show_create_table); /** * Form for changing properties. */ -- 2.11.4.GIT