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