summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2014-03-29 11:33:20 +0100
committerSergei Golubchik <sergii@pisem.net>2014-03-29 11:33:20 +0100
commit73f48615754833e637ba05d2a0d92a0ea5c2d5cf (patch)
tree9642317ac9f2a0aa73175a2f6ccacd9ae82b7eea /sql/item.cc
parentb37157e49e7cef7a5f70f4269678ad0c44863d69 (diff)
downloadmariadb-git-73f48615754833e637ba05d2a0d92a0ea5c2d5cf.tar.gz
MDEV-5969 Crash in prepared statement with NO_ZERO_IN_DATE and ROLLUP
MDEV-5971 Asymmetry between CAST(DATE'2001-00-00') to INT and TO CHAR in prepared statements Consistently set maybe_null flag, even not-NULL temporal literal may become NULL in the restrictive sql_mode.
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc29
1 files changed, 23 insertions, 6 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 7c04dc00880..9b27f730e80 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -341,12 +341,29 @@ String *Item::val_string_from_decimal(String *str)
}
+/*
+ All val_xxx_from_date() must call this method, to expose consistent behaviour
+ regarding SQL_MODE when converting DATE/DATETIME to other data types.
+*/
+bool Item::get_temporal_with_sql_mode(MYSQL_TIME *ltime)
+{
+ return get_date(ltime, field_type() == MYSQL_TYPE_TIME
+ ? TIME_TIME_ONLY
+ : sql_mode_for_dates(current_thd));
+}
+
+
+bool Item::is_null_from_temporal()
+{
+ MYSQL_TIME ltime;
+ return get_temporal_with_sql_mode(&ltime);
+}
+
+
String *Item::val_string_from_date(String *str)
{
MYSQL_TIME ltime;
- if (get_date(&ltime, field_type() == MYSQL_TYPE_TIME
- ? TIME_TIME_ONLY
- : sql_mode_for_dates(current_thd)) ||
+ if (get_temporal_with_sql_mode(&ltime) ||
str->alloc(MAX_DATE_STRING_REP_LENGTH))
{
null_value= 1;
@@ -403,7 +420,7 @@ my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- if (get_date(&ltime, sql_mode_for_dates(current_thd)))
+ if (get_temporal_with_sql_mode(&ltime))
{
my_decimal_set_zero(decimal_value);
null_value= 1; // set NULL, stop processing
@@ -430,7 +447,7 @@ longlong Item::val_int_from_date()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- if (get_date(&ltime, 0))
+ if (get_temporal_with_sql_mode(&ltime))
return 0;
longlong v= TIME_to_ulonglong(&ltime);
return ltime.neg ? -v : v;
@@ -441,7 +458,7 @@ double Item::val_real_from_date()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- if (get_date(&ltime, 0))
+ if (get_temporal_with_sql_mode(&ltime))
return 0;
return TIME_to_double(&ltime);
}