MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:eugene Date:July 11 2007 7:18pm
Subject:bk commit into 5.0 tree (evgen:1.2527) BUG#29555
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of evgen. When evgen does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-07-11 23:18:02+04:00, evgen@stripped +3 -0
  Bug#29555: Comparing time values as strings may lead to a wrong result.
  
  Time values were compared as strings. This led to a wrong comparison
  result when comparing values one of which is under 100 hours and another is
  over 100 hours.
  
  Now when the Arg_comparator::set_cmp_func function sees that both items to
  compare are of the TIME type it sets the comparator to the
  Arg_comparator::compare_e_int or the Arg_comparator::compare_int_unsigned
  functions.

  mysql-test/r/type_time.result@stripped, 2007-07-11 23:17:48+04:00, evgen@stripped +18 -0
    Added a test case for the bug#29555: Comparing time values as strings may
    lead to a wrong result.

  mysql-test/t/type_time.test@stripped, 2007-07-11 23:17:50+04:00, evgen@stripped +10 -0
    Added a test case for the bug#29555: Comparing time values as strings may
    lead to a wrong result.

  sql/item_cmpfunc.cc@stripped, 2007-07-11 23:17:33+04:00, evgen@stripped +12 -0
    Bug#29555: Comparing time values as strings may lead to a wrong result.
    Now when the Arg_comparator::set_cmp_func function sees that both items to
    compare are of the TIME type it sets the comparator to the
    Arg_comparator::compare_e_int or the Arg_comparator::compare_int_unsigned
    functions.

diff -Nrup a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result
--- a/mysql-test/r/type_time.result	2006-01-10 19:22:35 +03:00
+++ b/mysql-test/r/type_time.result	2007-07-11 23:17:48 +04:00
@@ -85,3 +85,21 @@ sec_to_time(time_to_sec(t))
 13:00:00
 09:00:00
 drop table t1;
+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
+select cast('100:55:50' as time) < cast('024:00:00' as time);
+cast('100:55:50' as time) < cast('024:00:00' as time)
+0
+select cast('300:55:50' as time) < cast('240:00:00' as time);
+cast('300:55:50' as time) < cast('240:00:00' as time)
+0
+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)
+1
+select cast('100:55:50' as time) > cast('024:00:00' as time);
+cast('100:55:50' as time) > cast('024:00:00' as time)
+1
+select cast('300:55:50' as time) > cast('240:00:00' as time);
+cast('300:55:50' as time) > cast('240:00:00' as time)
+1
diff -Nrup a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test
--- a/mysql-test/t/type_time.test	2006-01-10 17:55:54 +03:00
+++ b/mysql-test/t/type_time.test	2007-07-11 23:17:50 +04:00
@@ -40,3 +40,13 @@ drop table t1;
 # ##########################################################
 
 # End of 4.1 tests
+
+#
+# Bug#29555: Comparing time values as strings may lead to a wrong result.
+#
+select cast('100:55:50' as time) < cast('24:00:00' as time);
+select cast('100:55:50' as time) < cast('024:00:00' as time);
+select cast('300:55:50' as time) < cast('240:00:00' as time);
+select cast('100:55:50' as time) > cast('24:00:00' as time);
+select cast('100:55:50' as time) > cast('024:00:00' as time);
+select cast('300:55:50' as time) > cast('240:00:00' as time);
diff -Nrup a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
--- a/sql/item_cmpfunc.cc	2007-06-14 15:37:35 +04:00
+++ b/sql/item_cmpfunc.cc	2007-07-11 23:17:33 +04:00
@@ -706,6 +706,18 @@ int Arg_comparator::set_cmp_func(Item_bo
     func= &Arg_comparator::compare_datetime;
     return 0;
   }
+  else if (type == STRING_RESULT && (*a)->field_type() == MYSQL_TYPE_TIME &&
+           (*b)->field_type() == MYSQL_TYPE_TIME)
+  {
+    /* Compare TIME values as integers. */
+    thd= current_thd;
+    owner= owner_arg;
+    func= ((test(owner && owner->functype() == Item_func::EQUAL_FUNC)) ?
+           &Arg_comparator::compare_e_int :
+           &Arg_comparator::compare_int_unsigned);
+    return 0;
+  }
+
   return set_compare_func(owner_arg, type);
 }
 
Thread
bk commit into 5.0 tree (evgen:1.2527) BUG#29555eugene11 Jul