1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 MySQL
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#ifdef USE_PRAGMA_IMPLEMENTATION
22
#pragma implementation // gcc: Class implementation
27
/****************************************************************************
28
Field type int64_t int (8 bytes)
29
****************************************************************************/
31
int Field_int64_t::store(const char *from,uint len,CHARSET_INFO *cs)
37
tmp= cs->cset->strntoull10rnd(cs,from,len,unsigned_flag,&end,&error);
38
if (error == MY_ERRNO_ERANGE)
40
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
43
else if (table->in_use->count_cuted_fields &&
44
check_int(cs, from, len, end, error))
48
#ifdef WORDS_BIGENDIAN
49
if (table->s->db_low_byte_first)
55
int64_tstore(ptr,tmp);
60
int Field_int64_t::store(double nr)
73
else if (nr >= (double) UINT64_MAX)
79
res=(int64_t) (uint64_t) nr;
83
if (nr <= (double) INT64_MIN)
86
error= (nr < (double) INT64_MIN);
88
else if (nr >= (double) (uint64_t) INT64_MAX)
91
error= (nr > (double) INT64_MAX);
97
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
99
#ifdef WORDS_BIGENDIAN
100
if (table->s->db_low_byte_first)
106
int64_tstore(ptr,res);
111
int Field_int64_t::store(int64_t nr, bool unsigned_val)
115
if (nr < 0) // Only possible error
118
if field is unsigned and value is signed (< 0) or
119
if field is signed and value is unsigned we have an overflow
121
if (unsigned_flag != unsigned_val)
123
nr= unsigned_flag ? (uint64_t) 0 : (uint64_t) INT64_MAX;
124
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
129
#ifdef WORDS_BIGENDIAN
130
if (table->s->db_low_byte_first)
136
int64_tstore(ptr,nr);
141
double Field_int64_t::val_real(void)
144
#ifdef WORDS_BIGENDIAN
145
if (table->s->db_low_byte_first)
152
/* The following is open coded to avoid a bug in gcc 3.3 */
155
uint64_t tmp= (uint64_t) j;
156
return uint64_t2double(tmp);
162
int64_t Field_int64_t::val_int(void)
165
#ifdef WORDS_BIGENDIAN
166
if (table->s->db_low_byte_first)
175
String *Field_int64_t::val_str(String *val_buffer,
176
String *val_ptr __attribute__((unused)))
178
CHARSET_INFO *cs= &my_charset_bin;
180
uint mlength=max(field_length+1,22*cs->mbmaxlen);
181
val_buffer->alloc(mlength);
182
char *to=(char*) val_buffer->ptr();
184
#ifdef WORDS_BIGENDIAN
185
if (table->s->db_low_byte_first)
191
length=(uint) (cs->cset->int64_t10_to_str)(cs,to,mlength,
192
unsigned_flag ? 10 : -10, j);
193
val_buffer->length(length);
195
prepend_zeros(val_buffer);
200
bool Field_int64_t::send_binary(Protocol *protocol)
202
return protocol->store_int64_t(Field_int64_t::val_int(), unsigned_flag);
206
int Field_int64_t::cmp(const uchar *a_ptr, const uchar *b_ptr)
209
#ifdef WORDS_BIGENDIAN
210
if (table->s->db_low_byte_first)
222
return ((uint64_t) a < (uint64_t) b) ? -1 :
223
((uint64_t) a > (uint64_t) b) ? 1 : 0;
224
return (a < b) ? -1 : (a > b) ? 1 : 0;
227
void Field_int64_t::sort_string(uchar *to,uint length __attribute__((unused)))
229
#ifdef WORDS_BIGENDIAN
230
if (!table->s->db_low_byte_first)
235
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
250
to[0] = (char) (ptr[7] ^ 128); /* Revers signbit */
262
void Field_int64_t::sql_type(String &res) const
264
CHARSET_INFO *cs=res.charset();
265
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
266
"bigint(%d)",(int) field_length));
267
add_zerofill_and_unsigned(res);
272
Floating-point numbers
276
Field_real::pack(uchar *to, const uchar *from,
277
uint max_length, bool low_byte_first)
279
assert(max_length >= pack_length());
280
#ifdef WORDS_BIGENDIAN
281
if (low_byte_first != table->s->db_low_byte_first)
283
const uchar *dptr= from + pack_length();
284
while (dptr-- > from)
290
return(Field::pack(to, from, max_length, low_byte_first));
294
Field_real::unpack(uchar *to, const uchar *from,
295
uint param_data, bool low_byte_first)
297
#ifdef WORDS_BIGENDIAN
298
if (low_byte_first != table->s->db_low_byte_first)
300
const uchar *dptr= from + pack_length();
301
while (dptr-- > from)
303
return(from + pack_length());
307
return(Field::unpack(to, from, param_data, low_byte_first));