MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:eugene Date:May 3 2007 8:53pm
Subject:bk commit into 4.1 tree (evgen:1.2652) BUG#23656
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 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-05-04 00:53:37+04:00, evgen@stripped +3 -0
  Bug#23656: Wrong conversion result of a DATETIME to integer using CAST function.
  
  The generic string to int conversion was used by the Item_func_signed and
  the Item_func_unsigned classes to convert DATE/DATETIME values to the
  SIGNED/UNSIGNED type. But this conversion produces wrong results for such
  values.
  
  Now if the item which result has to be converted can return its result as
  longlong then the item->val_int() method is used to allow the item to carry
  out the conversion itself and return the correct result.
  This condition is checked in the Item_func_signed::val_int() and the
  Item_func_unsigned::val_int() functions.

  mysql-test/r/cast.result@stripped, 2007-05-04 00:52:13+04:00, evgen@stripped +6 -0
    Added a test case for the bug#23656: Wrong conversion result of a DATETIME to integer using CAST function.

  mysql-test/t/cast.test@stripped, 2007-05-04 00:48:19+04:00, evgen@stripped +6 -0
    Added a test case for the bug#23656: Wrong conversion result of a DATETIME to integer using CAST function.

  sql/item_func.cc@stripped, 2007-05-04 00:52:56+04:00, evgen@stripped +4 -2
    Bug#23656: Wrong conversion result of a DATETIME to integer using CAST function.
    Now if the item which result has to be converted can return its result as
    longlong then the item->val_int() method is used to allow the item to carry
    out the conversion itself and return the correct result.
    This condition is checked in the Item_func_signed::val_int() and the
    Item_func_unsigned::val_int() functions.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	evgen
# Host:	moonbone.local
# Root:	/mnt/gentoo64/work/23656-bug-4.1-opt-mysql

--- 1.275/sql/item_func.cc	2007-04-13 01:31:32.000000000 +0400
+++ 1.276/sql/item_func.cc	2007-05-04 00:52:56.000000000 +0400
@@ -477,7 +477,8 @@
   longlong value;
   int error;
 
-  if (args[0]->cast_to_int_type() != STRING_RESULT)
+  if (args[0]->cast_to_int_type() != STRING_RESULT ||
+      args[0]->result_as_longlong())
   {
     value= args[0]->val_int();
     null_value= args[0]->null_value; 
@@ -529,7 +530,8 @@
     return (longlong)  (dvalue + (dvalue > 0 ? 0.5 : -0.5));
   }
 
-  if (args[0]->cast_to_int_type() != STRING_RESULT)
+  if (args[0]->cast_to_int_type() != STRING_RESULT ||
+      args[0]->result_as_longlong())
   {
     value= args[0]->val_int();
     null_value= args[0]->null_value; 

--- 1.29/mysql-test/r/cast.result	2006-12-04 16:06:22.000000000 +0300
+++ 1.30/mysql-test/r/cast.result	2007-05-04 00:52:13.000000000 +0400
@@ -281,4 +281,10 @@
 select isnull(date(NULL)), isnull(cast(NULL as DATE));
 isnull(date(NULL))	isnull(cast(NULL as DATE))
 1	1
+SELECT CAST(cast('01-01-01' as date) AS UNSIGNED);
+CAST(cast('01-01-01' as date) AS UNSIGNED)
+20010101
+SELECT CAST(cast('01-01-01' as date) AS SIGNED);
+CAST(cast('01-01-01' as date) AS SIGNED)
+20010101
 End of 4.1 tests

--- 1.23/mysql-test/t/cast.test	2006-12-04 16:06:23.000000000 +0300
+++ 1.24/mysql-test/t/cast.test	2007-05-04 00:48:19.000000000 +0400
@@ -173,4 +173,10 @@
 
 select isnull(date(NULL)), isnull(cast(NULL as DATE));
 
+#
+# Bug#23656: Wrong result of CAST from DATE to int
+#
+SELECT CAST(cast('01-01-01' as date) AS UNSIGNED);
+SELECT CAST(cast('01-01-01' as date) AS SIGNED);
+
 --echo End of 4.1 tests
Thread
bk commit into 4.1 tree (evgen:1.2652) BUG#23656eugene3 May