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/session.h>
00023 #include <drizzled/error.h>
00024 #include <drizzled/item/string.h>
00025
00026 namespace drizzled {
00027
00028 Item *Item_string::safe_charset_converter(const charset_info_st * const tocs)
00029 {
00030 String tmp, cstr, *ostr= val_str(&tmp);
00031 cstr.copy(ostr->ptr(), ostr->length(), tocs);
00032 Item_string* conv= new Item_string(cstr.ptr(), cstr.length(), cstr.charset(), collation.derivation);
00033 char* ptr= getSession().mem.strdup(cstr);
00034
00035 conv->str_value.set(ptr, cstr.length(), cstr.charset());
00036
00037 conv->str_value.mark_as_const();
00038 return conv;
00039 }
00040
00041
00042 Item *Item_static_string_func::safe_charset_converter(const charset_info_st * const tocs)
00043 {
00044 String tmp, cstr, *ostr= val_str(&tmp);
00045 cstr.copy(ostr->ptr(), ostr->length(), tocs);
00046 Item_string* conv= new Item_static_string_func(func_name, cstr, cstr.charset(), collation.derivation);
00047 conv->str_value.copy();
00048
00049 conv->str_value.mark_as_const();
00050 return conv;
00051 }
00052
00053
00054 bool Item_string::eq(const Item *item, bool binary_cmp) const
00055 {
00056 if (type() == item->type() && item->basic_const_item())
00057 {
00058 if (binary_cmp)
00059 return !stringcmp(&str_value, &item->str_value);
00060 return (collation.collation == item->collation.collation &&
00061 !sortcmp(&str_value, &item->str_value, collation.collation));
00062 }
00063 return 0;
00064 }
00065
00066 void Item_string::print(String *str)
00067 {
00068 str->append('\'');
00069 str_value.print(*str);
00070 str->append('\'');
00071 }
00072
00073 double Item_string::val_real()
00074 {
00075 assert(fixed == 1);
00076 int error;
00077 char *end;
00078 const charset_info_st* cs= str_value.charset();
00079
00080 char* org_end= (char*) str_value.ptr() + str_value.length();
00081 double tmp= my_strntod(cs, (char*) str_value.ptr(), str_value.length(), &end, &error);
00082 if (error || (end != org_end && !check_if_only_end_space(cs, end, org_end)))
00083 {
00084
00085
00086
00087
00088 push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE", str_value.ptr());
00089 }
00090 return tmp;
00091 }
00092
00097 int64_t Item_string::val_int()
00098 {
00099 assert(fixed == 1);
00100 int err;
00101 char *end= (char*) str_value.ptr()+ str_value.length();
00102 char *org_end= end;
00103 const charset_info_st * const cs= str_value.charset();
00104
00105 int64_t tmp= (*(cs->cset->strtoll10))(cs, str_value.ptr(), &end, &err);
00106
00107
00108
00109
00110 if (err > 0 || (end != org_end && !check_if_only_end_space(cs, end, org_end)))
00111 {
00112 push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER", str_value.ptr());
00113 }
00114 return tmp;
00115 }
00116
00117 type::Decimal *Item_string::val_decimal(type::Decimal *decimal_value)
00118 {
00119 return val_decimal_from_string(decimal_value);
00120 }
00121
00122 int Item_string::save_in_field(Field *field, bool)
00123 {
00124 String* result=val_str(&str_value);
00125 return save_str_value_in_field(field, result);
00126 }
00127
00128
00129 }