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/item/bin_string.h>
00022
00023 namespace drizzled {
00024
00025
00026
00027
00028
00029
00030
00031 Item_bin_string::Item_bin_string(str_ref arg)
00032 {
00033 const char *str= arg.data();
00034 const char *end= str + arg.size() - 1;
00035 unsigned char bits= 0;
00036 uint32_t power= 1;
00037
00038 max_length= (arg.size() + 7) >> 3;
00039 char *ptr= (char*) memory::sql_alloc(max_length + 1);
00040 str_value.set(ptr, max_length, &my_charset_bin);
00041 ptr+= max_length - 1;
00042 ptr[1]= 0;
00043 for (; end >= str; end--)
00044 {
00045 if (power == 256)
00046 {
00047 power= 1;
00048 *ptr--= bits;
00049 bits= 0;
00050 }
00051 if (*end == '1')
00052 bits|= power;
00053 power<<= 1;
00054 }
00055 *ptr= (char) bits;
00056 collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
00057 fixed= 1;
00058 }
00059
00060 }