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 String* Item_func_export_set::val_str(String* str)
00031 {
00032 assert(fixed == 1);
00033 uint64_t the_set = (uint64_t) args[0]->val_int();
00034 String yes_buf, *yes;
00035 yes = args[1]->val_str(&yes_buf);
00036 String no_buf, *no;
00037 no = args[2]->val_str(&no_buf);
00038 String *sep = NULL, sep_buf ;
00039
00040 uint32_t num_set_values = 64;
00041 uint64_t mask = 0x1;
00042 str->length(0);
00043 str->set_charset(collation.collation);
00044
00045
00046 if (args[0]->null_value || args[1]->null_value || args[2]->null_value)
00047 {
00048 null_value=1;
00049 return 0;
00050 }
00051
00052
00053
00054
00055 switch(arg_count) {
00056 case 5:
00057 num_set_values = (uint) args[4]->val_int();
00058 if (num_set_values > 64)
00059 num_set_values=64;
00060 if (args[4]->null_value)
00061 {
00062 null_value=1;
00063 return 0;
00064 }
00065
00066 case 4:
00067 if (!(sep = args[3]->val_str(&sep_buf)))
00068 {
00069 null_value=1;
00070 return 0;
00071 }
00072 break;
00073 case 3:
00074 {
00075 sep_buf.copy(STRING_WITH_LEN(","), collation.collation);
00076 sep = &sep_buf;
00077 }
00078 break;
00079 default:
00080 assert(0);
00081 }
00082 null_value=0;
00083
00084 for (uint32_t i = 0; i < num_set_values; i++, mask = (mask << 1))
00085 {
00086 if (the_set & mask)
00087 str->append(*yes);
00088 else
00089 str->append(*no);
00090 if (i != num_set_values - 1)
00091 str->append(*sep);
00092 }
00093 return str;
00094 }
00095
00096 void Item_func_export_set::fix_length_and_dec()
00097 {
00098 uint32_t length= max(args[1]->max_length,args[2]->max_length);
00099 uint32_t sep_length= (arg_count > 3 ? args[3]->max_length : 1);
00100 max_length= length*64+sep_length*63;
00101
00102 if (agg_arg_charsets(collation, args+1, min(4U,arg_count)-1,
00103 MY_COLL_ALLOW_CONV, 1))
00104 return;
00105 }
00106
00107 }