List:Commits« Previous MessageNext Message »
From:Tatiana A. Nurnberg Date:January 30 2009 4:12pm
Subject:bzr commit into mysql-5.0-bugteam branch (azundris:2728) Bug#41370
View as plain text  
#At file:///misc/mysql/forest/41370/50-41370/ based on revid:azundris@stripped

 2728 Tatiana A. Nurnberg	2009-01-30
      Bug#41370: TIMESTAMP field does not accepts NULL from FROM_UNIXTIME()
      
      When storing a NULL to a TIMESTAMP NOT NULL DEFAULT ...,
      NULL returned from some functions threw a 'cannot be NULL error.'
      
      NULL-returns now correctly result in the timestamp-field being
      assigned its default value.
modified:
  mysql-test/r/type_timestamp.result
  mysql-test/t/type_timestamp.test
  sql/item.cc

per-file messages:
  mysql-test/r/type_timestamp.result
    Show that for TIMESTAMP NOT NULL DEFAULT, NULL function returns
    set default now.
  mysql-test/t/type_timestamp.test
    Show that for TIMESTAMP NOT NULL DEFAULT, NULL function returns
    set default now.
  sql/item.cc
    When storing a returned NULL (from a time- or date-related
    function), make sure to apply NULL-means-DEFAULT magic where
    applicable.
=== modified file 'mysql-test/r/type_timestamp.result'
--- a/mysql-test/r/type_timestamp.result	2006-12-13 09:19:19 +0000
+++ b/mysql-test/r/type_timestamp.result	2009-01-30 16:12:24 +0000
@@ -492,6 +492,7 @@ a	b	c
 5	NULL	2001-09-09 04:46:59
 6	NULL	2006-06-06 06:06:06
 drop table t1;
+End of 4.1 tests
 set time_zone= @@global.time_zone;
 CREATE TABLE t1 (
 `id` int(11) NOT NULL auto_increment,
@@ -508,3 +509,21 @@ select is_nullable from INFORMATION_SCHE
 is_nullable
 NO
 drop table t1;
+CREATE TABLE t1 ( f1 INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
+f2 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
+f3 TIMESTAMP);
+INSERT INTO t1 (f2,f3) VALUES (NOW(), "0000-00-00 00:00:00");
+INSERT INTO t1 (f2,f3) VALUES (NOW(), NULL);
+INSERT INTO t1 (f2,f3) VALUES (NOW(), ASCII(NULL));
+INSERT INTO t1 (f2,f3) VALUES (NOW(), FROM_UNIXTIME('9999999999'));
+INSERT INTO t1 (f2,f3) VALUES (NOW(), TIME(NULL));
+UPDATE t1 SET f2=NOW(), f3=FROM_UNIXTIME('9999999999') WHERE f1=1;
+SELECT f1,f2-f3 FROM t1;
+f1	f2-f3
+1	0
+2	0
+3	0
+4	0
+5	0
+DROP TABLE t1;
+End of 5.0 tests

=== modified file 'mysql-test/t/type_timestamp.test'
--- a/mysql-test/t/type_timestamp.test	2006-08-08 08:34:27 +0000
+++ b/mysql-test/t/type_timestamp.test	2009-01-30 16:12:24 +0000
@@ -324,7 +324,7 @@ insert into t1 (a, c) values (4, '2004-0
 select * from t1;
 drop table t1;
 
-# End of 4.1 tests
+--echo End of 4.1 tests
 
 # Restore timezone to default
 set time_zone= @@global.time_zone;
@@ -339,3 +339,21 @@ PRIMARY KEY (`id`)
 show fields from t1;
 select is_nullable from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='t1' and COLUMN_NAME='posted_on';
 drop table t1;
+
+#
+# Bug#41370: TIMESTAMP field does not accepts NULL from FROM_UNIXTIME()
+#
+
+CREATE TABLE t1 ( f1 INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
+                  f2 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
+                  f3 TIMESTAMP);
+INSERT INTO t1 (f2,f3) VALUES (NOW(), "0000-00-00 00:00:00");
+INSERT INTO t1 (f2,f3) VALUES (NOW(), NULL);
+INSERT INTO t1 (f2,f3) VALUES (NOW(), ASCII(NULL));
+INSERT INTO t1 (f2,f3) VALUES (NOW(), FROM_UNIXTIME('9999999999'));
+INSERT INTO t1 (f2,f3) VALUES (NOW(), TIME(NULL));
+UPDATE t1 SET f2=NOW(), f3=FROM_UNIXTIME('9999999999') WHERE f1=1;
+SELECT f1,f2-f3 FROM t1;
+DROP TABLE t1;
+
+--echo End of 5.0 tests

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2008-12-09 18:35:02 +0000
+++ b/sql/item.cc	2009-01-30 16:12:24 +0000
@@ -321,7 +321,7 @@ int Item::save_time_in_field(Field *fiel
 {
   MYSQL_TIME ltime;
   if (get_time(&ltime))
-    return set_field_to_null(field);
+    return set_field_to_null_with_conversions(field, 0);
   field->set_notnull();
   return field->store_time(&ltime, MYSQL_TIMESTAMP_TIME);
 }
@@ -331,7 +331,7 @@ int Item::save_date_in_field(Field *fiel
 {
   MYSQL_TIME ltime;
   if (get_date(&ltime, TIME_FUZZY_DATE))
-    return set_field_to_null(field);
+    return set_field_to_null_with_conversions(field, 0);
   field->set_notnull();
   return field->store_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
 }

Thread
bzr commit into mysql-5.0-bugteam branch (azundris:2728) Bug#41370Tatiana A. Nurnberg30 Jan