Below is the list of changes that have just been committed into a local
5.0 repository of cmiller. When cmiller 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, 2006-08-16 16:21:49+02:00, cmiller@stripped +3 -0
Bug#15583: BIN()/OCT()/CONV() do not work with BIT values
Converting BIT to a string (an intermediate step in conversion) does
not yield an ASCII numeric string, so we skip that step for BIT and
get the integer value directly from the item.
This site in sql/item_strfunc.cc may be ripe for refactoring for
other types as well, where converting to a string is a waste of time.
mysql-test/r/type_bit.result@stripped, 2006-08-16 16:21:46+02:00, cmiller@stripped +15 -0
Test that conversion functions on BIT types work properly.
mysql-test/t/type_bit.test@stripped, 2006-08-16 16:21:46+02:00, cmiller@stripped +12 -0
Test that conversion functions on BIT types work properly.
sql/item_strfunc.cc@stripped, 2006-08-16 16:21:46+02:00, cmiller@stripped +25 -11
BIT is unlike the other numeric types, in that when we convert it
to a String, it becomes a one-byte string with ordinal numeric value
of the BIT field, not a several-byte string with the ASCII decimal
representation. As a special case for conversion functions, we take
the integer directly from the bit type instead of representing it
as a string in an intermediate step.
# 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: cmiller
# Host: maint1.mysql.com
# Root: /data/localhome/cmiller/bug15583/my50-bug15583
--- 1.279/sql/item_strfunc.cc 2006-08-16 16:22:03 +02:00
+++ 1.280/sql/item_strfunc.cc 2006-08-16 16:22:03 +02:00
@@ -2348,26 +2348,40 @@ err:
String *Item_func_conv::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- String *res= args[0]->val_str(str);
char *endptr,ans[65],*ptr;
longlong dec;
int from_base= (int) args[1]->val_int();
int to_base= (int) args[2]->val_int();
int err;
- if (args[0]->null_value || args[1]->null_value || args[2]->null_value ||
- abs(to_base) > 36 || abs(to_base) < 2 ||
- abs(from_base) > 36 || abs(from_base) < 2 || !(res->length()))
+ if (args[0]->field_type() == MYSQL_TYPE_BIT)
{
- null_value=1;
- return 0;
+ /*
+ Special case: The string representation of BIT doesn't resemble the
+ decimal representation, so we shouldn't change it to string and then to
+ decimal.
+ */
+ dec= args[0]->val_int();
}
- null_value=0;
- unsigned_flag= !(from_base < 0);
- if (from_base < 0)
- dec= my_strntoll(res->charset(),res->ptr(),res->length(),-from_base,&endptr,&err);
else
- dec= (longlong) my_strntoull(res->charset(),res->ptr(),res->length(),from_base,&endptr,&err);
+ {
+ String *res= args[0]->val_str(str);
+
+ if (args[0]->null_value || args[1]->null_value || args[2]->null_value ||
+ abs(to_base) > 36 || abs(to_base) < 2 ||
+ abs(from_base) > 36 || abs(from_base) < 2 || !(res->length()))
+ {
+ null_value=1;
+ return 0;
+ }
+ null_value=0;
+ unsigned_flag= !(from_base < 0);
+ len = res->length();
+ if (from_base < 0)
+ dec= my_strntoll(res->charset(),res->ptr(),len,-from_base,&endptr,&err);
+ else
+ dec= (longlong) my_strntoull(res->charset(),res->ptr(),len,from_base,&endptr,&err);
+ }
ptr= longlong2str(dec,ans,to_base);
if (str->copy(ans,(uint32) (ptr-ans), default_charset()))
return &my_empty_string;
--- 1.16/mysql-test/r/type_bit.result 2006-08-16 16:22:03 +02:00
+++ 1.17/mysql-test/r/type_bit.result 2006-08-16 16:22:03 +02:00
@@ -572,4 +572,19 @@ def test t1 t1 a a 16 7 1 Y 0 0 63
a
`
drop table t1;
+create table bug15583(b BIT(8), n INT);
+insert into bug15583 values(128, 128);
+select hex(b), bin(b), oct(b), hex(n), bin(n), oct(n) from bug15583;
+hex(b) bin(b) oct(b) hex(n) bin(n) oct(n)
+80 10000000 200 80 10000000 200
+select hex(b)=hex(n) as should_be_onetrue, bin(b)=bin(n) as should_be_onetrue, oct(b)=oct(n) as should_be_onetrue from bug15583;
+should_be_onetrue should_be_onetrue should_be_onetrue
+1 1 1
+select hex(b + 0), bin(b + 0), oct(b + 0), hex(n), bin(n), oct(n) from bug15583;
+hex(b + 0) bin(b + 0) oct(b + 0) hex(n) bin(n) oct(n)
+80 10000000 200 80 10000000 200
+select conv(b, 10, 2), conv(b + 0, 10, 2) from bug15583;
+conv(b, 10, 2) conv(b + 0, 10, 2)
+10000000 10000000
+drop table bug15583;
End of 5.0 tests
--- 1.15/mysql-test/t/type_bit.test 2006-08-16 16:22:03 +02:00
+++ 1.16/mysql-test/t/type_bit.test 2006-08-16 16:22:03 +02:00
@@ -238,4 +238,16 @@ select * from t1;
--disable_metadata
drop table t1;
+#
+# Bug#15583: BIN()/OCT()/CONV() do not work with BIT values
+#
+create table bug15583(b BIT(8), n INT);
+insert into bug15583 values(128, 128);
+select hex(b), bin(b), oct(b), hex(n), bin(n), oct(n) from bug15583;
+select hex(b)=hex(n) as should_be_onetrue, bin(b)=bin(n) as should_be_onetrue, oct(b)=oct(n) as should_be_onetrue from bug15583;
+select hex(b + 0), bin(b + 0), oct(b + 0), hex(n), bin(n), oct(n) from bug15583;
+select conv(b, 10, 2), conv(b + 0, 10, 2) from bug15583;
+drop table bug15583;
+
+
--echo End of 5.0 tests
| Thread |
|---|
| • bk commit into 5.0 tree (cmiller:1.2235) BUG#15583 | Chad MILLER | 16 Aug |