23
#include <drizzled/field/int64.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>
27
#include "drizzled/internal/my_sys.h"
33
33
using namespace std;
38
38
/****************************************************************************
39
Field type Int64 int (8 bytes)
40
****************************************************************************/
39
Field type int64_t int (8 bytes)
40
****************************************************************************/
42
int Int64::store(const char *from,uint32_t len, const charset_info_st * const cs)
42
int Field_int64_t::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
47
48
ASSERT_COLUMN_MARKED_FOR_WRITE;
49
uint64_t tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
50
tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
51
if (error == MY_ERRNO_ERANGE)
52
53
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
55
else if (getTable()->in_use->count_cuted_fields && check_int(cs, from, len, end, error))
56
else if (table->in_use->count_cuted_fields &&
57
check_int(cs, from, len, end, error))
61
#ifdef WORDS_BIGENDIAN
62
if (table->s->db_low_byte_first)
64
int64_tstore(ptr,tmp);
68
int64_tstore(ptr,tmp);
70
int Int64::store(double nr)
73
int Field_int64_t::store(double nr)
87
90
error= (nr > (double) INT64_MAX);
95
96
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
97
int64_tstore(ptr, res);
98
#ifdef WORDS_BIGENDIAN
99
if (table->s->db_low_byte_first)
105
int64_tstore(ptr,res);
103
int Int64::store(int64_t nr, bool arg)
110
int Field_int64_t::store(int64_t nr, bool )
107
114
ASSERT_COLUMN_MARKED_FOR_WRITE;
108
if (arg && nr < 0) // Only a partial fix for overflow
116
#ifdef WORDS_BIGENDIAN
117
if (table->s->db_low_byte_first)
110
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
114
int64_tstore(ptr,nr);
123
int64_tstore(ptr,nr);
120
double Int64::val_real() const
128
double Field_int64_t::val_real(void)
124
132
ASSERT_COLUMN_MARKED_FOR_READ;
134
#ifdef WORDS_BIGENDIAN
135
if (table->s->db_low_byte_first)
127
142
/* The following is open coded to avoid a bug in gcc 3.3 */
129
143
return (double) j;
133
int64_t Int64::val_int() const
147
int64_t Field_int64_t::val_int(void)
137
151
ASSERT_COLUMN_MARKED_FOR_READ;
153
#ifdef WORDS_BIGENDIAN
154
if (table->s->db_low_byte_first)
145
String *Int64::val_str(String *val_buffer, String *) const
163
String *Field_int64_t::val_str(String *val_buffer,
147
const charset_info_st * const cs= &my_charset_bin;
166
const CHARSET_INFO * const cs= &my_charset_bin;
149
168
uint32_t mlength= max(field_length+1,22*cs->mbmaxlen);
150
169
val_buffer->alloc(mlength);
154
173
ASSERT_COLUMN_MARKED_FOR_READ;
175
#ifdef WORDS_BIGENDIAN
176
if (table->s->db_low_byte_first)
158
182
length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
159
183
val_buffer->length(length);
161
185
return val_buffer;
164
int Int64::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
188
int Field_int64_t::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
191
#ifdef WORDS_BIGENDIAN
192
if (table->s->db_low_byte_first)
171
203
return (a < b) ? -1 : (a > b) ? 1 : 0;
174
void Int64::sort_string(unsigned char *to,uint32_t )
206
void Field_int64_t::sort_string(unsigned char *to,uint32_t )
176
208
#ifdef WORDS_BIGENDIAN
209
if (!table->s->db_low_byte_first)
178
211
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
235
void Field_int64_t::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(), "bigint"));
242
unsigned char *Field_int64_t::pack(unsigned char* to, const unsigned char *from,
244
#ifdef WORDS_BIGENDIAN
201
unsigned char *Int64::pack(unsigned char* to, const unsigned char *from, uint32_t, bool)
205
int64_tget(val, from);
206
int64_tstore(to, val);
252
#ifdef WORDS_BIGENDIAN
253
if (table->s->db_low_byte_first)
254
val = sint8korr(from);
257
int64_tget(val, from);
259
#ifdef WORDS_BIGENDIAN
264
int64_tstore(to, val);
208
265
return to + sizeof(val);
212
const unsigned char *Int64::unpack(unsigned char* to, const unsigned char *from, uint32_t, bool)
269
const unsigned char *Field_int64_t::unpack(unsigned char* to, const unsigned char *from, uint32_t,
270
#ifdef WORDS_BIGENDIAN
216
int64_tget(val, from);
217
int64_tstore(to, val);
278
#ifdef WORDS_BIGENDIAN
280
val = sint8korr(from);
283
int64_tget(val, from);
285
#ifdef WORDS_BIGENDIAN
286
if (table->s->db_low_byte_first)
290
int64_tstore(to, val);
219
291
return from + sizeof(val);
222
} /* namespace field */
223
294
} /* namespace drizzled */