00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include <drizzled/function/str/strfunc.h>
00023
00024 namespace drizzled
00025 {
00026
00027 class Item_func_conv_charset :public Item_str_func
00028 {
00029 bool use_cached_value;
00030 public:
00031 bool safe;
00032 const CHARSET_INFO *conv_charset;
00033 Item_func_conv_charset(Item *a, const CHARSET_INFO * const cs) :Item_str_func(a)
00034 { conv_charset= cs; use_cached_value= 0; safe= 0; }
00035 Item_func_conv_charset(Item *a, const CHARSET_INFO * const cs, bool cache_if_const)
00036 :Item_str_func(a)
00037 {
00038 assert(args[0]->fixed);
00039 conv_charset= cs;
00040 if (cache_if_const && args[0]->const_item())
00041 {
00042 size_t errors= 0;
00043 String tmp, *str= args[0]->val_str(&tmp);
00044 if (!str || str_value.copy(str->ptr(), str->length(),
00045 str->charset(), conv_charset, &errors))
00046 null_value= 1;
00047 use_cached_value= 1;
00048 str_value.mark_as_const();
00049 safe= (errors == 0);
00050 }
00051 else
00052 {
00053 use_cached_value= 0;
00054
00055
00056
00057
00058
00059 safe= (args[0]->collation.collation == &my_charset_bin ||
00060 cs == &my_charset_bin ||
00061 (cs->state & MY_CS_UNICODE));
00062 }
00063 }
00064 String *val_str(String *);
00065 void fix_length_and_dec();
00066 const char *func_name() const { return "convert"; }
00067 virtual void print(String *str);
00068 };
00069
00070 }
00071