18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#ifdef USE_PRAGMA_IMPLEMENTATION
22
#pragma implementation // gcc: Class implementation
25
#include <drizzled/server_includes.h>
26
#include <drizzled/field/long.h>
23
#include <drizzled/field/int32.h>
24
#include <drizzled/error.h>
25
#include <drizzled/table.h>
26
#include <drizzled/session.h>
28
40
/****************************************************************************
30
****************************************************************************/
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;
42
****************************************************************************/
44
int Int32::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
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;
40
54
#ifdef WORDS_BIGENDIAN
41
if (table->s->db_low_byte_first)
43
int4store(ptr, store_tmp);
55
if (getTable()->getShare()->db_low_byte_first)
57
int4store(ptr, store_tmp);
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;
61
longstore(ptr, store_tmp);
66
int Int32::store(double nr)
72
ASSERT_COLUMN_MARKED_FOR_WRITE;
75
74
if (nr < (double) INT32_MIN)
77
76
res=(int32_t) INT32_MIN;
86
85
res=(int32_t) (int64_t) nr;
89
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
88
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
91
90
#ifdef WORDS_BIGENDIAN
92
if (table->s->db_low_byte_first)
91
if (getTable()->getShare()->db_low_byte_first)
103
int Field_long::store(int64_t nr, bool unsigned_val)
110
if (nr < 0 && !unsigned_val)
115
else if ((uint64_t) nr >= (1LL << 32))
117
res=(int32_t) (uint32_t) ~0L;
121
res=(int32_t) (uint32_t) nr;
102
int Int32::store(int64_t nr, bool unsigned_val)
107
ASSERT_COLUMN_MARKED_FOR_WRITE;
125
109
if (nr < 0 && unsigned_val)
126
110
nr= ((int64_t) INT32_MAX) + 1; // Generate overflow
127
if (nr < (int64_t) INT32_MIN)
111
if (nr < (int64_t) INT32_MIN)
129
113
res=(int32_t) INT32_MIN;
138
122
res=(int32_t) nr;
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)
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);
125
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
127
#ifdef WORDS_BIGENDIAN
128
if (getTable()->getShare()->db_low_byte_first)
139
double Int32::val_real(void)
143
ASSERT_COLUMN_MARKED_FOR_READ;
145
#ifdef WORDS_BIGENDIAN
146
if (getTable()->getShare()->db_low_byte_first)
154
int64_t Int32::val_int(void)
158
ASSERT_COLUMN_MARKED_FOR_READ;
160
/* See the comment in Int32::store(int64_t) */
161
#ifdef WORDS_BIGENDIAN
162
if (getTable()->getShare()->db_low_byte_first)
170
String *Int32::val_str(String *val_buffer,
173
const CHARSET_INFO * const cs= &my_charset_bin;
175
uint32_t mlength= max(field_length+1,12*cs->mbmaxlen);
176
val_buffer->alloc(mlength);
177
char *to=(char*) val_buffer->ptr();
180
ASSERT_COLUMN_MARKED_FOR_READ;
182
#ifdef WORDS_BIGENDIAN
183
if (getTable()->getShare()->db_low_byte_first)
200
189
length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
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)
190
val_buffer->length(length);
195
int Int32::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
215
198
#ifdef WORDS_BIGENDIAN
216
if (table->s->db_low_byte_first)
199
if (getTable()->getShare()->db_low_byte_first)
211
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;
232
void Field_long::sort_string(uchar *to,uint length __attribute__((unused)))
214
void Int32::sort_string(unsigned char *to,uint32_t )
234
216
#ifdef WORDS_BIGENDIAN
235
if (!table->s->db_low_byte_first)
217
if (!getTable()->getShare()->db_low_byte_first)
240
219
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
251
227
to[0] = (char) (ptr[3] ^ 128); /* Revers signbit */
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"));
235
void Int32::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(), "int"));
241
unsigned char *Int32::pack(unsigned char* to, const unsigned char *from,
243
#ifdef WORDS_BIGENDIAN
251
#ifdef WORDS_BIGENDIAN
252
if (getTable()->getShare()->db_low_byte_first)
253
val = sint4korr(from);
258
#ifdef WORDS_BIGENDIAN
264
return to + sizeof(val);
268
const unsigned char *Int32::unpack(unsigned char* to, const unsigned char *from, uint32_t,
269
#ifdef WORDS_BIGENDIAN
277
#ifdef WORDS_BIGENDIAN
279
val = sint4korr(from);
284
#ifdef WORDS_BIGENDIAN
285
if (getTable()->getShare()->db_low_byte_first)
290
return from + sizeof(val);
293
} /* namespace field */
294
} /* namespace drizzled */