summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2011-09-29 20:12:57 +0200
committerSergei Golubchik <sergii@pisem.net>2011-09-29 20:12:57 +0200
commit829b1747f9acc3dee0061b6bd4ebaeb38bd7f2f2 (patch)
tree9d17482559f0b4a0baf1eea0cf05d28a2eca3864
parentaf3a05dfbec291c256dc22aea6993822fa93af5e (diff)
downloadmariadb-git-829b1747f9acc3dee0061b6bd4ebaeb38bd7f2f2.tar.gz
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.
-rw-r--r--mysql-test/r/cast.result5
-rw-r--r--mysql-test/t/cast.test5
-rw-r--r--sql/item.cc2
-rw-r--r--sql/item_timefunc.cc12
4 files changed, 22 insertions, 2 deletions
diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result
index 877a6badc16..2576fe8fa63 100644
--- a/mysql-test/r/cast.result
+++ b/mysql-test/r/cast.result
@@ -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)
112233 20111213 20111213112233
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'
diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test
index b1e2d23b654..eeb87190ec1 100644
--- a/mysql-test/t/cast.test
+++ b/mysql-test/t/cast.test
@@ -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;
drop table t1;
+#
+# CAST(... AS DATE) and invalid dates
+#
+SELECT CAST(TIME('10:20:30') AS DATE) + INTERVAL 1 DAY;
+
diff --git a/sql/item.cc b/sql/item.cc
index a4cd292a5b1..8710b8f9024 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -5982,7 +5982,7 @@ bool Item::send(Protocol *protocol, String *buffer)
case MYSQL_TYPE_TIMESTAMP:
{
MYSQL_TIME tm;
- get_date(&tm, TIME_FUZZY_DATE);
+ get_date(&tm, TIME_FUZZY_DATE | sql_mode_for_dates());
if (!null_value)
{
if (f_type == MYSQL_TYPE_DATE)
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index f69d77ad6b5..0f12f6755ed 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -2304,7 +2304,17 @@ bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
return 1;
ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
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);
}