diff options
-rw-r--r-- | mysql-test/r/type_time.result | 14 | ||||
-rw-r--r-- | mysql-test/t/type_time.test | 11 | ||||
-rw-r--r-- | sql/item_func.h | 7 | ||||
-rw-r--r-- | sql/item_sum.cc | 12 | ||||
-rw-r--r-- | sql/item_sum.h | 1 |
5 files changed, 45 insertions, 0 deletions
diff --git a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result index 2aabd98229d..8b80177104d 100644 --- a/mysql-test/r/type_time.result +++ b/mysql-test/r/type_time.result @@ -1245,5 +1245,19 @@ a b c 2070 00:00:00 00:00:00 DROP TABLE t1,t2; # +# MDEV-10817 CAST(MAX(DATE'2001-01-01') AS TIME) returns a wrong result +# +SELECT CAST(DATE'2001-01-01' AS TIME); +CAST(DATE'2001-01-01' AS TIME) +00:00:00 +SELECT CAST(MAX(DATE'2001-01-01') AS TIME); +CAST(MAX(DATE'2001-01-01') AS TIME) +00:00:00 +CREATE FUNCTION f1() RETURNS DATE RETURN DATE'2001-01-01'; +SELECT CAST(f1() AS TIME); +CAST(f1() AS TIME) +00:00:00 +DROP FUNCTION f1; +# # End of 10.2 tests # diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test index fb96597e296..6841af41e11 100644 --- a/mysql-test/t/type_time.test +++ b/mysql-test/t/type_time.test @@ -747,5 +747,16 @@ DROP TABLE t1,t2; --echo # +--echo # MDEV-10817 CAST(MAX(DATE'2001-01-01') AS TIME) returns a wrong result +--echo # + +SELECT CAST(DATE'2001-01-01' AS TIME); +SELECT CAST(MAX(DATE'2001-01-01') AS TIME); +CREATE FUNCTION f1() RETURNS DATE RETURN DATE'2001-01-01'; +SELECT CAST(f1() AS TIME); +DROP FUNCTION f1; + + +--echo # --echo # End of 10.2 tests --echo # diff --git a/sql/item_func.h b/sql/item_func.h index bee6dc4e524..ef703456818 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -2367,6 +2367,13 @@ public: return sp_result_field->val_decimal(dec_buf); } + bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) + { + if (execute()) + return true; + return sp_result_field->get_date(ltime, fuzzydate); + } + String *val_str(String *str) { String buf; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index df09beeb274..20237435ba6 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -2065,6 +2065,18 @@ void Item_sum_hybrid::clear() null_value= 1; } +bool +Item_sum_hybrid::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +{ + DBUG_ASSERT(fixed == 1); + if (null_value) + return 0; + bool retval= value->get_date(ltime, fuzzydate); + if ((null_value= value->null_value)) + DBUG_ASSERT(retval == true); + return retval; +} + double Item_sum_hybrid::val_real() { DBUG_ASSERT(fixed == 1); diff --git a/sql/item_sum.h b/sql/item_sum.h index 0c655ded153..5c446e5779d 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -1037,6 +1037,7 @@ protected: double val_real(); longlong val_int(); my_decimal *val_decimal(my_decimal *); + bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); void reset_field(); String *val_str(String *); bool keep_field_type(void) const { return 1; } |