mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
Merge maint1.mysql.com:/data/localhome/cmiller/bug15583/my50-bug15583
into maint1.mysql.com:/data/localhome/cmiller/mysql-5.0-maint sql/item_strfunc.cc: Auto merged
This commit is contained in:
commit
0ca3700ed7
3 changed files with 69 additions and 8 deletions
|
@ -572,4 +572,34 @@ 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);
|
||||
insert into bug15583 values(null, null);
|
||||
insert into bug15583 values(0, 0);
|
||||
insert into bug15583 values(255, 255);
|
||||
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
|
||||
NULL NULL NULL NULL NULL NULL
|
||||
0 0 0 0 0 0
|
||||
FF 11111111 377 FF 11111111 377
|
||||
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
|
||||
NULL NULL NULL
|
||||
1 1 1
|
||||
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
|
||||
NULL NULL NULL NULL NULL NULL
|
||||
0 0 0 0 0 0
|
||||
FF 11111111 377 FF 11111111 377
|
||||
select conv(b, 10, 2), conv(b + 0, 10, 2) from bug15583;
|
||||
conv(b, 10, 2) conv(b + 0, 10, 2)
|
||||
10000000 10000000
|
||||
NULL NULL
|
||||
0 0
|
||||
11111111 11111111
|
||||
drop table bug15583;
|
||||
End of 5.0 tests
|
||||
|
|
|
@ -238,4 +238,19 @@ 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);
|
||||
insert into bug15583 values(null, null);
|
||||
insert into bug15583 values(0, 0);
|
||||
insert into bug15583 values(255, 255);
|
||||
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
|
||||
|
|
|
@ -2381,17 +2381,33 @@ String *Item_func_conv::val_str(String *str)
|
|||
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= 1;
|
||||
return NULL;
|
||||
}
|
||||
null_value=0;
|
||||
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);
|
||||
|
||||
if (args[0]->field_type() == MYSQL_TYPE_BIT)
|
||||
{
|
||||
/*
|
||||
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();
|
||||
}
|
||||
else
|
||||
dec= (longlong) my_strntoull(res->charset(),res->ptr(),res->length(),from_base,&endptr,&err);
|
||||
ptr= longlong2str(dec,ans,to_base);
|
||||
if (str->copy(ans,(uint32) (ptr-ans), default_charset()))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
ptr= longlong2str(dec, ans, to_base);
|
||||
if (str->copy(ans, (uint32) (ptr-ans), default_charset()))
|
||||
return &my_empty_string;
|
||||
return str;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue