22
#include <drizzled/server_includes.h>
23
#include <drizzled/field/long.h>
23
#include <drizzled/field/int32.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/table.h>
26
26
#include <drizzled/session.h>
29
#if defined(CMATH_NAMESPACE)
30
using namespace CMATH_NAMESPACE;
33
37
/****************************************************************************
35
****************************************************************************/
39
****************************************************************************/
37
int Field_long::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
43
error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
44
store_tmp= (long) rnd;
45
#ifdef WORDS_BIGENDIAN
46
if (table->s->db_low_byte_first)
41
int Int32::store(const char *from,uint32_t len, const charset_info_st * const cs)
48
int4store(ptr, store_tmp);
43
ASSERT_COLUMN_MARKED_FOR_WRITE;
45
int error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
46
long store_tmp= (long) rnd;
52
47
longstore(ptr, store_tmp);
57
int Field_long::store(double nr)
63
if (nr < (double) INT32_MIN)
65
res=(int32_t) INT32_MIN;
68
else if (nr > (double) INT32_MAX)
70
res=(int32_t) INT32_MAX;
74
res=(int32_t) (int64_t) nr;
77
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
79
#ifdef WORDS_BIGENDIAN
80
if (table->s->db_low_byte_first)
91
int Field_long::store(int64_t nr, bool unsigned_val)
96
if (nr < 0 && unsigned_val)
97
nr= ((int64_t) INT32_MAX) + 1; // Generate overflow
98
if (nr < (int64_t) INT32_MIN)
100
res=(int32_t) INT32_MIN;
103
else if (nr > (int64_t) INT32_MAX)
105
res=(int32_t) INT32_MAX;
112
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
114
#ifdef WORDS_BIGENDIAN
115
if (table->s->db_low_byte_first)
126
double Field_long::val_real(void)
129
#ifdef WORDS_BIGENDIAN
130
if (table->s->db_low_byte_first)
138
int64_t Field_long::val_int(void)
141
/* See the comment in Field_long::store(int64_t) */
142
assert(table->in_use == current_session);
143
#ifdef WORDS_BIGENDIAN
144
if (table->s->db_low_byte_first)
152
String *Field_long::val_str(String *val_buffer,
153
String *val_ptr __attribute__((unused)))
155
const CHARSET_INFO * const cs= &my_charset_bin;
157
uint32_t mlength=cmax(field_length+1,12*cs->mbmaxlen);
158
val_buffer->alloc(mlength);
159
char *to=(char*) val_buffer->ptr();
161
#ifdef WORDS_BIGENDIAN
162
if (table->s->db_low_byte_first)
168
length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
169
val_buffer->length(length);
175
bool Field_long::send_binary(Protocol *protocol)
177
return protocol->store_long(Field_long::val_int());
180
int Field_long::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
183
#ifdef WORDS_BIGENDIAN
184
if (table->s->db_low_byte_first)
52
int Int32::store(double nr)
58
ASSERT_COLUMN_MARKED_FOR_WRITE;
60
if (nr < (double) INT32_MIN)
62
res=(int32_t) INT32_MIN;
65
else if (nr > (double) INT32_MAX)
67
res=(int32_t) INT32_MAX;
71
res=(int32_t) (int64_t) nr;
74
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
82
int Int32::store(int64_t nr, bool unsigned_val)
87
ASSERT_COLUMN_MARKED_FOR_WRITE;
89
if (nr < 0 && unsigned_val)
90
nr= ((int64_t) INT32_MAX) + 1; // Generate overflow
92
if (nr < (int64_t) INT32_MIN)
94
res=(int32_t) INT32_MIN;
97
else if (nr > (int64_t) INT32_MAX)
99
res=(int32_t) INT32_MAX;
108
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
116
double Int32::val_real(void) const
120
ASSERT_COLUMN_MARKED_FOR_READ;
127
int64_t Int32::val_int(void) const
131
ASSERT_COLUMN_MARKED_FOR_READ;
138
String *Int32::val_str(String *val_buffer, String *) const
140
const charset_info_st * const cs= &my_charset_bin;
142
uint32_t mlength= max(field_length+1,12*cs->mbmaxlen);
143
val_buffer->alloc(mlength);
144
char *to=(char*) val_buffer->ptr();
147
ASSERT_COLUMN_MARKED_FOR_READ;
151
length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
152
val_buffer->length(length);
157
int Int32::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
192
161
longget(a,a_ptr);
193
162
longget(b,b_ptr);
196
return (a < b) ? -1 : (a > b) ? 1 : 0;
199
void Field_long::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
201
#ifdef WORDS_BIGENDIAN
202
if (!table->s->db_low_byte_first)
204
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
212
to[0] = (char) (ptr[3] ^ 128); /* Revers signbit */
220
void Field_long::sql_type(String &res) const
222
const CHARSET_INFO * const cs=res.charset();
223
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "int"));
226
unsigned char *Field_long::pack(unsigned char* to, const unsigned char *from,
228
#ifdef WORDS_BIGENDIAN
236
#ifdef WORDS_BIGENDIAN
237
if (table->s->db_low_byte_first)
238
val = sint4korr(from);
243
#ifdef WORDS_BIGENDIAN
249
return to + sizeof(val);
253
const unsigned char *Field_long::unpack(unsigned char* to, const unsigned char *from, uint32_t,
254
#ifdef WORDS_BIGENDIAN
262
#ifdef WORDS_BIGENDIAN
264
val = sint4korr(from);
269
#ifdef WORDS_BIGENDIAN
270
if (table->s->db_low_byte_first)
275
return from + sizeof(val);
164
return (a < b) ? -1 : (a > b) ? 1 : 0;
167
void Int32::sort_string(unsigned char *to,uint32_t )
169
#ifdef WORDS_BIGENDIAN
171
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
178
to[0] = (char) (ptr[3] ^ 128); /* Revers signbit */
187
unsigned char *Int32::pack(unsigned char* to, const unsigned char *from, uint32_t, bool)
193
return to + sizeof(val);
197
const unsigned char *Int32::unpack(unsigned char* to, const unsigned char *from, uint32_t, bool)
204
return from + sizeof(val);
207
} /* namespace field */
208
} /* namespace drizzled */