From fe8cd66697716f8dae9c38e374074f6b7d8191a4 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 22 May 2005 12:43:46 +0000 Subject: [PATCH] bug #1163595, NULL detection for TIMESTAMP --- ChangeLog | 2 ++ libraries/sqlparser.lib.php | 11 +++++++++++ tbl_properties.inc.php | 10 +++++++++- tbl_properties_structure.php | 10 +++++++++- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index efb668b9f..9f7ae7a98 100755 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,8 @@ $Source$ 2005-05-22 Marc Delisle * libraries/charset_conversion.lib.php: diacritics wrongly converted in Browse mode under MySQL 4.1.x if AllowAnywhereRecoding set to TRUE + * tbl_properties_structure.php, tbl_properties.inc.php, + libraries/sqlparser.lib.php: bug #1163595, NULL detection of TIMESTAMP 2005-05-19 Marc Delisle * tbl_select.php: bug #1204235, searching on a VARBINARY field diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index 359cd927e..6aa54d475 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -802,10 +802,14 @@ if ($is_minimum_common == FALSE) { * For now, mostly used to detect the DEFAULT CURRENT_TIMESTAMP and * ON UPDATE CURRENT_TIMESTAMP clauses of the CREATE TABLE query. * An array, each element is the identifier name. + * Note that for now, the timestamp_not_null element is created + * even for non-TIMESTAMP fields. + * * Sub-elements: ['type'] which contains the column type * optional (currently they are never false but can be absent): * ['default_current_timestamp'] boolean * ['on_update_current_timestamp'] boolean + * ['timestamp_not_null'] boolean * * section_before_limit, section_after_limit * ----------------------------------------- @@ -1560,6 +1564,11 @@ if ($is_minimum_common == FALSE) { if ($arr[$i]['type'] == 'alpha_reservedWord') { $upper_data = strtoupper($arr[$i]['data']); + if ($upper_data == 'NOT' && $in_timestamp_options) { + $create_table_fields[$current_identifier]['timestamp_not_null'] = TRUE; + + } + if ($upper_data == 'CREATE') { $seen_create = TRUE; } @@ -1707,6 +1716,8 @@ if ($is_minimum_common == FALSE) { if ($seen_create_table && $in_create_table_fields) { $current_identifier = $identifier; + // warning: we set this one even for non TIMESTAMP type + $create_table_fields[$current_identifier]['timestamp_not_null'] = FALSE; } if ($seen_constraint) { diff --git a/tbl_properties.inc.php b/tbl_properties.inc.php index 01661b296..7621fc4ff 100644 --- a/tbl_properties.inc.php +++ b/tbl_properties.inc.php @@ -2,7 +2,7 @@ /* $Id$ */ // vim: expandtab sw=4 ts=4 sts=4: // Check parameters -error_reporting(E_ALL); + require_once('./libraries/common.lib.php'); PMA_checkParameters(array('db','table','action','num_fields')); @@ -342,6 +342,14 @@ for ($i = 0 ; $i < $num_fields; $i++) { $attribute = $submit_attribute; } + // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the + // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe + // the latter. + if ($analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null'] == TRUE) { + $row['Null'] = ''; + } + + // MySQL 4.1.2+ TIMESTAMP options // (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'])) { diff --git a/tbl_properties_structure.php b/tbl_properties_structure.php index c58f936ae..5f9b0b68e 100644 --- a/tbl_properties_structure.php +++ b/tbl_properties_structure.php @@ -198,7 +198,7 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { $zerofill = stristr($row['Type'], 'zerofill'); } - // rabus: Devide charset from the rest of the type definition (MySQL >= 4.1) + // rabus: Divide charset from the rest of the type definition (MySQL >= 4.1) unset($field_charset); if (PMA_MYSQL_INT_VERSION >= 40100) { if ((substr($type, 0, 4) == 'char' @@ -247,6 +247,14 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { $attribute = 'ON UPDATE CURRENT_TIMESTAMP'; } + // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the + // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe + // the latter. + if ($analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null']) { + $row['Null'] = ''; + } + + if (!isset($row['Default'])) { if ($row['Null'] == 'YES') { $row['Default'] = 'NULL';