23
23
#include <drizzled/field/int64.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/table.h>
26
26
#include <drizzled/session.h>
27
#include "drizzled/internal/my_sys.h"
27
#include <drizzled/internal/my_sys.h>
42
42
Field type Int64 int (8 bytes)
43
43
****************************************************************************/
45
int Int64::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
45
int Int64::store(const char *from,uint32_t len, const charset_info_st * const cs)
51
51
ASSERT_COLUMN_MARKED_FOR_WRITE;
53
53
tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
54
if (error == MY_ERRNO_ERANGE)
56
56
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
59
else if (getTable()->in_use->count_cuted_fields &&
60
check_int(cs, from, len, end, error))
59
else if (getTable()->in_use->count_cuted_fields && check_int(cs, from, len, end, error))
64
#ifdef WORDS_BIGENDIAN
65
if (getTable()->getShare()->db_low_byte_first)
71
int64_tstore(ptr,tmp);
68
int64_tstore(ptr,tmp);
93
91
error= (nr > (double) INT64_MAX);
99
99
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
101
#ifdef WORDS_BIGENDIAN
102
if (getTable()->getShare()->db_low_byte_first)
108
int64_tstore(ptr,res);
101
int64_tstore(ptr, res);
113
int Int64::store(int64_t nr, bool )
107
int Int64::store(int64_t nr, bool arg)
117
111
ASSERT_COLUMN_MARKED_FOR_WRITE;
119
#ifdef WORDS_BIGENDIAN
120
if (getTable()->getShare()->db_low_byte_first)
112
if (arg and (nr < 0)) // Only a partial fix for overflow
114
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
126
int64_tstore(ptr,nr);
118
int64_tstore(ptr,nr);
131
double Int64::val_real(void)
124
double Int64::val_real(void) const
135
128
ASSERT_COLUMN_MARKED_FOR_READ;
137
#ifdef WORDS_BIGENDIAN
138
if (getTable()->getShare()->db_low_byte_first)
145
131
/* The following is open coded to avoid a bug in gcc 3.3 */
146
133
return (double) j;
150
int64_t Int64::val_int(void)
137
int64_t Int64::val_int(void) const
154
141
ASSERT_COLUMN_MARKED_FOR_READ;
156
#ifdef WORDS_BIGENDIAN
157
if (getTable()->getShare()->db_low_byte_first)
166
String *Int64::val_str(String *val_buffer,
149
String *Int64::val_str(String *val_buffer, String *) const
169
const CHARSET_INFO * const cs= &my_charset_bin;
151
const charset_info_st * const cs= &my_charset_bin;
171
153
uint32_t mlength= max(field_length+1,22*cs->mbmaxlen);
172
154
val_buffer->alloc(mlength);
176
158
ASSERT_COLUMN_MARKED_FOR_READ;
178
#ifdef WORDS_BIGENDIAN
179
if (getTable()->getShare()->db_low_byte_first)
185
162
length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
186
163
val_buffer->length(length);
191
168
int Int64::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
194
#ifdef WORDS_BIGENDIAN
195
if (getTable()->getShare()->db_low_byte_first)
206
175
return (a < b) ? -1 : (a > b) ? 1 : 0;
209
178
void Int64::sort_string(unsigned char *to,uint32_t )
211
180
#ifdef WORDS_BIGENDIAN
212
if (!getTable()->getShare()->db_low_byte_first)
214
182
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
238
206
void Int64::sql_type(String &res) const
240
const CHARSET_INFO * const cs=res.charset();
208
const charset_info_st * const cs=res.charset();
241
209
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "bigint"));
245
unsigned char *Int64::pack(unsigned char* to, const unsigned char *from,
247
#ifdef WORDS_BIGENDIAN
213
unsigned char *Int64::pack(unsigned char* to, const unsigned char *from, uint32_t, bool)
255
#ifdef WORDS_BIGENDIAN
256
if (getTable()->getShare()->db_low_byte_first)
257
val = sint8korr(from);
260
int64_tget(val, from);
262
#ifdef WORDS_BIGENDIAN
267
int64_tstore(to, val);
217
int64_tget(val, from);
218
int64_tstore(to, val);
268
220
return to + sizeof(val);
272
const unsigned char *Int64::unpack(unsigned char* to, const unsigned char *from, uint32_t,
273
#ifdef WORDS_BIGENDIAN
224
const unsigned char *Int64::unpack(unsigned char* to, const unsigned char *from, uint32_t, bool)
281
#ifdef WORDS_BIGENDIAN
283
val = sint8korr(from);
286
int64_tget(val, from);
288
#ifdef WORDS_BIGENDIAN
289
if (getTable()->getShare()->db_low_byte_first)
293
int64_tstore(to, val);
228
int64_tget(val, from);
229
int64_tstore(to, val);
294
231
return from + sizeof(val);