22
#include <drizzled/server_includes.h>
23
23
#include <drizzled/field/num.h>
24
#include <drizzled/error.h>
25
#include <drizzled/table.h>
26
#include <drizzled/session.h>
27
#include <drizzled/internal/my_sys.h>
24
#include <drizzled/drizzled_error_messages.h>
33
27
Numeric fields base class constructor.
35
Field_num::Field_num(unsigned char *ptr_arg,
37
unsigned char *null_ptr_arg,
38
unsigned char null_bit_arg,
39
utype unireg_check_arg,
29
Field_num::Field_num(unsigned char *ptr_arg,uint32_t len_arg, unsigned char *null_ptr_arg,
30
unsigned char null_bit_arg, utype unireg_check_arg,
40
31
const char *field_name_arg,
51
decimal_precision(zero_arg),
52
unsigned_flag(unsigned_arg)
32
uint8_t dec_arg, bool zero_arg, bool unsigned_arg)
33
:Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
34
unireg_check_arg, field_name_arg),
35
dec(dec_arg),decimal_precision(zero_arg),unsigned_flag(unsigned_arg)
86
71
String tmp(buff, (uint32_t) sizeof(buff), system_charset_info);
87
72
tmp.copy(str, length, system_charset_info);
88
push_warning_printf(getTable()->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
73
push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
89
74
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
90
75
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
91
76
"integer", tmp.c_ptr(), field_name,
92
(uint32_t) getTable()->in_use->row_count);
77
(uint32_t) table->in_use->row_count);
95
80
/* Test if we have garbage at the end of the given string. */
127
112
bool Field_num::get_int(const CHARSET_INFO * const cs, const char *from, uint32_t len,
128
int64_t *rnd, uint64_t ,
113
int64_t *rnd, uint64_t unsigned_max,
129
114
int64_t signed_min, int64_t signed_max)
134
*rnd= (int64_t) cs->cset->strntoull10rnd(cs, from, len, false, &end, &error);
135
if (*rnd < signed_min)
140
else if (*rnd > signed_max)
119
*rnd= (int64_t) cs->cset->strntoull10rnd(cs, from, len,
146
if (getTable()->in_use->count_cuted_fields &&
125
if ((((uint64_t) *rnd > unsigned_max) && (*rnd= (int64_t) unsigned_max)) ||
126
error == MY_ERRNO_ERANGE)
133
if (*rnd < signed_min)
138
else if (*rnd > signed_max)
144
if (table->in_use->count_cuted_fields &&
147
145
check_int(cs, from, len, end, error))
171
int Field_num::store_decimal(const type::Decimal *val)
174
int Field_num::store_decimal(const my_decimal *val)
174
int64_t i= convert_decimal2int64_t(val, false, &err);
175
return test(err | store(i, false));
177
int64_t i= convert_decimal2int64_t(val, unsigned_flag, &err);
178
return test(err | store(i, unsigned_flag));
189
192
pointer to decimal buffer with value of field
192
type::Decimal* Field_num::val_decimal(type::Decimal *decimal_value) const
195
my_decimal* Field_num::val_decimal(my_decimal *decimal_value)
194
197
assert(result_type() == INT_RESULT);
196
198
int64_t nr= val_int();
197
int2_class_decimal(E_DEC_FATAL_ERROR, nr, false, decimal_value);
199
int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
198
200
return decimal_value;
202
void Field_num::make_field(SendField *field)
204
void Field_num::make_field(Send_field *field)
204
206
Field::make_field(field);
205
207
field->decimals= dec;
216
218
Field_num *from_num= (Field_num*) field;
218
if (dec != from_num->dec)
220
if (unsigned_flag != from_num->unsigned_flag ||
221
dec != from_num->dec)
223
uint32_t Field_num::is_equal(CreateField *new_field_ptr)
226
uint32_t Field_num::is_equal(Create_field *new_field)
225
return ((new_field_ptr->sql_type == real_type()) &&
226
((new_field_ptr->flags & UNSIGNED_FLAG) ==
227
(uint32_t) (flags & UNSIGNED_FLAG)) &&
228
((new_field_ptr->flags & AUTO_INCREMENT_FLAG) ==
228
return ((new_field->sql_type == real_type()) &&
229
((new_field->flags & UNSIGNED_FLAG) == (uint32_t) (flags &
231
((new_field->flags & AUTO_INCREMENT_FLAG) ==
229
232
(uint32_t) (flags & AUTO_INCREMENT_FLAG)) &&
230
(new_field_ptr->length <= max_display_length()));
233
(new_field->length <= max_display_length()));
234
} /* namespace drizzled */