Commit 5044bc9c authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-454 Addition of a time interval reduces the resulting value

1. Field_newdate::get_date should refuse to return a date with zeros when
   TIME_NO_ZERO_IN_DATE is set, not when TIME_FUZZY_DATE is unset
2. Item_func_to_days and Item_date_add_interval can only work with valid dates,
   no zeros allowed.
parent df46e34d
create table t1 (d date);
insert into t1 values ('2012-00-00');
select * from t1;
d
2012-00-00
update t1 set d = adddate(d, interval 1 day);
select * from t1;
d
NULL
drop table t1;
#
# MDEV-454 Addition of a time interval reduces the resulting value
#
create table t1 (d date);
insert into t1 values ('2012-00-00');
select * from t1;
update t1 set d = adddate(d, interval 1 day);
select * from t1;
drop table t1;
...@@ -5789,7 +5789,7 @@ bool Field_newdate::get_date(MYSQL_TIME *ltime,uint fuzzydate) ...@@ -5789,7 +5789,7 @@ bool Field_newdate::get_date(MYSQL_TIME *ltime,uint fuzzydate)
if (!tmp) if (!tmp)
return fuzzydate & TIME_NO_ZERO_DATE; return fuzzydate & TIME_NO_ZERO_DATE;
if (!ltime->month || !ltime->day) if (!ltime->month || !ltime->day)
return !(fuzzydate & TIME_FUZZY_DATE); return fuzzydate & TIME_NO_ZERO_IN_DATE;
return 0; return 0;
} }
......
...@@ -751,7 +751,7 @@ longlong Item_func_to_days::val_int() ...@@ -751,7 +751,7 @@ longlong Item_func_to_days::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE)) if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE))
return 0; return 0;
return (longlong) calc_daynr(ltime.year,ltime.month,ltime.day); return (longlong) calc_daynr(ltime.year,ltime.month,ltime.day);
} }
...@@ -1932,7 +1932,7 @@ bool Item_date_add_interval::get_date(MYSQL_TIME *ltime, uint fuzzy_date) ...@@ -1932,7 +1932,7 @@ bool Item_date_add_interval::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
{ {
INTERVAL interval; INTERVAL interval;
if (args[0]->get_date(ltime, TIME_NO_ZERO_DATE | TIME_FUZZY_DATE) || if (args[0]->get_date(ltime, TIME_NO_ZERO_DATE | TIME_FUZZY_DATE | TIME_NO_ZERO_IN_DATE) ||
get_interval_value(args[1], int_type, &value, &interval)) get_interval_value(args[1], int_type, &value, &interval))
return (null_value=1); return (null_value=1);
......
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