23
#include <drizzled/field/int32.h>
24
#include <drizzled/error.h>
25
#include <drizzled/table.h>
26
#include <drizzled/session.h>
22
#include <drizzled/server_includes.h>
23
#include <drizzled/field/long.h>
40
25
/****************************************************************************
42
****************************************************************************/
44
int Int32::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
50
ASSERT_COLUMN_MARKED_FOR_WRITE;
52
error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
53
store_tmp= (long) rnd;
27
****************************************************************************/
29
int Field_long::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
35
error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
36
store_tmp= unsigned_flag ? (long) (uint64_t) rnd : (long) rnd;
54
37
#ifdef WORDS_BIGENDIAN
55
if (getTable()->getShare()->db_low_byte_first)
57
int4store(ptr, store_tmp);
38
if (table->s->db_low_byte_first)
40
int4store(ptr, store_tmp);
44
longstore(ptr, store_tmp);
49
int Field_long::store(double nr)
61
else if (nr > (double) UINT32_MAX)
64
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
61
longstore(ptr, store_tmp);
68
res=(int32_t) (uint32_t) nr;
66
int Int32::store(double nr)
72
ASSERT_COLUMN_MARKED_FOR_WRITE;
74
72
if (nr < (double) INT32_MIN)
76
74
res=(int32_t) INT32_MIN;
85
83
res=(int32_t) (int64_t) nr;
88
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
86
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
90
88
#ifdef WORDS_BIGENDIAN
91
if (getTable()->getShare()->db_low_byte_first)
89
if (table->s->db_low_byte_first)
100
int Field_long::store(int64_t nr, bool unsigned_val)
107
if (nr < 0 && !unsigned_val)
112
else if (nr > INT32_MAX)
118
res=(int32_t) (uint32_t) nr;
102
int Int32::store(int64_t nr, bool unsigned_val)
107
ASSERT_COLUMN_MARKED_FOR_WRITE;
109
122
if (nr < 0 && unsigned_val)
110
123
nr= ((int64_t) INT32_MAX) + 1; // Generate overflow
111
if (nr < (int64_t) INT32_MIN)
124
if (nr < (int64_t) INT32_MIN)
113
126
res=(int32_t) INT32_MIN;
122
135
res=(int32_t) nr;
125
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
127
#ifdef WORDS_BIGENDIAN
128
if (getTable()->getShare()->db_low_byte_first)
139
double Int32::val_real(void)
143
ASSERT_COLUMN_MARKED_FOR_READ;
145
#ifdef WORDS_BIGENDIAN
146
if (getTable()->getShare()->db_low_byte_first)
154
int64_t Int32::val_int(void)
158
ASSERT_COLUMN_MARKED_FOR_READ;
160
/* See the comment in Int32::store(int64_t) */
161
#ifdef WORDS_BIGENDIAN
162
if (getTable()->getShare()->db_low_byte_first)
170
String *Int32::val_str(String *val_buffer,
173
const CHARSET_INFO * const cs= &my_charset_bin;
175
uint32_t mlength= max(field_length+1,12*cs->mbmaxlen);
176
val_buffer->alloc(mlength);
177
char *to=(char*) val_buffer->ptr();
180
ASSERT_COLUMN_MARKED_FOR_READ;
182
#ifdef WORDS_BIGENDIAN
183
if (getTable()->getShare()->db_low_byte_first)
138
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
140
#ifdef WORDS_BIGENDIAN
141
if (table->s->db_low_byte_first)
152
double Field_long::val_real(void)
155
#ifdef WORDS_BIGENDIAN
156
if (table->s->db_low_byte_first)
161
return unsigned_flag ? (double) (uint32_t) j : (double) j;
164
int64_t Field_long::val_int(void)
167
/* See the comment in Field_long::store(int64_t) */
168
assert(table->in_use == current_thd);
169
#ifdef WORDS_BIGENDIAN
170
if (table->s->db_low_byte_first)
175
return unsigned_flag ? (int64_t) (uint32_t) j : (int64_t) j;
178
String *Field_long::val_str(String *val_buffer,
179
String *val_ptr __attribute__((unused)))
181
const CHARSET_INFO * const cs= &my_charset_bin;
183
uint32_t mlength=cmax(field_length+1,12*cs->mbmaxlen);
184
val_buffer->alloc(mlength);
185
char *to=(char*) val_buffer->ptr();
187
#ifdef WORDS_BIGENDIAN
188
if (table->s->db_low_byte_first)
195
length=cs->cset->long10_to_str(cs,to,mlength, 10,(long) (uint32_t)j);
189
197
length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
190
val_buffer->length(length);
195
int Int32::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
198
#ifdef WORDS_BIGENDIAN
199
if (getTable()->getShare()->db_low_byte_first)
198
val_buffer->length(length);
204
bool Field_long::send_binary(Protocol *protocol)
206
return protocol->store_long(Field_long::val_int());
209
int Field_long::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
212
#ifdef WORDS_BIGENDIAN
213
if (table->s->db_low_byte_first)
225
return ((uint32_t) a < (uint32_t) b) ? -1 : ((uint32_t) a > (uint32_t) b) ? 1 : 0;
226
return (a < b) ? -1 : (a > b) ? 1 : 0;
229
void Field_long::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
231
#ifdef WORDS_BIGENDIAN
232
if (!table->s->db_low_byte_first)
211
return (a < b) ? -1 : (a > b) ? 1 : 0;
214
void Int32::sort_string(unsigned char *to,uint32_t )
216
#ifdef WORDS_BIGENDIAN
217
if (!getTable()->getShare()->db_low_byte_first)
219
237
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
227
248
to[0] = (char) (ptr[3] ^ 128); /* Revers signbit */
235
void Int32::sql_type(String &res) const
237
const CHARSET_INFO * const cs=res.charset();
238
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "int"));
241
unsigned char *Int32::pack(unsigned char* to, const unsigned char *from,
243
#ifdef WORDS_BIGENDIAN
251
#ifdef WORDS_BIGENDIAN
252
if (getTable()->getShare()->db_low_byte_first)
253
val = sint4korr(from);
258
#ifdef WORDS_BIGENDIAN
264
return to + sizeof(val);
268
const unsigned char *Int32::unpack(unsigned char* to, const unsigned char *from, uint32_t,
269
#ifdef WORDS_BIGENDIAN
277
#ifdef WORDS_BIGENDIAN
279
val = sint4korr(from);
284
#ifdef WORDS_BIGENDIAN
285
if (getTable()->getShare()->db_low_byte_first)
290
return from + sizeof(val);
293
} /* namespace field */
294
} /* namespace drizzled */
256
void Field_long::sql_type(String &res) const
258
const CHARSET_INFO * const cs=res.charset();
259
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "int"));