Commit 829b1747 authored by Sergei Golubchik's avatar Sergei Golubchik

make sure that cast(... as date) returns a valid date, as specified by the caller.

make Item::send() request a date according to the current SQL mode limitations.
parent af3a05df
...@@ -733,3 +733,8 @@ select cast(f1 as unsigned), cast(f2 as unsigned), cast(f3 as unsigned) from t1; ...@@ -733,3 +733,8 @@ select cast(f1 as unsigned), cast(f2 as unsigned), cast(f3 as unsigned) from t1;
cast(f1 as unsigned) cast(f2 as unsigned) cast(f3 as unsigned) cast(f1 as unsigned) cast(f2 as unsigned) cast(f3 as unsigned)
112233 20111213 20111213112233 112233 20111213 20111213112233
drop table t1; drop table t1;
SELECT CAST(TIME('10:20:30') AS DATE) + INTERVAL 1 DAY;
CAST(TIME('10:20:30') AS DATE) + INTERVAL 1 DAY
NULL
Warnings:
Warning 1292 Truncated incorrect date value: '0000-00-00'
...@@ -407,3 +407,8 @@ insert into t1 values ('11:22:33','2011-12-13','2011-12-13 11:22:33'); ...@@ -407,3 +407,8 @@ insert into t1 values ('11:22:33','2011-12-13','2011-12-13 11:22:33');
select cast(f1 as unsigned), cast(f2 as unsigned), cast(f3 as unsigned) from t1; select cast(f1 as unsigned), cast(f2 as unsigned), cast(f3 as unsigned) from t1;
drop table t1; drop table t1;
#
# CAST(... AS DATE) and invalid dates
#
SELECT CAST(TIME('10:20:30') AS DATE) + INTERVAL 1 DAY;
...@@ -5982,7 +5982,7 @@ bool Item::send(Protocol *protocol, String *buffer) ...@@ -5982,7 +5982,7 @@ bool Item::send(Protocol *protocol, String *buffer)
case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_TIMESTAMP:
{ {
MYSQL_TIME tm; MYSQL_TIME tm;
get_date(&tm, TIME_FUZZY_DATE); get_date(&tm, TIME_FUZZY_DATE | sql_mode_for_dates());
if (!null_value) if (!null_value)
{ {
if (f_type == MYSQL_TYPE_DATE) if (f_type == MYSQL_TYPE_DATE)
......
...@@ -2304,7 +2304,17 @@ bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date) ...@@ -2304,7 +2304,17 @@ bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
return 1; return 1;
ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0; ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
ltime->time_type= MYSQL_TIMESTAMP_DATE; ltime->time_type= MYSQL_TIMESTAMP_DATE;
return 0;
int unused;
if (check_date(ltime, ltime->year || ltime->month || ltime->day,
fuzzy_date, &unused))
{
Lazy_string_time str(ltime);
make_truncated_value_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
&str, MYSQL_TIMESTAMP_DATE, 0);
return (null_value= 1);
}
return (null_value= 0);
} }
......
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