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/10 17:37:27 jimw@stripped +7 -0
Add Item::val_uint() method, used by Item_func_unsigned::val_int()
so that unsigned integers are not truncated as signed integers
when converted from strings. (Bug #7036)
sql/item_sum.h
1.79 05/03/10 17:37:24 jimw@stripped +6 -0
Add Item_sum_udf_str::val_uint()
sql/item_strfunc.h
1.92 05/03/10 17:37:24 jimw@stripped +1 -0
Add val_uint() declaration
sql/item_strfunc.cc
1.218 05/03/10 17:37:23 jimw@stripped +14 -0
Add Item_str_func::val_uint()
sql/item_func.h
1.120 05/03/10 17:37:23 jimw@stripped +12 -0
Use val_uint() in Item_func_unsigned::val_int() to get unsigned
value from argument, and add Item_func_udf_str::val_uint().
sql/item.h
1.173 05/03/10 17:37:23 jimw@stripped +16 -0
Add val_uint() method to get unsigned longlong from an Item
mysql-test/t/cast.test
1.16 05/03/10 17:37:23 jimw@stripped +13 -0
Add new regression test
mysql-test/r/cast.result
1.22 05/03/10 17:37:23 jimw@stripped +24 -0
Add 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-10 17:37:23 -08:00
@@ -186,6 +186,10 @@
/* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
virtual double val()=0;
virtual longlong val_int()=0;
+ virtual ulonglong val_uint()
+ {
+ return (ulonglong)val_int();
+ }
/*
Return string representation of this item object.
@@ -726,6 +730,13 @@
return my_strntoll(str_value.charset(), str_value.ptr(),
str_value.length(), 10, (char**) 0, &err);
}
+ ulonglong val_uint()
+ {
+ DBUG_ASSERT(fixed == 1);
+ int err;
+ return my_strntoull(str_value.charset(), str_value.ptr(),
+ str_value.length(), 10, (char**) 0, &err);
+ }
String *val_str(String*)
{
DBUG_ASSERT(fixed == 1);
@@ -1057,6 +1068,11 @@
{
int err;
return null_value ? LL(0) :
my_strntoll(str_value.charset(),str_value.ptr(),str_value.length(),10, (char**)
0,&err);
+ }
+ ulonglong val_uint()
+ {
+ int err;
+ return null_value ? LL(0) :
my_strntoull(str_value.charset(),str_value.ptr(),str_value.length(),10, (char**)
0,&err);
}
String *val_str(String*);
void make_field(Send_field *field) { item->make_field(field); }
--- 1.119/sql/item_func.h 2005-02-22 02:51:19 -08:00
+++ 1.120/sql/item_func.h 2005-03-10 17:37:23 -08:00
@@ -246,6 +246,12 @@
void fix_length_and_dec()
{ max_length=args[0]->max_length; unsigned_flag=1; }
void print(String *str);
+ longlong val_int()
+ {
+ ulonglong tmp= args[0]->val_uint();
+ null_value= args[0]->null_value;
+ return (longlong)tmp;
+ }
};
@@ -839,6 +845,12 @@
int err;
String *res; res=val_str(&str_value);
return res ? my_strntoll(res->charset(),res->ptr(),res->length(),10,(char**)
0,&err) : (longlong) 0;
+ }
+ ulonglong val_uint()
+ {
+ int err;
+ String *res; res=val_str(&str_value);
+ return res ?
my_strntoull(res->charset(),res->ptr(),res->length(),10,(char**) 0,&err) :
(longlong) 0;
}
enum Item_result result_type () const { return STRING_RESULT; }
void fix_length_and_dec();
--- 1.217/sql/item_strfunc.cc 2005-03-04 02:17:10 -08:00
+++ 1.218/sql/item_strfunc.cc 2005-03-10 17:37:23 -08:00
@@ -84,6 +84,20 @@
}
+ulonglong Item_str_func::val_uint()
+{
+ DBUG_ASSERT(fixed == 1);
+ int err;
+ char buff[22];
+ String *res, tmp(buff,sizeof(buff), &my_charset_bin);
+ res= val_str(&tmp);
+ return (res ?
+ my_strntoull(res->charset(), res->ptr(), res->length(), 10, NULL,
+ &err) :
+ (longlong) 0);
+}
+
+
String *Item_func_md5::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
--- 1.91/sql/item_strfunc.h 2005-03-04 02:18:04 -08:00
+++ 1.92/sql/item_strfunc.h 2005-03-10 17:37:24 -08:00
@@ -32,6 +32,7 @@
Item_str_func(Item *a,Item *b,Item *c,Item *d, Item* e) :Item_func(a,b,c,d,e)
{decimals=NOT_FIXED_DEC; }
Item_str_func(List<Item> &list) :Item_func(list) {decimals=NOT_FIXED_DEC; }
longlong val_int();
+ ulonglong val_uint();
double val();
enum Item_result result_type () const { return STRING_RESULT; }
void left_right_max_length();
--- 1.78/sql/item_sum.h 2005-02-22 02:51:20 -08:00
+++ 1.79/sql/item_sum.h 2005-03-10 17:37:24 -08:00
@@ -612,6 +612,12 @@
String *res; res=val_str(&str_value);
return res ? my_strntoll(res->charset(),res->ptr(),res->length(),10,
(char**) 0, &err) : (longlong) 0;
}
+ ulonglong val_uint()
+ {
+ int err;
+ String *res; res=val_str(&str_value);
+ return res ? my_strntoull(res->charset(),res->ptr(),res->length(),10,
(char**) 0, &err) : (longlong) 0;
+ }
enum Item_result result_type () const { return STRING_RESULT; }
void fix_length_and_dec();
Item *copy_or_same(THD* thd);
--- 1.21/mysql-test/r/cast.result 2004-12-30 02:38:29 -08:00
+++ 1.22/mysql-test/r/cast.result 2005-03-10 17:37:23 -08:00
@@ -187,3 +187,27 @@
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 signed);
+cast(18446744073709551615 as signed)
+-1
+select cast('18446744073709551615' as unsigned);
+cast('18446744073709551615' as unsigned)
+18446744073709551615
+select cast('18446744073709551615' as signed);
+cast('18446744073709551615' as signed)
+9223372036854775807
+select cast(concat('184467440','73709551615') as unsigned);
+cast(concat('184467440','73709551615') as unsigned)
+18446744073709551615
+select cast(concat('184467440','73709551615') as signed);
+cast(concat('184467440','73709551615') as signed)
+9223372036854775807
+select cast(repeat('1',20) as unsigned);
+cast(repeat('1',20) as unsigned)
+11111111111111111111
+select cast(repeat('1',20) as signed);
+cast(repeat('1',20) as signed)
+9223372036854775807
--- 1.15/mysql-test/t/cast.test 2004-12-30 02:38:29 -08:00
+++ 1.16/mysql-test/t/cast.test 2005-03-10 17:37:23 -08:00
@@ -118,3 +118,16 @@
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 signed);
+select cast('18446744073709551615' as unsigned);
+select cast('18446744073709551615' as signed);
+
+select cast(concat('184467440','73709551615') as unsigned);
+select cast(concat('184467440','73709551615') as signed);
+
+select cast(repeat('1',20) as unsigned);
+select cast(repeat('1',20) as signed);
| Thread |
|---|
| • bk commit into 4.1 tree (jimw:1.2090) BUG#7036 | Jim Winstead | 11 Mar |