diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 81d866bfe6d..a4f09f9103e 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1911,12 +1911,25 @@ outp: return str; } +String *Item_func_charset::val_str(String *str) +{ + String *res = args[0]->val_str(str); + + if ((null_value=(args[0]->null_value || !res->charset()))) + return 0; + str->copy(res->charset()->name,strlen(res->charset()->name)); + return str; +} + + void Item_func_conv_charset3::fix_length_and_dec() { /* BAR TODO: What to do here??? */ } + + String *Item_func_hex::val_str(String *str) { if (args[0]->result_type() != STRING_RESULT) diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 03ef65c352a..a273abaf614 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -503,6 +503,18 @@ public: const char *func_name() const { return "conv_charset3"; } }; +class Item_func_charset :public Item_str_func +{ +public: + Item_func_charset(Item *a) :Item_str_func(a) {} + String *val_str(String *); + const char *func_name() const { return "charset"; } + void fix_length_and_dec() + { + max_length=20; // should be enough + }; +}; + /******************************************************* Spatial functions diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index f3c5ae6efaf..91c87e9b849 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1784,6 +1784,8 @@ simple_expr: { $$= new Item_func_atan($3,$5); } | CHAR_SYM '(' expr_list ')' { $$= new Item_func_char(*$3); } + | CHARSET '(' expr ')' + { $$= new Item_func_charset($3); } | COALESCE '(' expr_list ')' { $$= new Item_func_coalesce(* $3); } | CONCAT '(' expr_list ')'