23
#include <drizzled/field/int64.h>
24
#include <drizzled/error.h>
25
#include <drizzled/table.h>
26
#include <drizzled/session.h>
27
#include "drizzled/internal/my_sys.h"
22
#include <drizzled/server_includes.h>
23
#include <drizzled/field/int64_t.h>
41
25
/****************************************************************************
42
Field type Int64 int (8 bytes)
43
****************************************************************************/
26
Field type int64_t int (8 bytes)
27
****************************************************************************/
45
int Int64::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
29
int Field_int64_t::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
51
ASSERT_COLUMN_MARKED_FOR_WRITE;
53
tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
35
tmp= cs->cset->strntoull10rnd(cs,from,len,unsigned_flag,&end,&error);
54
36
if (error == MY_ERRNO_ERANGE)
56
38
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
59
else if (getTable()->in_use->count_cuted_fields &&
41
else if (table->in_use->count_cuted_fields &&
60
42
check_int(cs, from, len, end, error))
64
46
#ifdef WORDS_BIGENDIAN
65
if (getTable()->getShare()->db_low_byte_first)
47
if (table->s->db_low_byte_first)
67
49
int8store(ptr,tmp);
76
int Int64::store(double nr)
58
int Field_int64_t::store(double nr)
81
ASSERT_COLUMN_MARKED_FOR_WRITE;
85
if (nr <= (double) INT64_MIN)
88
error= (nr < (double) INT64_MIN);
90
else if (nr >= (double) (uint64_t) INT64_MAX)
93
error= (nr > (double) INT64_MAX);
71
else if (nr >= (double) UINT64_MAX)
77
res=(int64_t) (uint64_t) nr;
81
if (nr <= (double) INT64_MIN)
84
error= (nr < (double) INT64_MIN);
86
else if (nr >= (double) (uint64_t) INT64_MAX)
89
error= (nr > (double) INT64_MAX);
99
95
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
101
97
#ifdef WORDS_BIGENDIAN
102
if (getTable()->getShare()->db_low_byte_first)
98
if (table->s->db_low_byte_first)
104
100
int8store(ptr,res);
113
int Int64::store(int64_t nr, bool )
109
int Field_int64_t::store(int64_t nr, bool unsigned_val)
117
ASSERT_COLUMN_MARKED_FOR_WRITE;
113
if (nr < 0) // Only possible error
116
if field is unsigned and value is signed (< 0) or
117
if field is signed and value is unsigned we have an overflow
119
if (unsigned_flag != unsigned_val)
121
nr= unsigned_flag ? (uint64_t) 0 : (uint64_t) INT64_MAX;
122
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
119
127
#ifdef WORDS_BIGENDIAN
120
if (getTable()->getShare()->db_low_byte_first)
128
if (table->s->db_low_byte_first)
122
130
int8store(ptr,nr);
131
double Int64::val_real(void)
139
double Field_int64_t::val_real(void)
135
ASSERT_COLUMN_MARKED_FOR_READ;
137
142
#ifdef WORDS_BIGENDIAN
138
if (getTable()->getShare()->db_low_byte_first)
143
if (table->s->db_low_byte_first)
140
145
j=sint8korr(ptr);
144
149
int64_tget(j,ptr);
145
150
/* The following is open coded to avoid a bug in gcc 3.3 */
153
uint64_t tmp= (uint64_t) j;
154
return uint64_t2double(tmp);
146
156
return (double) j;
150
int64_t Int64::val_int(void)
160
int64_t Field_int64_t::val_int(void)
154
ASSERT_COLUMN_MARKED_FOR_READ;
156
163
#ifdef WORDS_BIGENDIAN
157
if (getTable()->getShare()->db_low_byte_first)
164
if (table->s->db_low_byte_first)
158
165
j=sint8korr(ptr);
166
String *Int64::val_str(String *val_buffer,
173
String *Field_int64_t::val_str(String *val_buffer,
174
String *val_ptr __attribute__((unused)))
169
176
const CHARSET_INFO * const cs= &my_charset_bin;
171
uint32_t mlength= max(field_length+1,22*cs->mbmaxlen);
178
uint32_t mlength=cmax(field_length+1,22*cs->mbmaxlen);
172
179
val_buffer->alloc(mlength);
173
180
char *to=(char*) val_buffer->ptr();
176
ASSERT_COLUMN_MARKED_FOR_READ;
178
182
#ifdef WORDS_BIGENDIAN
179
if (getTable()->getShare()->db_low_byte_first)
183
if (table->s->db_low_byte_first)
180
184
j=sint8korr(ptr);
183
187
int64_tget(j,ptr);
185
length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
189
length=(uint) (cs->cset->int64_t10_to_str)(cs,to,mlength,
190
unsigned_flag ? 10 : -10, j);
186
191
val_buffer->length(length);
188
193
return val_buffer;
191
int Int64::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
197
bool Field_int64_t::send_binary(Protocol *protocol)
199
return protocol->store_int64_t(Field_int64_t::val_int(), unsigned_flag);
203
int Field_int64_t::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
194
206
#ifdef WORDS_BIGENDIAN
195
if (getTable()->getShare()->db_low_byte_first)
207
if (table->s->db_low_byte_first)
197
209
a=sint8korr(a_ptr);
198
210
b=sint8korr(b_ptr);
203
215
int64_tget(a,a_ptr);
204
216
int64_tget(b,b_ptr);
219
return ((uint64_t) a < (uint64_t) b) ? -1 :
220
((uint64_t) a > (uint64_t) b) ? 1 : 0;
206
221
return (a < b) ? -1 : (a > b) ? 1 : 0;
209
void Int64::sort_string(unsigned char *to,uint32_t )
224
void Field_int64_t::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
211
226
#ifdef WORDS_BIGENDIAN
212
if (!getTable()->getShare()->db_low_byte_first)
227
if (!table->s->db_low_byte_first)
214
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
232
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
238
void Int64::sql_type(String &res) const
259
void Field_int64_t::sql_type(String &res) const
240
261
const CHARSET_INFO * const cs=res.charset();
241
262
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
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);
268
return to + sizeof(val);
272
const unsigned char *Int64::unpack(unsigned char* to, const unsigned char *from, uint32_t,
273
#ifdef WORDS_BIGENDIAN
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);
294
return from + sizeof(val);
297
} /* namespace field */
298
} /* namespace drizzled */