23
#include <drizzled/field/int32.h>
22
#include <drizzled/server_includes.h>
23
#include <drizzled/field/long.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/table.h>
26
26
#include <drizzled/session.h>
30
28
#include <algorithm>
32
30
using namespace std;
40
33
/****************************************************************************
42
****************************************************************************/
44
int Int32::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
35
****************************************************************************/
37
int Field_long::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
43
ASSERT_COLUMN_MARKED_FOR_WRITE;
45
error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
46
store_tmp= (long) rnd;
47
#ifdef WORDS_BIGENDIAN
48
if (table->s->db_low_byte_first)
50
ASSERT_COLUMN_MARKED_FOR_WRITE;
52
error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
53
store_tmp= (long) rnd;
50
int4store(ptr, store_tmp);
54
54
longstore(ptr, store_tmp);
60
int Int32::store(double nr)
66
ASSERT_COLUMN_MARKED_FOR_WRITE;
68
if (nr < (double) INT32_MIN)
70
res=(int32_t) INT32_MIN;
73
else if (nr > (double) INT32_MAX)
75
res=(int32_t) INT32_MAX;
79
res=(int32_t) (int64_t) nr;
82
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
90
int Int32::store(int64_t nr, bool unsigned_val)
95
ASSERT_COLUMN_MARKED_FOR_WRITE;
97
if (nr < 0 && unsigned_val)
98
nr= ((int64_t) INT32_MAX) + 1; // Generate overflow
100
if (nr < (int64_t) INT32_MIN)
102
res=(int32_t) INT32_MIN;
105
else if (nr > (int64_t) INT32_MAX)
107
res=(int32_t) INT32_MAX;
116
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
124
double Int32::val_real(void)
128
ASSERT_COLUMN_MARKED_FOR_READ;
135
int64_t Int32::val_int(void)
139
ASSERT_COLUMN_MARKED_FOR_READ;
146
String *Int32::val_str(String *val_buffer, String *)
148
const CHARSET_INFO * const cs= &my_charset_bin;
150
uint32_t mlength= max(field_length+1,12*cs->mbmaxlen);
151
val_buffer->alloc(mlength);
152
char *to=(char*) val_buffer->ptr();
155
ASSERT_COLUMN_MARKED_FOR_READ;
159
length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
160
val_buffer->length(length);
165
int Int32::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
59
int Field_long::store(double nr)
65
ASSERT_COLUMN_MARKED_FOR_WRITE;
67
if (nr < (double) INT32_MIN)
69
res=(int32_t) INT32_MIN;
72
else if (nr > (double) INT32_MAX)
74
res=(int32_t) INT32_MAX;
78
res=(int32_t) (int64_t) nr;
81
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
83
#ifdef WORDS_BIGENDIAN
84
if (table->s->db_low_byte_first)
95
int Field_long::store(int64_t nr, bool unsigned_val)
100
ASSERT_COLUMN_MARKED_FOR_WRITE;
102
if (nr < 0 && unsigned_val)
103
nr= ((int64_t) INT32_MAX) + 1; // Generate overflow
104
if (nr < (int64_t) INT32_MIN)
106
res=(int32_t) INT32_MIN;
109
else if (nr > (int64_t) INT32_MAX)
111
res=(int32_t) INT32_MAX;
118
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
120
#ifdef WORDS_BIGENDIAN
121
if (table->s->db_low_byte_first)
132
double Field_long::val_real(void)
136
ASSERT_COLUMN_MARKED_FOR_READ;
138
#ifdef WORDS_BIGENDIAN
139
if (table->s->db_low_byte_first)
147
int64_t Field_long::val_int(void)
151
ASSERT_COLUMN_MARKED_FOR_READ;
153
/* See the comment in Field_long::store(int64_t) */
154
assert(table->in_use == current_session);
155
#ifdef WORDS_BIGENDIAN
156
if (table->s->db_low_byte_first)
164
String *Field_long::val_str(String *val_buffer,
167
const CHARSET_INFO * const cs= &my_charset_bin;
169
uint32_t mlength= max(field_length+1,12*cs->mbmaxlen);
170
val_buffer->alloc(mlength);
171
char *to=(char*) val_buffer->ptr();
174
ASSERT_COLUMN_MARKED_FOR_READ;
176
#ifdef WORDS_BIGENDIAN
177
if (table->s->db_low_byte_first)
183
length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
184
val_buffer->length(length);
189
int Field_long::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
192
#ifdef WORDS_BIGENDIAN
193
if (table->s->db_low_byte_first)
169
201
longget(a,a_ptr);
170
202
longget(b,b_ptr);
172
return (a < b) ? -1 : (a > b) ? 1 : 0;
175
void Int32::sort_string(unsigned char *to,uint32_t )
177
#ifdef WORDS_BIGENDIAN
179
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
186
to[0] = (char) (ptr[3] ^ 128); /* Revers signbit */
195
void Int32::sql_type(String &res) const
197
const CHARSET_INFO * const cs=res.charset();
198
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "int"));
201
unsigned char *Int32::pack(unsigned char* to, const unsigned char *from, uint32_t, bool)
207
return to + sizeof(val);
211
const unsigned char *Int32::unpack(unsigned char* to, const unsigned char *from, uint32_t, bool)
218
return from + sizeof(val);
221
} /* namespace field */
222
} /* namespace drizzled */
205
return (a < b) ? -1 : (a > b) ? 1 : 0;
208
void Field_long::sort_string(unsigned char *to,uint32_t )
210
#ifdef WORDS_BIGENDIAN
211
if (!table->s->db_low_byte_first)
213
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
221
to[0] = (char) (ptr[3] ^ 128); /* Revers signbit */
229
void Field_long::sql_type(String &res) const
231
const CHARSET_INFO * const cs=res.charset();
232
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "int"));
235
unsigned char *Field_long::pack(unsigned char* to, const unsigned char *from,
237
#ifdef WORDS_BIGENDIAN
245
#ifdef WORDS_BIGENDIAN
246
if (table->s->db_low_byte_first)
247
val = sint4korr(from);
252
#ifdef WORDS_BIGENDIAN
258
return to + sizeof(val);
262
const unsigned char *Field_long::unpack(unsigned char* to, const unsigned char *from, uint32_t,
263
#ifdef WORDS_BIGENDIAN
271
#ifdef WORDS_BIGENDIAN
273
val = sint4korr(from);
278
#ifdef WORDS_BIGENDIAN
279
if (table->s->db_low_byte_first)
284
return from + sizeof(val);