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 "drizzle/server/field/long.h"
40
27
/****************************************************************************
42
****************************************************************************/
29
****************************************************************************/
44
int Int32::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
31
int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
37
error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
38
store_tmp= unsigned_flag ? (long) (uint64_t) rnd : (long) rnd;
39
#ifdef WORDS_BIGENDIAN
40
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;
42
int4store(ptr, store_tmp);
54
46
longstore(ptr, store_tmp);
51
int Field_long::store(double nr)
63
else if (nr > (double) UINT32_MAX)
66
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
70
res=(int32_t) (ulong) nr;
60
int Int32::store(double nr)
66
ASSERT_COLUMN_MARKED_FOR_WRITE;
68
74
if (nr < (double) INT32_MIN)
70
76
res=(int32_t) INT32_MIN;
79
85
res=(int32_t) (int64_t) nr;
82
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
88
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
90
#ifdef WORDS_BIGENDIAN
91
if (table->s->db_low_byte_first)
84
97
longstore(ptr,res);
102
int Field_long::store(int64_t nr, bool unsigned_val)
109
if (nr < 0 && !unsigned_val)
114
else if ((uint64_t) nr >= (1LL << 32))
116
res=(int32_t) (uint32_t) ~0L;
120
res=(int32_t) (uint32_t) nr;
90
int Int32::store(int64_t nr, bool unsigned_val)
95
ASSERT_COLUMN_MARKED_FOR_WRITE;
97
124
if (nr < 0 && unsigned_val)
98
125
nr= ((int64_t) INT32_MAX) + 1; // Generate overflow
100
if (nr < (int64_t) INT32_MIN)
126
if (nr < (int64_t) INT32_MIN)
102
128
res=(int32_t) INT32_MIN;
112
137
res=(int32_t) nr;
116
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
140
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
142
#ifdef WORDS_BIGENDIAN
143
if (table->s->db_low_byte_first)
118
149
longstore(ptr,res);
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;
154
double Field_long::val_real(void)
157
#ifdef WORDS_BIGENDIAN
158
if (table->s->db_low_byte_first)
163
return unsigned_flag ? (double) (uint32_t) j : (double) j;
166
int64_t Field_long::val_int(void)
169
/* See the comment in Field_long::store(long long) */
170
assert(table->in_use == current_thd);
171
#ifdef WORDS_BIGENDIAN
172
if (table->s->db_low_byte_first)
177
return unsigned_flag ? (int64_t) (uint32_t) j : (int64_t) j;
180
String *Field_long::val_str(String *val_buffer,
181
String *val_ptr __attribute__((unused)))
183
CHARSET_INFO *cs= &my_charset_bin;
185
uint mlength=max(field_length+1,12*cs->mbmaxlen);
186
val_buffer->alloc(mlength);
187
char *to=(char*) val_buffer->ptr();
189
#ifdef WORDS_BIGENDIAN
190
if (table->s->db_low_byte_first)
197
length=cs->cset->long10_to_str(cs,to,mlength, 10,(long) (uint32_t)j);
159
199
length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
160
val_buffer->length(length);
200
val_buffer->length(length);
202
prepend_zeros(val_buffer);
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
CHARSET_INFO *cs=res.charset();
262
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
263
"int(%d)",(int) field_length));
264
add_zerofill_and_unsigned(res);