List:Commits« Previous MessageNext Message »
From:Gleb Shchepa Date:October 13 2009 4:50pm
Subject:bzr commit into mysql-5.5.0-next-mr-bugfixing branch (gshchepa:2898)
Bug#33629
View as plain text  
#At file:///work/mysql-next-mr-bugfixing/ based on revid:serg@stripped

 2898 Gleb Shchepa	2009-10-13
      Backport of fix to bug #33629 into mysql-next-mr-bugfixing.
      
      Bug #33629: last_day function can return null, but has 'not null' flag set for result
      
      LAST_DAY and MAKEDATE functions are documented as
      returning NULL value, but actually they was implemented
      as returning NOT NULL typed values.
      
      That caused a confusing error "ERROR 1048 (23000): Column
      '...' cannot be null" on queries like: 
      
        SELECT 1 FROM (SELECT LAST_DAY('0')) a;
     @ mysql-test/r/func_sapdb.result
          Updated test case for bug #33629.
     @ mysql-test/r/func_time.result
          Updated test case for bug #33629.
     @ mysql-test/r/type_date.result
          Added test case for bug #33629.
     @ mysql-test/t/type_date.test
          Added test case for bug #33629.
     @ sql/item_timefunc.h
          Bug #33629: last_day function can return null, but has 'not null' flag set for result
          
          1. The Item_func_makedate::fix_length_and_dec method
             has been modified to declare MAKEDATE() as a function
             returning nullable value.
          2. The Item_func_last_day::fix_length_and_dec method
             has been overloaded for the same purpose.

    modified:
      mysql-test/r/func_sapdb.result
      mysql-test/r/func_time.result
      mysql-test/r/type_date.result
      mysql-test/t/type_date.test
      sql/item_timefunc.h
=== modified file 'mysql-test/r/func_sapdb.result'
--- a/mysql-test/r/func_sapdb.result	2009-02-07 15:50:31 +0000
+++ b/mysql-test/r/func_sapdb.result	2009-10-13 16:50:08 +0000
@@ -194,7 +194,7 @@ date("1997-12-31 23:59:59.000001") as f8
 time("1997-12-31 23:59:59.000001") as f9;
 describe t1;
 Field	Type	Null	Key	Default	Extra
-f1	date	NO		0000-00-00	
+f1	date	YES		NULL	
 f2	datetime	YES		NULL	
 f3	time	YES		NULL	
 f4	time	YES		NULL	

=== modified file 'mysql-test/r/func_time.result'
--- a/mysql-test/r/func_time.result	2009-01-23 12:22:05 +0000
+++ b/mysql-test/r/func_time.result	2009-10-13 16:50:08 +0000
@@ -814,7 +814,7 @@ create table t1 select last_day('2000-02
 from_days(to_days("960101")) as b;
 describe t1;
 Field	Type	Null	Key	Default	Extra
-a	date	NO		0000-00-00	
+a	date	YES		NULL	
 b	date	YES		NULL	
 select * from t1;
 a	b

=== modified file 'mysql-test/r/type_date.result'
--- a/mysql-test/r/type_date.result	2009-01-13 14:04:28 +0000
+++ b/mysql-test/r/type_date.result	2009-10-13 16:50:08 +0000
@@ -276,3 +276,25 @@ a
 0000-00-01
 drop table t1;
 End of 5.1 tests
+#
+# Bug #33629: last_day function can return null, but has 'not null'
+#             flag set for result
+#
+SELECT 1 FROM (SELECT LAST_DAY('0')) a;
+1
+1
+Warnings:
+Warning	1292	Incorrect datetime value: '0'
+SELECT 1 FROM (SELECT MAKEDATE(2011,0)) a;
+1
+1
+CREATE TABLE t1 AS
+SELECT LAST_DAY('1970-01-01') AS f1,
+MAKEDATE(1970, 1)      AS f2;
+DESCRIBE t1;
+Field	Type	Null	Key	Default	Extra
+f1	date	YES		NULL	
+f2	date	YES		NULL	
+DROP TABLE t1;
+#
+End of 6.0 tests

=== modified file 'mysql-test/t/type_date.test'
--- a/mysql-test/t/type_date.test	2009-01-13 14:04:28 +0000
+++ b/mysql-test/t/type_date.test	2009-10-13 16:50:08 +0000
@@ -247,3 +247,21 @@ select * from t1 where a between '0000-0
 drop table t1;
 
 --echo End of 5.1 tests
+
+--echo #
+--echo # Bug #33629: last_day function can return null, but has 'not null'
+--echo #             flag set for result
+--echo #
+
+SELECT 1 FROM (SELECT LAST_DAY('0')) a;
+SELECT 1 FROM (SELECT MAKEDATE(2011,0)) a;
+
+CREATE TABLE t1 AS
+  SELECT LAST_DAY('1970-01-01') AS f1,
+         MAKEDATE(1970, 1)      AS f2;
+DESCRIBE t1;
+DROP TABLE t1;
+
+--echo #
+
+--echo End of 6.0 tests

=== modified file 'sql/item_timefunc.h'
--- a/sql/item_timefunc.h	2009-02-07 15:50:31 +0000
+++ b/sql/item_timefunc.h	2009-10-13 16:50:08 +0000
@@ -871,6 +871,7 @@ public:
   { 
     decimals=0;
     max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
+    maybe_null= 1;
   }
   longlong val_int();
 };
@@ -1025,4 +1026,9 @@ public:
   Item_func_last_day(Item *a) :Item_date(a) {}
   const char *func_name() const { return "last_day"; }
   bool get_date(MYSQL_TIME *res, uint fuzzy_date);
+  void fix_length_and_dec()
+  { 
+    Item_date::fix_length_and_dec();
+    maybe_null= 1;
+  }
 };


Attachment: [text/bzr-bundle] bzr/gshchepa@mysql.com-20091013165008-ay8db1u1u8q4daz5.bundle
Thread
bzr commit into mysql-5.5.0-next-mr-bugfixing branch (gshchepa:2898)Bug#33629Gleb Shchepa13 Oct