Commit 299b29b2 authored by Sergei Golubchik's avatar Sergei Golubchik

lp:738091 cast(timestamp() AS time returns NULL for 0000-00-00 00:00:00 in 5.1-micro

parent a67bf98f
......@@ -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;
......@@ -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;
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment