diff options
author | evgen@moonbone.local <> | 2007-07-20 00:06:35 +0400 |
---|---|---|
committer | evgen@moonbone.local <> | 2007-07-20 00:06:35 +0400 |
commit | 08b9103d71c0d400b3741d2f48f8f763b96a1320 (patch) | |
tree | c289f957a8353fed4b3b04d0291bdd114445733c | |
parent | 7a2491871d61a2a64bc496eecbcbcbc56fe5471c (diff) | |
download | mariadb-git-08b9103d71c0d400b3741d2f48f8f763b96a1320.tar.gz |
Bug#29898: Item_date_typecast::val_int doesn't reset the null_value flag.
The Item_date_typecast::val_int function doesn't reset null_value flag.
This makes all values that follows the first null value to be treated as nulls
and led to a wrong result.
Now the Item_date_typecast::val_int function correctly sets the null_value flag
for both null and non-null values.
-rw-r--r-- | mysql-test/r/cast.result | 11 | ||||
-rw-r--r-- | mysql-test/t/cast.test | 9 | ||||
-rw-r--r-- | sql/item_timefunc.cc | 5 |
3 files changed, 21 insertions, 4 deletions
diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result index 6eceeff87e2..524ff48d69e 100644 --- a/mysql-test/r/cast.result +++ b/mysql-test/r/cast.result @@ -403,4 +403,15 @@ hex(cast('a' as binary(2))) select hex(cast('a' as char(2) binary)); hex(cast('a' as char(2) binary)) 61 +CREATE TABLE t1 (d1 datetime); +INSERT INTO t1(d1) VALUES ('2007-07-19 08:30:00'), (NULL), +('2007-07-19 08:34:00'), (NULL), ('2007-07-19 08:36:00'); +SELECT cast(date(d1) as signed) FROM t1; +cast(date(d1) as signed) +20070719 +NULL +20070719 +NULL +20070719 +drop table t1; End of 5.0 tests diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index b665eb86656..316b79efe4d 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -237,4 +237,13 @@ select hex(cast('a' as char(2) binary)); select hex(cast('a' as binary(2))); select hex(cast('a' as char(2) binary)); +# +# Bug#29898: Item_date_typecast::val_int doesn't reset the null_value flag. +# +CREATE TABLE t1 (d1 datetime); +INSERT INTO t1(d1) VALUES ('2007-07-19 08:30:00'), (NULL), + ('2007-07-19 08:34:00'), (NULL), ('2007-07-19 08:36:00'); +SELECT cast(date(d1) as signed) FROM t1; +drop table t1; + --echo End of 5.0 tests diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 9795ec5f413..873e2833a1e 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2662,11 +2662,8 @@ longlong Item_date_typecast::val_int() { DBUG_ASSERT(fixed == 1); MYSQL_TIME ltime; - if (args[0]->get_date(<ime, TIME_FUZZY_DATE)) - { - null_value= 1; + if ((null_value= args[0]->get_date(<ime, TIME_FUZZY_DATE))) return 0; - } return (longlong) (ltime.year * 10000L + ltime.month * 100 + ltime.day); } |