23
#include <drizzled/field/int64.h>
22
#include <drizzled/server_includes.h>
23
#include <drizzled/field/int64_t.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>
30
#if defined(CMATH_NAMESPACE)
31
using namespace CMATH_NAMESPACE;
41
34
/****************************************************************************
42
Field type Int64 int (8 bytes)
43
****************************************************************************/
35
Field type int64_t int (8 bytes)
36
****************************************************************************/
45
int Int64::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
38
int Field_int64_t::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
51
ASSERT_COLUMN_MARKED_FOR_WRITE;
53
44
tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
54
45
if (error == MY_ERRNO_ERANGE)
56
47
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
59
else if (getTable()->in_use->count_cuted_fields && check_int(cs, from, len, end, error))
50
else if (table->in_use->count_cuted_fields &&
51
check_int(cs, from, len, end, error))
55
#ifdef WORDS_BIGENDIAN
56
if (table->s->db_low_byte_first)
68
int64_tstore(ptr,tmp);
62
int64_tstore(ptr,tmp);
74
int Int64::store(double nr)
67
int Field_int64_t::store(double nr)
79
ASSERT_COLUMN_MARKED_FOR_WRITE;
83
74
if (nr <= (double) INT64_MIN)
91
82
error= (nr > (double) INT64_MAX);
99
88
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
101
int64_tstore(ptr, res);
90
#ifdef WORDS_BIGENDIAN
91
if (table->s->db_low_byte_first)
97
int64_tstore(ptr,res);
107
int Int64::store(int64_t nr, bool arg)
102
int Field_int64_t::store(int64_t nr, bool )
111
ASSERT_COLUMN_MARKED_FOR_WRITE;
112
if (arg and (nr < 0)) // Only a partial fix for overflow
106
#ifdef WORDS_BIGENDIAN
107
if (table->s->db_low_byte_first)
114
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
118
int64_tstore(ptr,nr);
113
int64_tstore(ptr,nr);
124
double Int64::val_real(void) const
118
double Field_int64_t::val_real(void)
128
ASSERT_COLUMN_MARKED_FOR_READ;
121
#ifdef WORDS_BIGENDIAN
122
if (table->s->db_low_byte_first)
131
129
/* The following is open coded to avoid a bug in gcc 3.3 */
133
130
return (double) j;
137
int64_t Int64::val_int(void) const
134
int64_t Field_int64_t::val_int(void)
141
ASSERT_COLUMN_MARKED_FOR_READ;
137
#ifdef WORDS_BIGENDIAN
138
if (table->s->db_low_byte_first)
149
String *Int64::val_str(String *val_buffer, String *) const
147
String *Field_int64_t::val_str(String *val_buffer,
151
150
const CHARSET_INFO * const cs= &my_charset_bin;
153
uint32_t mlength= max(field_length+1,22*cs->mbmaxlen);
152
uint32_t mlength=cmax(field_length+1,22*cs->mbmaxlen);
154
153
val_buffer->alloc(mlength);
155
154
char *to=(char*) val_buffer->ptr();
158
ASSERT_COLUMN_MARKED_FOR_READ;
162
length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
156
#ifdef WORDS_BIGENDIAN
157
if (table->s->db_low_byte_first)
163
length=(uint) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
163
164
val_buffer->length(length);
165
166
return val_buffer;
168
int Int64::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
170
bool Field_int64_t::send_binary(Protocol *protocol)
172
return protocol->store_int64_t(Field_int64_t::val_int(), false);
176
int Field_int64_t::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
179
#ifdef WORDS_BIGENDIAN
180
if (table->s->db_low_byte_first)
175
191
return (a < b) ? -1 : (a > b) ? 1 : 0;
178
void Int64::sort_string(unsigned char *to,uint32_t )
194
void Field_int64_t::sort_string(unsigned char *to,uint32_t )
180
196
#ifdef WORDS_BIGENDIAN
197
if (!table->s->db_low_byte_first)
182
199
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
206
void Int64::sql_type(String &res) const
223
void Field_int64_t::sql_type(String &res) const
208
225
const CHARSET_INFO * const cs=res.charset();
209
226
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "bigint"));
213
unsigned char *Int64::pack(unsigned char* to, const unsigned char *from, uint32_t, bool)
230
unsigned char *Field_int64_t::pack(unsigned char* to, const unsigned char *from,
232
#ifdef WORDS_BIGENDIAN
217
int64_tget(val, from);
218
int64_tstore(to, val);
240
#ifdef WORDS_BIGENDIAN
241
if (table->s->db_low_byte_first)
242
val = sint8korr(from);
245
int64_tget(val, from);
247
#ifdef WORDS_BIGENDIAN
252
int64_tstore(to, val);
220
253
return to + sizeof(val);
224
const unsigned char *Int64::unpack(unsigned char* to, const unsigned char *from, uint32_t, bool)
257
const unsigned char *Field_int64_t::unpack(unsigned char* to, const unsigned char *from, uint32_t,
258
#ifdef WORDS_BIGENDIAN
228
int64_tget(val, from);
229
int64_tstore(to, val);
266
#ifdef WORDS_BIGENDIAN
268
val = sint8korr(from);
271
int64_tget(val, from);
273
#ifdef WORDS_BIGENDIAN
274
if (table->s->db_low_byte_first)
278
int64_tstore(to, val);
231
279
return from + sizeof(val);
234
} /* namespace field */
235
} /* namespace drizzled */