diff options
author | unknown <bar@bar.mysql.r18.ru> | 2003-05-28 17:57:58 +0500 |
---|---|---|
committer | unknown <bar@bar.mysql.r18.ru> | 2003-05-28 17:57:58 +0500 |
commit | 5f9d3e4276913351a9a8485654657d23b8aa7b6d (patch) | |
tree | d90c589c4aa4758f8cd2ece67315b1f98e924f3e | |
parent | 9166602342853af34ee7f38ae638692e4fcdd46e (diff) | |
download | mariadb-git-5f9d3e4276913351a9a8485654657d23b8aa7b6d.tar.gz |
CAST(expr AS char) now supports character set with conversion:
SELECT CAST(_latin1'string' AS CHAR CHARACTER SET latin2)
-rw-r--r-- | mysql-test/r/cast.result | 13 | ||||
-rw-r--r-- | mysql-test/t/cast.test | 9 | ||||
-rw-r--r-- | sql/item_create.cc | 7 | ||||
-rw-r--r-- | sql/item_create.h | 2 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 24 |
5 files changed, 41 insertions, 14 deletions
diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result index 7909fabc971..42164a2111b 100644 --- a/mysql-test/r/cast.result +++ b/mysql-test/r/cast.result @@ -28,6 +28,19 @@ cast("2001-1-1" as DATE) cast("2001-1-1" as DATETIME) select cast("1:2:3" as TIME); cast("1:2:3" as TIME) 01:02:03 +select cast(_latin1'test' as char character set latin2); +cast(_latin1'test' as char character set latin2) +test +select cast(_koi8r'ΤΕΣΤ' as char character set cp1251); +cast(_koi8r'ΤΕΣΤ' as char character set cp1251) +ςερς +create table t1 select cast(_koi8r'ΤΕΣΤ' as char character set cp1251) as t; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `t` char(4) character set cp1251 NOT NULL default '' +) TYPE=MyISAM CHARSET=latin1 +drop table t1; select cast("2001-1-1" as date) = "2001-01-01"; cast("2001-1-1" as date) = "2001-01-01" 0 diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index 8703a6b739d..59b8f3b0c75 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -14,6 +14,15 @@ select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME); select cast("1:2:3" as TIME); # +# Character set convertion +# +select cast(_latin1'test' as char character set latin2); +select cast(_koi8r'ΤΕΣΤ' as char character set cp1251); +create table t1 select cast(_koi8r'ΤΕΣΤ' as char character set cp1251) as t; +show create table t1; +drop table t1; + +# # The following should be fixed in 4.1 # diff --git a/sql/item_create.cc b/sql/item_create.cc index 39e1c2dec22..723610c0df4 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -457,13 +457,16 @@ Item *create_load_file(Item* a) } -Item *create_func_cast(Item *a, Item_cast cast_type) +Item *create_func_cast(Item *a, Item_cast cast_type, CHARSET_INFO *cs) { Item *res; LINT_INIT(res); switch (cast_type) { case ITEM_CAST_BINARY: res= new Item_func_binary(a); break; - case ITEM_CAST_CHAR: res= new Item_char_typecast(a); break; + case ITEM_CAST_CHAR: + res= (cs == NULL) ? new Item_char_typecast(a) : + new Item_func_conv_charset(a,cs); + break; case ITEM_CAST_SIGNED_INT: res= new Item_func_signed(a); break; case ITEM_CAST_UNSIGNED_INT: res= new Item_func_unsigned(a); break; case ITEM_CAST_DATE: res= new Item_date_typecast(a); break; diff --git a/sql/item_create.h b/sql/item_create.h index c79fe07b8d4..b679c639244 100644 --- a/sql/item_create.h +++ b/sql/item_create.h @@ -28,7 +28,7 @@ Item *create_func_bit_length(Item* a); Item *create_func_coercibility(Item* a); Item *create_func_ceiling(Item* a); Item *create_func_char_length(Item* a); -Item *create_func_cast(Item *a, Item_cast cast_type); +Item *create_func_cast(Item *a, Item_cast cast_type, CHARSET_INFO *cs); Item *create_func_connection_id(void); Item *create_func_conv(Item* a, Item *b, Item *c); Item *create_func_cos(Item* a); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 1d735730801..bab6d05a0e0 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2233,10 +2233,12 @@ simple_expr: $$= new Item_func_set_collation($2,new Item_string(binary_keyword, 6, &my_charset_latin1)); } - | CAST_SYM '(' expr AS cast_type ')' { $$= create_func_cast($3, $5); } + | CAST_SYM '(' expr AS cast_type ')' + { $$= create_func_cast($3, $5, Lex->charset); } | CASE_SYM opt_expr WHEN_SYM when_list opt_else END { $$= new Item_func_case(* $4, $2, $5 ); } - | CONVERT_SYM '(' expr ',' cast_type ')' { $$= create_func_cast($3, $5); } + | CONVERT_SYM '(' expr ',' cast_type ')' + { $$= create_func_cast($3, $5, Lex->charset); } | CONVERT_SYM '(' expr USING charset_name ')' { $$= new Item_func_conv_charset($3,$5); } | CONVERT_SYM '(' expr ',' expr ',' expr ')' @@ -2645,15 +2647,15 @@ in_sum_expr: }; cast_type: - BINARY { $$=ITEM_CAST_BINARY; } - | CHAR_SYM { $$=ITEM_CAST_CHAR; } - | SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT; } - | SIGNED_SYM INT_SYM { $$=ITEM_CAST_SIGNED_INT; } - | UNSIGNED { $$=ITEM_CAST_UNSIGNED_INT; } - | UNSIGNED INT_SYM { $$=ITEM_CAST_UNSIGNED_INT; } - | DATE_SYM { $$=ITEM_CAST_DATE; } - | TIME_SYM { $$=ITEM_CAST_TIME; } - | DATETIME { $$=ITEM_CAST_DATETIME; } + BINARY { $$=ITEM_CAST_BINARY; Lex->charset= NULL; } + | CHAR_SYM opt_binary { $$=ITEM_CAST_CHAR; } + | SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; } + | SIGNED_SYM INT_SYM { $$=ITEM_CAST_SIGNED_INT; Lex->charset= NULL; } + | UNSIGNED { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; } + | UNSIGNED INT_SYM { $$=ITEM_CAST_UNSIGNED_INT; Lex->charset= NULL; } + | DATE_SYM { $$=ITEM_CAST_DATE; Lex->charset= NULL; } + | TIME_SYM { $$=ITEM_CAST_TIME; Lex->charset= NULL; } + | DATETIME { $$=ITEM_CAST_DATETIME; Lex->charset= NULL; } ; expr_list: |