#At file:///misc/mysql/forest/42664/50-42664/ based on revid:azundris@stripped
2740 Tatiana A. Nurnberg 2009-02-09
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.
modified:
mysql-test/r/type_time.result
mysql-test/t/type_time.test
sql/item_cmpfunc.cc
per-file messages:
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.
=== modified file 'mysql-test/r/type_time.result'
--- a/mysql-test/r/type_time.result 2007-07-15 17:51:36 +0000
+++ b/mysql-test/r/type_time.result 2009-02-09 18:37:45 +0000
@@ -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
@@ -128,3 +129,27 @@ SELECT sum(f3) FROM t1 where f2='2007-07
sum(f3)
3
drop table t1;
+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 5.0 tests
=== modified file 'mysql-test/t/type_time.test'
--- a/mysql-test/t/type_time.test 2007-07-15 17:51:36 +0000
+++ b/mysql-test/t/type_time.test 2009-02-09 18:37:45 +0000
@@ -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.
@@ -77,3 +77,21 @@ insert into t1 values('2007-07-02', 1);
insert into t1 values('2007-07-02', 2);
SELECT sum(f3) FROM t1 where f2='2007-07-01 00:00:00' group by f2;
drop table t1;
+
+#
+# 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 5.0 tests
=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc 2009-01-15 11:08:09 +0000
+++ b/sql/item_cmpfunc.cc 2009-02-09 18:37:45 +0000
@@ -761,7 +761,8 @@ get_time_value(THD *thd, Item ***item_ar
else
{
*is_null= item->get_time(<ime);
- value= !*is_null ? (longlong) TIME_to_ulonglong_datetime(<ime) : 0;
+ value= !*is_null ? (longlong) TIME_to_ulonglong_datetime(<ime) *
+ (ltime.neg ? -1 : 1) : 0;
}
/*
Do not cache GET_USER_VAR() function as its const_item() may return TRUE
| Thread |
|---|
| • bzr commit into mysql-5.0-bugteam branch (azundris:2740) Bug#42664 | Tatiana A. Nurnberg | 9 Feb |