00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021 #include <drizzled/function/str/set_collation.h>
00022 #include <drizzled/error.h>
00023 #include <drizzled/charset.h>
00024
00025 namespace drizzled {
00026
00027 static const char *binary_keyword= "BINARY";
00028
00029 String *Item_func_set_collation::val_str(String *str)
00030 {
00031 assert(fixed == 1);
00032 str=args[0]->val_str(str);
00033 if ((null_value=args[0]->null_value))
00034 return 0;
00035 str->set_charset(collation.collation);
00036 return str;
00037 }
00038
00039 void Item_func_set_collation::fix_length_and_dec()
00040 {
00041 const charset_info_st *set_collation;
00042 const char *colname;
00043 String tmp, *str= args[1]->val_str(&tmp);
00044 colname= str->c_ptr();
00045 if (colname == binary_keyword)
00046 set_collation= get_charset_by_csname(args[0]->collation.collation->csname, MY_CS_BINSORT);
00047 else
00048 {
00049 if (!(set_collation= get_charset_by_name(colname)))
00050 {
00051 my_error(ER_UNKNOWN_COLLATION, MYF(0), colname);
00052 return;
00053 }
00054 }
00055
00056 if (!set_collation ||
00057 !my_charset_same(args[0]->collation.collation,set_collation))
00058 {
00059 my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
00060 colname, args[0]->collation.collation->csname);
00061 return;
00062 }
00063 collation.set(set_collation, DERIVATION_EXPLICIT);
00064 max_length= args[0]->max_length;
00065 }
00066
00067 bool Item_func_set_collation::eq(const Item *item, bool binary_cmp) const
00068 {
00069
00070 if (this == item)
00071 return 1;
00072 if (item->type() != FUNC_ITEM)
00073 return 0;
00074 Item_func *item_func=(Item_func*) item;
00075 if (arg_count != item_func->arg_count ||
00076 functype() != item_func->functype())
00077 return 0;
00078 Item_func_set_collation *item_func_sc=(Item_func_set_collation*) item;
00079 if (collation.collation != item_func_sc->collation.collation)
00080 return 0;
00081 for (uint32_t i=0; i < arg_count ; i++)
00082 if (!args[i]->eq(item_func_sc->args[i], binary_cmp))
00083 return 0;
00084 return 1;
00085 }
00086
00087 void Item_func_set_collation::print(String *str)
00088 {
00089 str->append('(');
00090 args[0]->print(str);
00091 str->append(STRING_WITH_LEN(" collate "));
00092 assert(args[1]->basic_const_item() && args[1]->type() == Item::STRING_ITEM);
00093 args[1]->str_value.print(*str);
00094 str->append(')');
00095 }
00096
00097 }
00098
00099