summaryrefslogtreecommitdiff
path: root/mysql-test/t/func_time.test
diff options
context:
space:
mode:
authorEvgeny Potemkin <epotemkin@mysql.com>2010-10-07 11:07:56 +0400
committerEvgeny Potemkin <epotemkin@mysql.com>2010-10-07 11:07:56 +0400
commit3c9c7efb3b9f505e3db5b2dc2fdef30893f7d5f0 (patch)
treefaa94ed990e76cab367149941d91bce0b95a772d /mysql-test/t/func_time.test
parent32de99125a2fa6aace8650e8a4a1a5087fcf614a (diff)
downloadmariadb-git-3c9c7efb3b9f505e3db5b2dc2fdef30893f7d5f0.tar.gz
Bug#57039: constant subtime expression returns incorrect result.
The subtime function wasn't able to produce correct int representation of its result. For constant expressions the Item_datetime_cache is used to speedup evaluation and Item_datetime_cache expects underlying item to return correct int representation of DATETIME value. These two factors combined led to a wrong query result. Now the Item_func_add_time has function val_datetime which performs the calculation and saves result into given MYSQL_TIME struct, it also sets null_value to appropriate value. val_int and val_str member functions convert the result obtained from val_datetime to int or string respectively and returns it. mysql-test/r/func_time.result: Added a test case for the bug#57039. mysql-test/t/func_time.test: Added a test case for the bug#57039. sql/item_timefunc.cc: Bug#57039: constant subtime expression returns incorrect result. Now the Item_func_add_time has function val_datetime which performs the calculation and saves result into given MYSQL_TIME struct, it also sets null_value to appropriate value. val_int and val_str member functions convert the result obtained from val_datetime to int or string respectively and returns it. sql/item_timefunc.h: Bug#57039: constant subtime expression returns incorrect result.
Diffstat (limited to 'mysql-test/t/func_time.test')
-rw-r--r--mysql-test/t/func_time.test11
1 files changed, 11 insertions, 0 deletions
diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test
index 1f6001219a3..08c09adb093 100644
--- a/mysql-test/t/func_time.test
+++ b/mysql-test/t/func_time.test
@@ -833,3 +833,14 @@ SELECT 1 FROM t1 ORDER BY @x:=makedate(a,a);
DROP TABLE t1;
--echo End of 5.1 tests
+
+--echo #
+--echo # Bug#57039: constant subtime expression returns incorrect result.
+--echo #
+CREATE TABLE t1 (`date_date` datetime NOT NULL);
+INSERT INTO t1 VALUES ('2008-01-03 00:00:00'), ('2008-01-03 00:00:00');
+SELECT * FROM t1 WHERE date_date >= subtime(now(), "00:30:00");
+SELECT * FROM t1 WHERE date_date <= addtime(date_add("2000-1-1", INTERVAL "1:1:1" HOUR_SECOND), "00:20:00");
+DROP TABLE t1;
+--echo #
+