18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include <drizzled/field/int32.h>
24
#include <drizzled/error.h>
25
#include <drizzled/table.h>
26
#include <drizzled/session.h>
21
#ifdef USE_PRAGMA_IMPLEMENTATION
22
#pragma implementation // gcc: Class implementation
25
#include <drizzled/server_includes.h>
26
#include <drizzled/field/long.h>
40
28
/****************************************************************************
42
****************************************************************************/
30
****************************************************************************/
44
int Int32::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
32
int Field_long::store(const char *from,uint len, const CHARSET_INFO * const cs)
38
error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
39
store_tmp= unsigned_flag ? (long) (uint64_t) rnd : (long) rnd;
40
#ifdef WORDS_BIGENDIAN
41
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;
43
int4store(ptr, store_tmp);
54
47
longstore(ptr, store_tmp);
52
int Field_long::store(double nr)
64
else if (nr > (double) UINT32_MAX)
67
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
71
res=(int32_t) (uint32_t) nr;
60
int Int32::store(double nr)
66
ASSERT_COLUMN_MARKED_FOR_WRITE;
68
75
if (nr < (double) INT32_MIN)
70
77
res=(int32_t) INT32_MIN;
79
86
res=(int32_t) (int64_t) nr;
82
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
89
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
91
#ifdef WORDS_BIGENDIAN
92
if (table->s->db_low_byte_first)
84
98
longstore(ptr,res);
103
int Field_long::store(int64_t nr, bool unsigned_val)
110
if (nr < 0 && !unsigned_val)
115
else if (nr > INT32_MAX)
121
res=(int32_t) (uint32_t) nr;
90
int Int32::store(int64_t nr, bool unsigned_val)
95
ASSERT_COLUMN_MARKED_FOR_WRITE;
97
125
if (nr < 0 && unsigned_val)
98
126
nr= ((int64_t) INT32_MAX) + 1; // Generate overflow
100
if (nr < (int64_t) INT32_MIN)
127
if (nr < (int64_t) INT32_MIN)
102
129
res=(int32_t) INT32_MIN;
112
138
res=(int32_t) nr;
116
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
141
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
143
#ifdef WORDS_BIGENDIAN
144
if (table->s->db_low_byte_first)
118
150
longstore(ptr,res);
124
double Int32::val_real(void) const
128
ASSERT_COLUMN_MARKED_FOR_READ;
135
int64_t Int32::val_int(void) const
139
ASSERT_COLUMN_MARKED_FOR_READ;
146
String *Int32::val_str(String *val_buffer, String *) const
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;
155
double Field_long::val_real(void)
158
#ifdef WORDS_BIGENDIAN
159
if (table->s->db_low_byte_first)
164
return unsigned_flag ? (double) (uint32_t) j : (double) j;
167
int64_t Field_long::val_int(void)
170
/* See the comment in Field_long::store(long long) */
171
assert(table->in_use == current_thd);
172
#ifdef WORDS_BIGENDIAN
173
if (table->s->db_low_byte_first)
178
return unsigned_flag ? (int64_t) (uint32_t) j : (int64_t) j;
181
String *Field_long::val_str(String *val_buffer,
182
String *val_ptr __attribute__((unused)))
184
const CHARSET_INFO * const cs= &my_charset_bin;
186
uint mlength=max(field_length+1,12*cs->mbmaxlen);
187
val_buffer->alloc(mlength);
188
char *to=(char*) val_buffer->ptr();
190
#ifdef WORDS_BIGENDIAN
191
if (table->s->db_low_byte_first)
198
length=cs->cset->long10_to_str(cs,to,mlength, 10,(long) (uint32_t)j);
159
200
length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
160
val_buffer->length(length);
201
val_buffer->length(length);
207
bool Field_long::send_binary(Protocol *protocol)
209
return protocol->store_long(Field_long::val_int());
212
int Field_long::cmp(const uchar *a_ptr, const uchar *b_ptr)
215
#ifdef WORDS_BIGENDIAN
216
if (table->s->db_low_byte_first)
165
int Int32::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
169
224
longget(a,a_ptr);
170
225
longget(b,b_ptr);
172
return (a < b) ? -1 : (a > b) ? 1 : 0;
228
return ((uint32_t) a < (uint32_t) b) ? -1 : ((uint32_t) a > (uint32_t) b) ? 1 : 0;
229
return (a < b) ? -1 : (a > b) ? 1 : 0;
175
void Int32::sort_string(unsigned char *to,uint32_t )
232
void Field_long::sort_string(uchar *to,uint length __attribute__((unused)))
234
#ifdef WORDS_BIGENDIAN
235
if (!table->s->db_low_byte_first)
177
#ifdef WORDS_BIGENDIAN
179
240
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
186
251
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 */
259
void Field_long::sql_type(String &res) const
261
const CHARSET_INFO * const cs=res.charset();
262
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "int"));