37
40
/****************************************************************************
39
****************************************************************************/
41
int Field_long::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
47
ASSERT_COLUMN_MARKED_FOR_WRITE;
49
error= get_int(cs, from, len, &rnd, UINT32_MAX, INT32_MIN, INT32_MAX);
50
store_tmp= (long) rnd;
51
#ifdef WORDS_BIGENDIAN
52
if (getTable()->getShare()->db_low_byte_first)
42
****************************************************************************/
44
int Int32::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
54
int4store(ptr, store_tmp);
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;
58
54
longstore(ptr, store_tmp);
63
int Field_long::store(double nr)
69
ASSERT_COLUMN_MARKED_FOR_WRITE;
71
if (nr < (double) INT32_MIN)
73
res=(int32_t) INT32_MIN;
76
else if (nr > (double) INT32_MAX)
78
res=(int32_t) INT32_MAX;
82
res=(int32_t) (int64_t) nr;
85
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
87
#ifdef WORDS_BIGENDIAN
88
if (getTable()->getShare()->db_low_byte_first)
99
int Field_long::store(int64_t nr, bool unsigned_val)
104
ASSERT_COLUMN_MARKED_FOR_WRITE;
106
if (nr < 0 && unsigned_val)
107
nr= ((int64_t) INT32_MAX) + 1; // Generate overflow
108
if (nr < (int64_t) INT32_MIN)
110
res=(int32_t) INT32_MIN;
113
else if (nr > (int64_t) INT32_MAX)
115
res=(int32_t) INT32_MAX;
122
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
124
#ifdef WORDS_BIGENDIAN
125
if (getTable()->getShare()->db_low_byte_first)
136
double Field_long::val_real(void)
140
ASSERT_COLUMN_MARKED_FOR_READ;
142
#ifdef WORDS_BIGENDIAN
143
if (getTable()->getShare()->db_low_byte_first)
151
int64_t Field_long::val_int(void)
155
ASSERT_COLUMN_MARKED_FOR_READ;
157
/* See the comment in Field_long::store(int64_t) */
158
#ifdef WORDS_BIGENDIAN
159
if (getTable()->getShare()->db_low_byte_first)
167
String *Field_long::val_str(String *val_buffer,
170
const CHARSET_INFO * const cs= &my_charset_bin;
172
uint32_t mlength= max(field_length+1,12*cs->mbmaxlen);
173
val_buffer->alloc(mlength);
174
char *to=(char*) val_buffer->ptr();
177
ASSERT_COLUMN_MARKED_FOR_READ;
179
#ifdef WORDS_BIGENDIAN
180
if (getTable()->getShare()->db_low_byte_first)
186
length=cs->cset->long10_to_str(cs,to,mlength,-10,(long) j);
187
val_buffer->length(length);
192
int Field_long::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
195
#ifdef WORDS_BIGENDIAN
196
if (getTable()->getShare()->db_low_byte_first)
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)
204
169
longget(a,a_ptr);
205
170
longget(b,b_ptr);
208
return (a < b) ? -1 : (a > b) ? 1 : 0;
211
void Field_long::sort_string(unsigned char *to,uint32_t )
213
#ifdef WORDS_BIGENDIAN
214
if (!getTable()->getShare()->db_low_byte_first)
216
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
224
to[0] = (char) (ptr[3] ^ 128); /* Revers signbit */
232
void Field_long::sql_type(String &res) const
234
const CHARSET_INFO * const cs=res.charset();
235
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "int"));
238
unsigned char *Field_long::pack(unsigned char* to, const unsigned char *from,
240
#ifdef WORDS_BIGENDIAN
248
#ifdef WORDS_BIGENDIAN
249
if (getTable()->getShare()->db_low_byte_first)
250
val = sint4korr(from);
255
#ifdef WORDS_BIGENDIAN
261
return to + sizeof(val);
265
const unsigned char *Field_long::unpack(unsigned char* to, const unsigned char *from, uint32_t,
266
#ifdef WORDS_BIGENDIAN
274
#ifdef WORDS_BIGENDIAN
276
val = sint4korr(from);
281
#ifdef WORDS_BIGENDIAN
282
if (getTable()->getShare()->db_low_byte_first)
287
return from + sizeof(val);
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 */
290
222
} /* namespace drizzled */