List:Internals« Previous MessageNext Message »
From:Jim Winstead Date:March 8 2005 1:48am
Subject:bk commit into 4.1 tree (jimw:1.2090) BUG#7036
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of jimw. When jimw 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
  1.2090 05/03/07 16:48:22 jimw@stripped +4 -0
  Fix CAST(<value> AS UNSIGNED) to handle large integer values
  passed within strings. (Bug #7036)

  sql/item_func.h
    1.120 05/03/07 16:48:18 jimw@stripped +13 -0
    Signal to the argument of CAST(<value> AS UNSIGNED) that we
    want an unsigned result.

  sql/item.h
    1.173 05/03/07 16:48:18 jimw@stripped +6 -2
    Use unsigned_flag to decide whether to call my_strntoull() or
    my_strntoll() in conversion of string to integer.

  mysql-test/t/cast.test
    1.16 05/03/07 16:48:18 jimw@stripped +5 -0
    Add new regression test

  mysql-test/r/cast.result
    1.22 05/03/07 16:48:18 jimw@stripped +6 -0
    Add new results

# 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:	jimw
# Host:	rama.(none)
# Root:	/home/jimw/my/mysql-4.1-7036

--- 1.172/sql/item.h	2005-03-04 02:16:24 -08:00
+++ 1.173/sql/item.h	2005-03-07 16:48:18 -08:00
@@ -723,8 +723,12 @@
   {
     DBUG_ASSERT(fixed == 1);
     int err;
-    return my_strntoll(str_value.charset(), str_value.ptr(),
-		       str_value.length(), 10, (char**) 0, &err);
+    if (unsigned_flag)
+      return my_strntoull(str_value.charset(), str_value.ptr(),
+                          str_value.length(), 10, (char**) 0, &err);
+    else
+      return my_strntoll(str_value.charset(), str_value.ptr(),
+                         str_value.length(), 10, (char**) 0, &err);
   }
   String *val_str(String*)
   {

--- 1.119/sql/item_func.h	2005-02-22 02:51:19 -08:00
+++ 1.120/sql/item_func.h	2005-03-07 16:48:18 -08:00
@@ -243,6 +243,19 @@
 public:
   Item_func_unsigned(Item *a) :Item_func_signed(a) {}
   const char *func_name() const { return "cast_as_unsigned"; }
+  longlong val_int()
+  {
+    /*
+      We temporarily set the unsigned_flag on our argument as a hint that it
+      should give us an unsigned result from val_int().
+    */
+    my_bool uf= args[0]->unsigned_flag;
+    args[0]->unsigned_flag= TRUE;
+    longlong tmp= args[0]->val_int();
+    null_value= args[0]->null_value; 
+    args[0]->unsigned_flag= uf;
+    return tmp;
+  }
   void fix_length_and_dec()
   { max_length=args[0]->max_length; unsigned_flag=1; }
   void print(String *str);

--- 1.21/mysql-test/r/cast.result	2004-12-30 02:38:29 -08:00
+++ 1.22/mysql-test/r/cast.result	2005-03-07 16:48:18 -08:00
@@ -187,3 +187,9 @@
 select timediff(cast('1 12:00:00' as time), '12:00:00');
 timediff(cast('1 12:00:00' as time), '12:00:00')
 24:00:00
+select cast(18446744073709551615 as unsigned);
+cast(18446744073709551615 as unsigned)
+18446744073709551615
+select cast('18446744073709551615' as unsigned);
+cast('18446744073709551615' as unsigned)
+18446744073709551615

--- 1.15/mysql-test/t/cast.test	2004-12-30 02:38:29 -08:00
+++ 1.16/mysql-test/t/cast.test	2005-03-07 16:48:18 -08:00
@@ -118,3 +118,8 @@
 select timediff(cast('2004-12-30 12:00:00' as time), '12:00:00');
 # Still we should not throw away "days" part of time value
 select timediff(cast('1 12:00:00' as time), '12:00:00');
+
+# Bug #7036: Casting from string to unsigned would cap value of result at
+# maximum signed value instead of maximum unsigned value
+select cast(18446744073709551615 as unsigned);
+select cast('18446744073709551615' as unsigned);
Thread
bk commit into 4.1 tree (jimw:1.2090) BUG#7036Jim Winstead8 Mar