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
00028 static const char *binary_keyword= "BINARY";
00029
00030 String *Item_func_set_collation::val_str(String *str)
00031 {
00032 assert(fixed == 1);
00033 str=args[0]->val_str(str);
00034 if ((null_value=args[0]->null_value))
00035 return 0;
00036 str->set_charset(collation.collation);
00037 return str;
00038 }
00039
00040 void Item_func_set_collation::fix_length_and_dec()
00041 {
00042 const CHARSET_INFO *set_collation;
00043 const char *colname;
00044 String tmp, *str= args[1]->val_str(&tmp);
00045 colname= str->c_ptr();
00046 if (colname == binary_keyword)
00047 set_collation= get_charset_by_csname(args[0]->collation.collation->csname, MY_CS_BINSORT);
00048 else
00049 {
00050 if (!(set_collation= get_charset_by_name(colname)))
00051 {
00052 my_error(ER_UNKNOWN_COLLATION, MYF(0), colname);
00053 return;
00054 }
00055 }
00056
00057 if (!set_collation ||
00058 !my_charset_same(args[0]->collation.collation,set_collation))
00059 {
00060 my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
00061 colname, args[0]->collation.collation->csname);
00062 return;
00063 }
00064 collation.set(set_collation, DERIVATION_EXPLICIT);
00065 max_length= args[0]->max_length;
00066 }
00067
00068 bool Item_func_set_collation::eq(const Item *item, bool binary_cmp) const
00069 {
00070
00071 if (this == item)
00072 return 1;
00073 if (item->type() != FUNC_ITEM)
00074 return 0;
00075 Item_func *item_func=(Item_func*) item;
00076 if (arg_count != item_func->arg_count ||
00077 functype() != item_func->functype())
00078 return 0;
00079 Item_func_set_collation *item_func_sc=(Item_func_set_collation*) item;
00080 if (collation.collation != item_func_sc->collation.collation)
00081 return 0;
00082 for (uint32_t i=0; i < arg_count ; i++)
00083 if (!args[i]->eq(item_func_sc->args[i], binary_cmp))
00084 return 0;
00085 return 1;
00086 }
00087
00088 void Item_func_set_collation::print(String *str)
00089 {
00090 str->append('(');
00091 args[0]->print(str);
00092 str->append(STRING_WITH_LEN(" collate "));
00093 assert(args[1]->basic_const_item() &&
00094 args[1]->type() == Item::STRING_ITEM);
00095 args[1]->str_value.print(str);
00096 str->append(')');
00097 }
00098
00099 }
00100
00101