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/item/cache_str.h>
00023 #include <drizzled/field.h>
00024
00025 namespace drizzled {
00026
00027 Item_cache_str::Item_cache_str(const Item *item) :
00028 Item_cache(), value(0),
00029 is_varbinary(item->type() == FIELD_ITEM &&
00030 ((const Item_field *) item)->field->type() ==
00031 DRIZZLE_TYPE_VARCHAR &&
00032 !((const Item_field *) item)->field->has_charset())
00033 {}
00034
00035 void Item_cache_str::store(Item *item)
00036 {
00037 value_buff.set(buffer, sizeof(buffer), item->collation.collation);
00038 value= item->str_result(&value_buff);
00039 if ((null_value= item->null_value))
00040 value= 0;
00041 else if (value != &value_buff)
00042 {
00043
00044
00045
00046
00047
00048
00049
00050
00051 value_buff.copy(*value);
00052 value= &value_buff;
00053 }
00054 }
00055
00056 double Item_cache_str::val_real()
00057 {
00058 assert(fixed == 1);
00059 int err_not_used;
00060 char *end_not_used;
00061 if (value)
00062 return my_strntod(value->charset(), (char*) value->ptr(),
00063 value->length(), &end_not_used, &err_not_used);
00064 return (double) 0;
00065 }
00066
00067
00068 int64_t Item_cache_str::val_int()
00069 {
00070 assert(fixed == 1);
00071 int err;
00072 if (value)
00073 return my_strntoll(value->charset(), value->ptr(),
00074 value->length(), 10, (char**) 0, &err);
00075 else
00076 return 0;
00077 }
00078
00079 type::Decimal *Item_cache_str::val_decimal(type::Decimal *decimal_val)
00080 {
00081 assert(fixed == 1);
00082 if (value)
00083 decimal_val->store(E_DEC_FATAL_ERROR, value);
00084 else
00085 decimal_val= 0;
00086 return decimal_val;
00087 }
00088
00089 int Item_cache_str::save_in_field(Field *field, bool no_conversions)
00090 {
00091 return Item_cache::save_in_field(field, no_conversions);
00092 }
00093
00094 }