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/charset.h>
00023 #include <drizzled/field.h>
00024 #include <drizzled/internal/m_string.h>
00025 #include <drizzled/item/int.h>
00026
00027 namespace drizzled {
00028
00035 Item_int::Item_int(const char *str_arg, uint32_t length)
00036 {
00037 char *end_ptr= (char*) str_arg + length;
00038 int error;
00039 value= internal::my_strtoll10(str_arg, &end_ptr, &error);
00040 max_length= (uint32_t) (end_ptr - str_arg);
00041 name= (char*) str_arg;
00042 fixed= 1;
00043 }
00044
00045 type::Decimal *Item_int::val_decimal(type::Decimal *decimal_value)
00046 {
00047 int2_class_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_value);
00048 return decimal_value;
00049 }
00050
00051 String *Item_int::val_str(String *str)
00052 {
00053
00054 assert(fixed == 1);
00055 str->set(value, &my_charset_bin);
00056 return str;
00057 }
00058
00059 void Item_int::print(String *str)
00060 {
00061
00062 str_value.set(value, &my_charset_bin);
00063 str->append(str_value);
00064 }
00065
00066 int Item_int::save_in_field(Field *field, bool)
00067 {
00068 int64_t nr=val_int();
00069 if (null_value)
00070 return set_field_to_null(field);
00071 field->set_notnull();
00072 return field->store(nr, unsigned_flag);
00073 }
00074
00075 bool Item_int::eq(const Item *arg, bool) const
00076 {
00077
00078 if (arg->basic_const_item() && arg->type() == type())
00079 {
00080
00081
00082
00083
00084 Item *item= (Item*) arg;
00085 return item->val_int() == value && item->unsigned_flag == unsigned_flag;
00086 }
00087 return false;
00088 }
00089
00090
00091 }