summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagne Mahre <magne.mahre@sun.com>2009-11-04 11:28:50 +0100
committerMagne Mahre <magne.mahre@sun.com>2009-11-04 11:28:50 +0100
commita5d74eb1b406e20658a1ef9ff5ac8add7b0b1c96 (patch)
tree89f1a72c5bd26b657a9b24896dea90ca82b014cc
parent6f5418515fb479ea2a2537d454f8938052a947ed (diff)
downloadmariadb-git-a5d74eb1b406e20658a1ef9ff5ac8add7b0b1c96.tar.gz
Bug#42664: Sign ignored for TIME types when not comparing as longlong
Another code-path dropped sign of TIME, presuming all time is positive. Minds sign now. Patch depends on ChangeSet for 42661. mysql-test/r/type_time.result: Show we now no longer ignore sign of TIME-type in this code-path. mysql-test/t/type_time.test: Show we now no longer ignore sign of TIME-type in this code-path. sql/item_cmpfunc.cc: TIME_to_ulonglong() (somewhat obviously) loses sign of its argument, so we put it back in where needed.
-rw-r--r--mysql-test/r/type_time.result25
-rw-r--r--mysql-test/t/type_time.test21
-rw-r--r--sql/item_cmpfunc.cc3
3 files changed, 47 insertions, 2 deletions
diff --git a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result
index e4b90196c2d..a5880f2b452 100644
--- a/mysql-test/r/type_time.result
+++ b/mysql-test/r/type_time.result
@@ -85,6 +85,7 @@ sec_to_time(time_to_sec(t))
13:00:00
09:00:00
drop table t1;
+End of 4.1 tests
select cast('100:55:50' as time) < cast('24:00:00' as time);
cast('100:55:50' as time) < cast('24:00:00' as time)
0
@@ -138,3 +139,27 @@ CAST(c AS TIME)
00:00:00
DROP TABLE t1;
End of 5.0 tests
+CREATE TABLE t1 (f1 TIME);
+INSERT INTO t1 VALUES ('24:00:00');
+SELECT '24:00:00' = (SELECT f1 FROM t1);
+'24:00:00' = (SELECT f1 FROM t1)
+1
+SELECT CAST('24:00:00' AS TIME) = (SELECT f1 FROM t1);
+CAST('24:00:00' AS TIME) = (SELECT f1 FROM t1)
+1
+SELECT CAST('-24:00:00' AS TIME) = (SELECT f1 FROM t1);
+CAST('-24:00:00' AS TIME) = (SELECT f1 FROM t1)
+0
+TRUNCATE t1;
+INSERT INTO t1 VALUES ('-24:00:00');
+SELECT CAST('24:00:00' AS TIME) = (SELECT f1 FROM t1);
+CAST('24:00:00' AS TIME) = (SELECT f1 FROM t1)
+0
+SELECT CAST('-24:00:00' AS TIME) = (SELECT f1 FROM t1);
+CAST('-24:00:00' AS TIME) = (SELECT f1 FROM t1)
+1
+SELECT '-24:00:00' = (SELECT f1 FROM t1);
+'-24:00:00' = (SELECT f1 FROM t1)
+1
+DROP TABLE t1;
+End of 6.0 tests
diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test
index 5bb521601e5..3cec27d7782 100644
--- a/mysql-test/t/type_time.test
+++ b/mysql-test/t/type_time.test
@@ -39,7 +39,7 @@ drop table t1;
# SELECT CAST(0.2359591234567e+30 AS TIME);
# ##########################################################
-# End of 4.1 tests
+--echo End of 4.1 tests
#
# Bug#29555: Comparing time values as strings may lead to a wrong result.
@@ -90,3 +90,22 @@ DROP TABLE t1;
--echo End of 5.0 tests
+
+
+#
+# Bug#42664 - Sign ignored for TIME types when not comparing as longlong
+#
+
+CREATE TABLE t1 (f1 TIME);
+INSERT INTO t1 VALUES ('24:00:00');
+SELECT '24:00:00' = (SELECT f1 FROM t1);
+SELECT CAST('24:00:00' AS TIME) = (SELECT f1 FROM t1);
+SELECT CAST('-24:00:00' AS TIME) = (SELECT f1 FROM t1);
+TRUNCATE t1;
+INSERT INTO t1 VALUES ('-24:00:00');
+SELECT CAST('24:00:00' AS TIME) = (SELECT f1 FROM t1);
+SELECT CAST('-24:00:00' AS TIME) = (SELECT f1 FROM t1);
+SELECT '-24:00:00' = (SELECT f1 FROM t1);
+DROP TABLE t1;
+
+--echo End of 6.0 tests
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index c29031d25b5..07160b8307a 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -829,7 +829,8 @@ get_time_value(THD *thd, Item ***item_arg, Item **cache_arg,
else
{
*is_null= item->get_time(&ltime);
- value= !*is_null ? (longlong) TIME_to_ulonglong_datetime(&ltime) : 0;
+ value= !*is_null ? (longlong) TIME_to_ulonglong_datetime(&ltime) *
+ (ltime.neg ? -1 : 1) : 0;
}
/*
Do not cache GET_USER_VAR() function as its const_item() may return TRUE