Skip to content

Commit

Permalink
MDEV-10817 CAST(MAX(DATE'2001-01-01') AS TIME) returns a wrong result
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Barkov committed Nov 7, 2017
1 parent 8128ae4 commit fff7fc5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mysql-test/r/type_time.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
11 changes: 11 additions & 0 deletions mysql-test/t/type_time.test
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,17 @@ SELECT * FROM t1;
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 #
7 changes: 7 additions & 0 deletions sql/item_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,13 @@ class Item_func_sp :public Item_func
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;
Expand Down
12 changes: 12 additions & 0 deletions sql/item_sum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions sql/item_sum.h
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ class Item_sum_hybrid :public Item_sum, public Type_handler_hybrid_field_type
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; }
Expand Down

0 comments on commit fff7fc5

Please sign in to comment.