Bug 2202: CAST from binary to char still returns a binary string

This commit is contained in:
unknown 2003-12-25 17:42:17 +04:00
parent 229cc61277
commit 8fac0f4d27
4 changed files with 31 additions and 1 deletions

View File

@ -101,6 +101,21 @@ t1 CREATE TABLE `t1` (
`c5` char(2) character set utf8 NOT NULL default '' `c5` char(2) character set utf8 NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1; drop table t1;
create table t1 (a binary(10), b char(10) character set koi8r);
insert into t1 values (_binary'ÔÅÓÔ',_binary'ÔÅÓÔ');
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
a b cast(a as char character set cp1251) cast(b as binary)
ÔÅÓÔ ÔÅÓÔ ÔÅÓÔ ÔÅÓÔ
set names koi8r;
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
a b cast(a as char character set cp1251) cast(b as binary)
ÔÅÓÔ ÔÅÓÔ æåõæ ÔÅÓÔ
set names cp1251;
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
a b cast(a as char character set cp1251) cast(b as binary)
ÔÅÓÔ òåñò ÔÅÓÔ ÔÅÓÔ
drop table t1;
set names binary;
select cast("2001-1-1" as date) = "2001-01-01"; select cast("2001-1-1" as date) = "2001-01-01";
cast("2001-1-1" as date) = "2001-01-01" cast("2001-1-1" as date) = "2001-01-01"
1 1

View File

@ -64,6 +64,19 @@ select * from t1;
show create table t1; show create table t1;
drop table t1; drop table t1;
#
# Bug 2202
# CAST from BINARY to non-BINARY and from non-BINARY to BINARY
#
create table t1 (a binary(10), b char(10) character set koi8r);
insert into t1 values (_binary'ÔÅÓÔ',_binary'ÔÅÓÔ');
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
set names koi8r;
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
set names cp1251;
select a,b,cast(a as char character set cp1251),cast(b as binary) from t1;
drop table t1;
set names binary;
# #
# The following should be fixed in 4.1 # The following should be fixed in 4.1

View File

@ -1849,6 +1849,8 @@ String *Item_char_typecast::val_str(String *str)
res= str; res= str;
} }
res->set_charset(cast_cs);
/* /*
Cut the tail if cast with length Cut the tail if cast with length
and the result is longer than cast length, e.g. and the result is longer than cast length, e.g.

View File

@ -235,7 +235,7 @@ bool String::copy(const char *str, uint32 arg_length,
{ {
if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin)) if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin))
{ {
return copy(str, arg_length, &my_charset_bin); return copy(str, arg_length, to_cs);
} }
uint32 new_length= to_cs->mbmaxlen*arg_length; uint32 new_length= to_cs->mbmaxlen*arg_length;
if (alloc(new_length)) if (alloc(new_length))