CAST(expr AS char) now supports character set with conversion:
SELECT CAST(_latin1'string' AS CHAR CHARACTER SET latin2)
This commit is contained in:
parent
9166602342
commit
5f9d3e4276
@ -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
|
||||
|
@ -13,6 +13,15 @@ select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A";
|
||||
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
|
||||
#
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user