18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#ifdef USE_PRAGMA_IMPLEMENTATION
22
#pragma implementation // gcc: Class implementation
25
22
#include <drizzled/server_includes.h>
26
23
#include <drizzled/field/int64_t.h>
24
#include <drizzled/error.h>
25
#include <drizzled/table.h>
26
#include <drizzled/session.h>
28
29
/****************************************************************************
29
30
Field type int64_t int (8 bytes)
38
tmp= cs->cset->strntoull10rnd(cs,from,len,unsigned_flag,&end,&error);
39
tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
39
40
if (error == MY_ERRNO_ERANGE)
41
42
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
44
else if (table->in_use->count_cuted_fields &&
45
else if (table->in_use->count_cuted_fields &&
45
46
check_int(cs, from, len, end, error))
74
else if (nr >= (double) UINT64_MAX)
80
res=(int64_t) (uint64_t) nr;
69
if (nr <= (double) INT64_MIN)
72
error= (nr < (double) INT64_MIN);
74
else if (nr >= (double) (uint64_t) INT64_MAX)
77
error= (nr > (double) INT64_MAX);
84
if (nr <= (double) INT64_MIN)
87
error= (nr < (double) INT64_MIN);
89
else if (nr >= (double) (uint64_t) INT64_MAX)
92
error= (nr > (double) INT64_MAX);
98
83
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
112
int Field_int64_t::store(int64_t nr, bool unsigned_val)
97
int Field_int64_t::store(int64_t nr, bool )
116
if (nr < 0) // Only possible error
119
if field is unsigned and value is signed (< 0) or
120
if field is signed and value is unsigned we have an overflow
122
if (unsigned_flag != unsigned_val)
124
nr= unsigned_flag ? (uint64_t) 0 : (uint64_t) INT64_MAX;
125
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
130
101
#ifdef WORDS_BIGENDIAN
131
102
if (table->s->db_low_byte_first)
190
156
int64_tget(j,ptr);
192
length=(uint) (cs->cset->int64_t10_to_str)(cs,to,mlength,
193
unsigned_flag ? 10 : -10, j);
158
length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
194
159
val_buffer->length(length);
196
161
return val_buffer;
200
bool Field_int64_t::send_binary(Protocol *protocol)
202
return protocol->store_int64_t(Field_int64_t::val_int(), unsigned_flag);
206
164
int Field_int64_t::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
218
176
int64_tget(a,a_ptr);
219
177
int64_tget(b,b_ptr);
222
return ((uint64_t) a < (uint64_t) b) ? -1 :
223
((uint64_t) a > (uint64_t) b) ? 1 : 0;
224
179
return (a < b) ? -1 : (a > b) ? 1 : 0;
227
void Field_int64_t::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
182
void Field_int64_t::sort_string(unsigned char *to,uint32_t )
229
184
#ifdef WORDS_BIGENDIAN
230
185
if (!table->s->db_low_byte_first)
235
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
187
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
264
213
const CHARSET_INFO * const cs=res.charset();
265
214
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "bigint"));
271
Floating-point numbers
275
Field_real::pack(unsigned char *to, const unsigned char *from,
276
uint32_t max_length, bool low_byte_first)
278
assert(max_length >= pack_length());
279
#ifdef WORDS_BIGENDIAN
280
if (low_byte_first != table->s->db_low_byte_first)
282
const unsigned char *dptr= from + pack_length();
283
while (dptr-- > from)
289
return(Field::pack(to, from, max_length, low_byte_first));
292
const unsigned char *
293
Field_real::unpack(unsigned char *to, const unsigned char *from,
294
uint32_t param_data, bool low_byte_first)
296
#ifdef WORDS_BIGENDIAN
297
if (low_byte_first != table->s->db_low_byte_first)
299
const unsigned char *dptr= from + pack_length();
300
while (dptr-- > from)
302
return(from + pack_length());
306
return(Field::unpack(to, from, param_data, low_byte_first));
218
unsigned char *Field_int64_t::pack(unsigned char* to, const unsigned char *from,
220
#ifdef WORDS_BIGENDIAN
228
#ifdef WORDS_BIGENDIAN
229
if (table->s->db_low_byte_first)
230
val = sint8korr(from);
233
int64_tget(val, from);
235
#ifdef WORDS_BIGENDIAN
240
int64_tstore(to, val);
241
return to + sizeof(val);
245
const unsigned char *Field_int64_t::unpack(unsigned char* to, const unsigned char *from, uint32_t,
246
#ifdef WORDS_BIGENDIAN
254
#ifdef WORDS_BIGENDIAN
256
val = sint8korr(from);
259
int64_tget(val, from);
261
#ifdef WORDS_BIGENDIAN
262
if (table->s->db_low_byte_first)
266
int64_tstore(to, val);
267
return from + sizeof(val);