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