diff options
author | Sergei Golubchik <sergii@pisem.net> | 2011-03-19 15:19:05 +0100 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2011-03-19 15:19:05 +0100 |
commit | 299b29b27300f7c4c6600deaf077a98e322fdc86 (patch) | |
tree | 4e30a023265305872a37c50c511f9834bf3bf5de | |
parent | a67bf98f02237e39a475bedc362e8fc28dbe44fb (diff) | |
download | mariadb-git-299b29b27300f7c4c6600deaf077a98e322fdc86.tar.gz |
lp:738091 cast(timestamp() AS time returns NULL for 0000-00-00 00:00:00 in 5.1-micro
-rw-r--r-- | mysql-test/r/func_time.result | 6 | ||||
-rw-r--r-- | mysql-test/t/func_time.test | 9 | ||||
-rw-r--r-- | sql/field.cc | 20 |
3 files changed, 29 insertions, 6 deletions
diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 9e04078f1ee..0b20b7e9b61 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -1539,3 +1539,9 @@ NULL select timestamp(greatest('2002-08-20', '0000-00-00 00:00:00')); timestamp(greatest('2002-08-20', '0000-00-00 00:00:00')) 2002-08-20 00:00:00 +create table t1 (f1 datetime); +insert into t1 values ('0000-00-00 00:00:00'); +select cast(f1 AS time) from t1; +cast(f1 AS time) +00:00:00 +drop table t1; diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 70451e98763..cf725893505 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -977,3 +977,12 @@ select day(coalesce(null)); # lp:738067 Crash in get_datetime_value() in 5.1-micro # select timestamp(greatest('2002-08-20', '0000-00-00 00:00:00')); + +# +# lp:738091 cast(timestamp() AS time returns NULL for 0000-00-00 00:00:00 in 5.1-micro +# +create table t1 (f1 datetime); +insert into t1 values ('0000-00-00 00:00:00'); +select cast(f1 AS time) from t1; +drop table t1; + diff --git a/sql/field.cc b/sql/field.cc index f7675b82a99..352dd187bb9 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5870,10 +5870,10 @@ bool Field_newdate::get_date(MYSQL_TIME *ltime,uint fuzzydate) ltime->year= (tmp >> 9); ltime->time_type= MYSQL_TIMESTAMP_DATE; ltime->hour= ltime->minute= ltime->second= ltime->second_part= ltime->neg= 0; - if ((fuzzydate & TIME_NO_ZERO_DATE) && !tmp) - return 1; - if (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) - return 1; + if (!tmp) + return fuzzydate & TIME_NO_ZERO_DATE; + if (!ltime->month || !ltime->day) + return !(fuzzydate & TIME_FUZZY_DATE); return 0; } @@ -6003,7 +6003,11 @@ bool Field_datetime::get_date(MYSQL_TIME *ltime, uint fuzzydate) ltime->day= (int) (part1%100); ltime->month= (int) (part1/100%100); ltime->year= (int) (part1/10000); - return (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ? 1 : 0; + if (!tmp) + return fuzzydate & TIME_NO_ZERO_DATE; + if (!ltime->month || !ltime->day) + return !(fuzzydate & TIME_FUZZY_DATE); + return 0; } int Field_datetime::cmp(const uchar *a_ptr, const uchar *b_ptr) @@ -6110,7 +6114,11 @@ bool Field_datetime_hires::get_date(MYSQL_TIME *ltime, uint fuzzydate) { ulonglong packed= read_bigendian(ptr, Field_datetime_hires::pack_length()); unpack_time(sec_part_unshift(packed, dec), ltime); - return (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ? 1 : 0; + if (!packed) + return fuzzydate & TIME_NO_ZERO_DATE; + if (!ltime->month || !ltime->day) + return !(fuzzydate & TIME_FUZZY_DATE); + return 0; } uint32 Field_datetime_hires::pack_length() const |