Commit 5ff5c4b8 authored by Sergei Golubchik's avatar Sergei Golubchik

lp:737111 Different behavior for TIMESTAMPADD with 0000-00-00 argument in 5.1-micro

respect fuzzydate flags in Item_*::get_date() methods
parent 1a963822
......@@ -1501,3 +1501,14 @@ create table t1 (f1 timestamp);
select * from t1 where f1 > f1 and f1 <=> timestampadd(hour, 9 , '2010-01-01 16:55:35');
f1
drop table t1;
create table t1 (f1 date);
insert into t1 values ('0000-00-00');
select timestampadd(week, 1, f1) from t1;
timestampadd(week, 1, f1)
NULL
select timestampadd(week, 1, date("0000-00-00"));
timestampadd(week, 1, date("0000-00-00"))
NULL
Warnings:
Warning 1292 Incorrect datetime value: '0000-00-00'
drop table t1;
......@@ -944,3 +944,13 @@ select now() > coalesce(time('21:43:24'), date('2010-05-03'));
create table t1 (f1 timestamp);
select * from t1 where f1 > f1 and f1 <=> timestampadd(hour, 9 , '2010-01-01 16:55:35');
drop table t1;
#
# lp:737111 Different behavior for TIMESTAMPADD with 0000-00-00 argument in 5.1-micro
#
create table t1 (f1 date);
insert into t1 values ('0000-00-00');
select timestampadd(week, 1, f1) from t1;
select timestampadd(week, 1, date("0000-00-00"));
drop table t1;
......@@ -5869,8 +5869,11 @@ 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;
return ((!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ?
1 : 0);
if ((fuzzydate & TIME_NO_ZERO_DATE) && !tmp)
return 1;
if (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day))
return 1;
return 0;
}
......
......@@ -2309,7 +2309,7 @@ bool Item_time_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
{
if (get_arg0_date(ltime, TIME_FUZZY_DATE))
if (get_arg0_date(ltime, fuzzy_date & ~TIME_TIME_ONLY))
return 1;
ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
ltime->time_type= MYSQL_TIMESTAMP_DATE;
......@@ -2318,11 +2318,11 @@ bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
{
if (get_arg0_date(ltime, TIME_FUZZY_DATE))
if (get_arg0_date(ltime, fuzzy_date & ~TIME_TIME_ONLY))
return 1;
/*
ltime is valid MYSQL_TYPE_TIME ( according to fuzzy_date).
ltime is valid MYSQL_TYPE_TIME (according to fuzzy_date).
But not every valid TIME value is a valid DATETIME value!
*/
if (ltime->time_type == MYSQL_TIMESTAMP_TIME && ltime->hour >= 24)
......
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