MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:February 4 2008 2:39pm
Subject:bk commit into 5.1 tree (anozdrin:1.2663) BUG#18834
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of anozdrin.  When anozdrin does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-02-04 17:39:14+03:00, anozdrin@quad. +3 -0
  A patch for Bug#18834: ALTER TABLE ADD INDEX on table with
  two timestamp fields.
  
  The actual problem here was that CREATE TABLE allowed zero
  date as a default value for a TIMESTAMP column in NO_ZERO_DATE mode.
  
  The thing is that for TIMESTAMP date type specific rule is applied:
    column_name TIMESTAMP == column_name TIMESTAMP DEFAULT 0
  whever for any other date data type
    column_name TYPE == column_name TYPE DEFAULT NULL
  
  The fix is to raise an error when we're in NO_ZERO_DATE mode and
  there is TIMESTAMP column w/o default value.

  mysql-test/r/create.result@stripped, 2008-02-04 17:39:12+03:00, anozdrin@quad. +22 -0
    Update result file.

  mysql-test/t/create.test@stripped, 2008-02-04 17:39:12+03:00, anozdrin@quad. +34 -0
    Test case for Bug#18834: ALTER TABLE ADD INDEX on table with
    two timestamp fields.

  sql/unireg.cc@stripped, 2008-02-04 17:39:13+03:00, anozdrin@quad. +26 -0
    Report an error if NO_ZERO_MODE is set and we have zero date
    as a default.

diff -Nrup a/mysql-test/r/create.result b/mysql-test/r/create.result
--- a/mysql-test/r/create.result	2007-12-13 14:49:51 +03:00
+++ b/mysql-test/r/create.result	2008-02-04 17:39:12 +03:00
@@ -1743,4 +1743,26 @@ t1	CREATE TABLE `t1` (
   `MAXLEN` bigint(3) NOT NULL DEFAULT '0'
 ) ENGINE=MEMORY DEFAULT CHARSET=utf8
 drop table t1;
+# --
+# -- Bug#18834: ALTER TABLE ADD INDEX on table with two timestamp fields
+# --
+
+DROP TABLE IF EXISTS t1;
+
+SET sql_mode = NO_ZERO_DATE;
+
+CREATE TABLE t1(c1 TIMESTAMP, c2 TIMESTAMP DEFAULT 0);
+ERROR 42000: Invalid default value for 'c2'
+
+CREATE TABLE t1(c1 TIMESTAMP, c2 TIMESTAMP);
+ERROR 42000: Invalid default value for 'c2'
+
+# -- Check that NULL column still can be created.
+CREATE TABLE t1(c1 TIMESTAMP NULL);
+
+# -- Cleanup.
+SET sql_mode = '';
+DROP TABLE t1;
+
+# -- End of Bug#18834.
 End of 5.1 tests
diff -Nrup a/mysql-test/t/create.test b/mysql-test/t/create.test
--- a/mysql-test/t/create.test	2007-12-13 14:49:52 +03:00
+++ b/mysql-test/t/create.test	2008-02-04 17:39:12 +03:00
@@ -1341,4 +1341,38 @@ create table t1 like information_schema.
 show create table t1;
 drop table t1;
 
+--echo # --
+--echo # -- Bug#18834: ALTER TABLE ADD INDEX on table with two timestamp fields
+--echo # --
+--echo
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+--echo
+
+SET sql_mode = NO_ZERO_DATE;
+
+--echo
+--error ER_INVALID_DEFAULT
+CREATE TABLE t1(c1 TIMESTAMP, c2 TIMESTAMP DEFAULT 0);
+
+--echo
+--error ER_INVALID_DEFAULT
+CREATE TABLE t1(c1 TIMESTAMP, c2 TIMESTAMP);
+
+--echo
+--echo # -- Check that NULL column still can be created.
+CREATE TABLE t1(c1 TIMESTAMP NULL);
+
+--echo
+--echo # -- Cleanup.
+
+SET sql_mode = '';
+DROP TABLE t1;
+
+--echo
+--echo # -- End of Bug#18834.
+
 --echo End of 5.1 tests
diff -Nrup a/sql/unireg.cc b/sql/unireg.cc
--- a/sql/unireg.cc	2008-01-19 22:32:45 +03:00
+++ b/sql/unireg.cc	2008-02-04 17:39:13 +03:00
@@ -959,6 +959,7 @@ static bool make_empty_rec(THD *thd, Fil
                                 field->save_interval ? field->save_interval :
                                 field->interval, 
                                 field->field_name);
+
     if (!regfield)
     {
       error= 1;
@@ -992,6 +993,31 @@ static bool make_empty_rec(THD *thd, Fil
         delete regfield; //To avoid memory leak
         goto err;
       }
+    }
+    else if (thd->variables.sql_mode & MODE_NO_ZERO_DATE &&
+             !field->def &&
+             field->sql_type == MYSQL_TYPE_TIMESTAMP &&
+             (field->flags & NOT_NULL_FLAG) &&
+             (type == Field::NONE || type == Field::TIMESTAMP_UN_FIELD))
+    {
+      /*
+        An error should be reported if:
+          - NO_ZERO_DATE SQL mode is active;
+          - there is no explicit DEFAULT clause (default column value);
+          - this is a TIMESTAMP column;
+          - the column is not NULL;
+          - this is not the DEFAULT CURRENT_TIMESTAMP column.
+
+        In other words, an error should be reported if
+          - NO_ZERO_DATE SQL mode is active;
+          - the column definition is equivalent to
+            'column_name TIMESTAMP DEFAULT 0'.
+      */
+
+      my_error(ER_INVALID_DEFAULT, MYF(0), regfield->field_name);
+      error= 1;
+      delete regfield; //To avoid memory leak
+      goto err;
     }
     else if (regfield->real_type() == MYSQL_TYPE_ENUM &&
 	     (field->flags & NOT_NULL_FLAG))
Thread
bk commit into 5.1 tree (anozdrin:1.2663) BUG#18834Alexander Nozdrin4 Feb
  • Re: bk commit into 5.1 tree (anozdrin:1.2663) BUG#18834Konstantin Osipov6 Feb