List:Commits« Previous MessageNext Message »
From:eugene Date:July 12 2007 7:09pm
Subject:bk commit into 5.0 tree (evgen:1.2535) BUG#29739
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-12 23:09:55+04:00, evgen@stripped +3 -0
  Bug#29739: Incorrect time comparison in BETWEEN.
  
  Time values were compared by the BETWEEN function as strings. This led to a
  wrong result in cases when some of arguments are less than 100 hours and other
  are greater.
  
  Now if all 3 arguments of the BETWEEN function are of the TIME type then
  they are compared as integers.

  mysql-test/r/type_time.result@stripped, 2007-07-12 23:07:49+04:00, evgen@stripped +6 -0
    Added a tes tcase for the bug#29739: Incorrect time comparison in BETWEEN.

  mysql-test/t/type_time.test@stripped, 2007-07-12 23:07:34+04:00, evgen@stripped +8 -0
    Added a tes tcase for the bug#29739: Incorrect time comparison in BETWEEN.

  sql/item_cmpfunc.cc@stripped, 2007-07-12 23:08:13+04:00, evgen@stripped +16 -8
    Bug#29739: Incorrect time comparison in BETWEEN.
    Now if all 3 arguments of the BETWEEN function are of the TIME type then
    they are compared as integers.

diff -Nrup a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result
--- a/mysql-test/r/type_time.result	2007-07-11 23:17:48 +04:00
+++ b/mysql-test/r/type_time.result	2007-07-12 23:07:49 +04:00
@@ -103,3 +103,9 @@ cast('100:55:50' as time) > cast('024:00
 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
+create table t1(f1 time, f2 time);
+insert into t1 values('20:00:00','150:00:00');
+select 1 from t1 where cast('100:00:00' as time) between f1 and f2;
+1
+1
+drop table t1;
diff -Nrup a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test
--- a/mysql-test/t/type_time.test	2007-07-11 23:17:50 +04:00
+++ b/mysql-test/t/type_time.test	2007-07-12 23:07:34 +04:00
@@ -50,3 +50,11 @@ select cast('300:55:50' as time) < cast(
 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);
+
+#
+# Bug#29739: Incorrect time comparison in BETWEEN.
+#
+create table t1(f1 time, f2 time);
+insert into t1 values('20:00:00','150:00:00');
+select 1 from t1 where cast('100:00:00' as time) between f1 and f2;
+drop table t1;
diff -Nrup a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
--- a/sql/item_cmpfunc.cc	2007-07-11 23:17:33 +04:00
+++ b/sql/item_cmpfunc.cc	2007-07-12 23:08:13 +04:00
@@ -1728,6 +1728,7 @@ void Item_func_between::fix_length_and_d
   THD *thd= current_thd;
   int i;
   bool datetime_found= FALSE;
+  int time_items_found= 0;
   compare_as_dates= TRUE;
 
   /*
@@ -1747,17 +1748,19 @@ void Item_func_between::fix_length_and_d
     At least one of items should be a DATE/DATETIME item and other items
     should return the STRING result.
   */
-  for (i= 0; i < 3; i++)
+  if (cmp_type == STRING_RESULT)
   {
-    if (args[i]->is_datetime())
+    for (i= 0; i < 3; i++)
     {
-      datetime_found= TRUE;
-      continue;
+      if (args[i]->is_datetime())
+      {
+        datetime_found= TRUE;
+        continue;
+      }
+      if (args[i]->field_type() == MYSQL_TYPE_TIME &&
+          args[i]->result_as_longlong())
+        time_items_found++;
     }
-    if (args[i]->result_type() == STRING_RESULT)
-      continue;
-    compare_as_dates= FALSE;
-    break;
   }
   if (!datetime_found)
     compare_as_dates= FALSE;
@@ -1766,6 +1769,11 @@ void Item_func_between::fix_length_and_d
   {
     ge_cmp.set_datetime_cmp_func(args, args + 1);
     le_cmp.set_datetime_cmp_func(args, args + 2);
+  }
+  else if (time_items_found == 3)
+  {
+    /* Compare TIME items as integers. */
+    cmp_type= INT_RESULT;
   }
   else if (args[0]->real_item()->type() == FIELD_ITEM &&
            thd->lex->sql_command != SQLCOM_CREATE_VIEW &&
Thread
bk commit into 5.0 tree (evgen:1.2535) BUG#29739eugene12 Jul