00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <drizzled/function/str/export_set.h>
00023
00024 #include <algorithm>
00025
00026 using namespace std;
00027
00028 namespace drizzled
00029 {
00030
00031 String* Item_func_export_set::val_str(String* str)
00032 {
00033 assert(fixed == 1);
00034 uint64_t the_set = (uint64_t) args[0]->val_int();
00035 String yes_buf, *yes;
00036 yes = args[1]->val_str(&yes_buf);
00037 String no_buf, *no;
00038 no = args[2]->val_str(&no_buf);
00039 String *sep = NULL, sep_buf ;
00040
00041 uint32_t num_set_values = 64;
00042 uint64_t mask = 0x1;
00043 str->length(0);
00044 str->set_charset(collation.collation);
00045
00046
00047 if (args[0]->null_value || args[1]->null_value || args[2]->null_value)
00048 {
00049 null_value=1;
00050 return 0;
00051 }
00052
00053
00054
00055
00056 switch(arg_count) {
00057 case 5:
00058 num_set_values = (uint) args[4]->val_int();
00059 if (num_set_values > 64)
00060 num_set_values=64;
00061 if (args[4]->null_value)
00062 {
00063 null_value=1;
00064 return 0;
00065 }
00066
00067 case 4:
00068 if (!(sep = args[3]->val_str(&sep_buf)))
00069 {
00070 null_value=1;
00071 return 0;
00072 }
00073 break;
00074 case 3:
00075 {
00076
00077 size_t errors;
00078 sep_buf.copy(STRING_WITH_LEN(","), &my_charset_bin, collation.collation, &errors);
00079 sep = &sep_buf;
00080 }
00081 break;
00082 default:
00083 assert(0);
00084 }
00085 null_value=0;
00086
00087 for (uint32_t i = 0; i < num_set_values; i++, mask = (mask << 1))
00088 {
00089 if (the_set & mask)
00090 str->append(*yes);
00091 else
00092 str->append(*no);
00093 if (i != num_set_values - 1)
00094 str->append(*sep);
00095 }
00096 return str;
00097 }
00098
00099 void Item_func_export_set::fix_length_and_dec()
00100 {
00101 uint32_t length= max(args[1]->max_length,args[2]->max_length);
00102 uint32_t sep_length= (arg_count > 3 ? args[3]->max_length : 1);
00103 max_length= length*64+sep_length*63;
00104
00105 if (agg_arg_charsets(collation, args+1, min(4U,arg_count)-1,
00106 MY_COLL_ALLOW_CONV, 1))
00107 return;
00108 }
00109
00110 }