22
#include <drizzled/server_includes.h>
23
#include <drizzled/field/int64_t.h>
23
#include <drizzled/field/int64.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/table.h>
26
26
#include <drizzled/session.h>
30
#if defined(CMATH_NAMESPACE)
31
using namespace CMATH_NAMESPACE;
27
#include <drizzled/internal/my_sys.h>
34
38
/****************************************************************************
35
Field type int64_t int (8 bytes)
36
****************************************************************************/
39
Field type Int64 int (8 bytes)
40
****************************************************************************/
38
int Field_int64_t::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
42
int Int64::store(const char *from,uint32_t len, const charset_info_st * const cs)
44
tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
45
if (error == MY_ERRNO_ERANGE)
47
ASSERT_COLUMN_MARKED_FOR_WRITE;
49
uint64_t tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
47
52
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
50
else if (table->in_use->count_cuted_fields &&
51
check_int(cs, from, len, end, error))
55
else if (getTable()->in_use->count_cuted_fields && check_int(cs, from, len, end, error))
55
#ifdef WORDS_BIGENDIAN
56
if (table->s->db_low_byte_first)
62
int64_tstore(ptr,tmp);
64
int64_tstore(ptr,tmp);
67
int Field_int64_t::store(double nr)
70
int Int64::store(double nr)
75
ASSERT_COLUMN_MARKED_FOR_WRITE;
74
79
if (nr <= (double) INT64_MIN)
82
87
error= (nr > (double) INT64_MAX);
88
95
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
90
#ifdef WORDS_BIGENDIAN
91
if (table->s->db_low_byte_first)
97
int64_tstore(ptr,res);
97
int64_tstore(ptr, res);
102
int Field_int64_t::store(int64_t nr, bool unsigned_val __attribute__((unused)))
103
int Int64::store(int64_t nr, bool arg)
106
#ifdef WORDS_BIGENDIAN
107
if (table->s->db_low_byte_first)
107
ASSERT_COLUMN_MARKED_FOR_WRITE;
108
if (arg && nr < 0) // Only a partial fix for overflow
110
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
113
int64_tstore(ptr,nr);
114
int64_tstore(ptr,nr);
118
double Field_int64_t::val_real(void)
120
double Int64::val_real() const
121
#ifdef WORDS_BIGENDIAN
122
if (table->s->db_low_byte_first)
124
ASSERT_COLUMN_MARKED_FOR_READ;
129
127
/* The following is open coded to avoid a bug in gcc 3.3 */
130
129
return (double) j;
134
int64_t Field_int64_t::val_int(void)
133
int64_t Int64::val_int() const
137
#ifdef WORDS_BIGENDIAN
138
if (table->s->db_low_byte_first)
137
ASSERT_COLUMN_MARKED_FOR_READ;
147
String *Field_int64_t::val_str(String *val_buffer,
148
String *val_ptr __attribute__((unused)))
145
String *Int64::val_str(String *val_buffer, String *) const
150
const CHARSET_INFO * const cs= &my_charset_bin;
147
const charset_info_st * const cs= &my_charset_bin;
152
uint32_t mlength=cmax(field_length+1,22*cs->mbmaxlen);
149
uint32_t mlength= max(field_length+1,22*cs->mbmaxlen);
153
150
val_buffer->alloc(mlength);
154
151
char *to=(char*) val_buffer->ptr();
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);
154
ASSERT_COLUMN_MARKED_FOR_READ;
158
length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
164
159
val_buffer->length(length);
166
161
return val_buffer;
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)
164
int Int64::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
179
#ifdef WORDS_BIGENDIAN
180
if (table->s->db_low_byte_first)
191
171
return (a < b) ? -1 : (a > b) ? 1 : 0;
194
void Field_int64_t::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
174
void Int64::sort_string(unsigned char *to,uint32_t )
196
176
#ifdef WORDS_BIGENDIAN
197
if (!table->s->db_low_byte_first)
199
178
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
223
void Field_int64_t::sql_type(String &res) const
225
const CHARSET_INFO * const cs=res.charset();
226
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "bigint"));
230
unsigned char *Field_int64_t::pack(unsigned char* to, const unsigned char *from,
232
#ifdef WORDS_BIGENDIAN
201
unsigned char *Int64::pack(unsigned char* to, const unsigned char *from, uint32_t, bool)
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);
205
int64_tget(val, from);
206
int64_tstore(to, val);
253
208
return to + sizeof(val);
257
const unsigned char *Field_int64_t::unpack(unsigned char* to, const unsigned char *from, uint32_t,
258
#ifdef WORDS_BIGENDIAN
212
const unsigned char *Int64::unpack(unsigned char* to, const unsigned char *from, uint32_t, bool)
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);
216
int64_tget(val, from);
217
int64_tstore(to, val);
279
219
return from + sizeof(val);
222
} /* namespace field */
223
} /* namespace drizzled */