diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result index acca50b45dd..24d33e79411 100644 --- a/mysql-test/r/cast.result +++ b/mysql-test/r/cast.result @@ -101,6 +101,21 @@ t1 CREATE TABLE `t1` ( `c5` char(2) character set utf8 NOT NULL default '' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 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"; cast("2001-1-1" as date) = "2001-01-01" 1 diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index dd17904effb..cb5f10515bd 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -64,6 +64,19 @@ select * from t1; show create 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 diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 9799c5814c4..ed5b9ecc0db 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1848,6 +1848,8 @@ String *Item_char_typecast::val_str(String *str) } res= str; } + + res->set_charset(cast_cs); /* Cut the tail if cast with length diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 61070f07266..89f48607969 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -235,7 +235,7 @@ bool String::copy(const char *str, uint32 arg_length, { 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; if (alloc(new_length))