diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 45c05f0b5b5..32f930ca6ba 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -1207,3 +1207,17 @@ SET NAMES DEFAULT; select str_to_date('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE; str_to_date('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE NULL +CREATE TABLE t1 (a int, t1 time, t2 time, d date, PRIMARY KEY (a)); +INSERT INTO t1 VALUES (1, '10:00:00', NULL, NULL), +(2, '11:00:00', '11:15:00', '1972-02-06'); +SELECT t1, t2, SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) ), QUARTER(d) +FROM t1; +t1 t2 SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) ) QUARTER(d) +10:00:00 NULL NULL NULL +11:00:00 11:15:00 00:15:00 1 +SELECT t1, t2, SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) ), QUARTER(d) +FROM t1 ORDER BY a DESC; +t1 t2 SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) ) QUARTER(d) +11:00:00 11:15:00 00:15:00 1 +10:00:00 NULL NULL NULL +DROP TABLE t1; diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index a69cbb67c5b..1aa4b434a83 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -713,3 +713,15 @@ SET NAMES DEFAULT; # select str_to_date('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE; + +# +# Bug #25643: SEC_TO_TIME function problem +# +CREATE TABLE t1 (a int, t1 time, t2 time, d date, PRIMARY KEY (a)); +INSERT INTO t1 VALUES (1, '10:00:00', NULL, NULL), + (2, '11:00:00', '11:15:00', '1972-02-06'); +SELECT t1, t2, SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) ), QUARTER(d) + FROM t1; +SELECT t1, t2, SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) ), QUARTER(d) + FROM t1 ORDER BY a DESC; +DROP TABLE t1; diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index e99db62068d..83b48645d1c 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1054,7 +1054,8 @@ longlong Item_func_quarter::val_int() { DBUG_ASSERT(fixed == 1); TIME ltime; - (void) get_arg0_date(<ime, TIME_FUZZY_DATE); + if (get_arg0_date(<ime, TIME_FUZZY_DATE)) + return 0; return (longlong) ((ltime.month+2)/3); } @@ -1668,6 +1669,7 @@ String *Item_func_sec_to_time::val_str(String *str) { DBUG_ASSERT(fixed == 1); TIME ltime; + longlong arg_val= args[0]->val_int(); if ((null_value=args[0]->null_value) || str->alloc(19)) { @@ -1675,7 +1677,7 @@ String *Item_func_sec_to_time::val_str(String *str) return (String*) 0; } - sec_to_time(args[0]->val_int(), args[0]->unsigned_flag, <ime); + sec_to_time(arg_val, args[0]->unsigned_flag, <ime); make_time((DATE_TIME_FORMAT *) 0, <ime, str); return str; @@ -1686,11 +1688,12 @@ longlong Item_func_sec_to_time::val_int() { DBUG_ASSERT(fixed == 1); TIME ltime; + longlong arg_val= args[0]->val_int(); if ((null_value=args[0]->null_value)) return 0; - sec_to_time(args[0]->val_int(), args[0]->unsigned_flag, <ime); + sec_to_time(arg_val, args[0]->unsigned_flag, <ime); return (ltime.neg ? -1 : 1) * ((ltime.hour)*10000 + ltime.minute*100 + ltime.second);