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
23
#include <drizzled/field/int64.h>
24
#include <drizzled/error.h>
25
#include <drizzled/table.h>
26
#include <drizzled/session.h>
27
#include "drizzled/internal/my_sys.h"
41
/****************************************************************************
42
Field type Int64 int (8 bytes)
43
****************************************************************************/
45
int Int64::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
51
ASSERT_COLUMN_MARKED_FOR_WRITE;
53
tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
54
if (error == MY_ERRNO_ERANGE)
56
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
59
else if (getTable()->in_use->count_cuted_fields &&
60
check_int(cs, from, len, end, error))
64
#ifdef WORDS_BIGENDIAN
65
if (getTable()->getShare()->db_low_byte_first)
71
int64_tstore(ptr,tmp);
76
int Int64::store(double nr)
81
ASSERT_COLUMN_MARKED_FOR_WRITE;
85
if (nr <= (double) INT64_MIN)
88
error= (nr < (double) INT64_MIN);
90
else if (nr >= (double) (uint64_t) INT64_MAX)
93
error= (nr > (double) INT64_MAX);
99
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
101
#ifdef WORDS_BIGENDIAN
102
if (getTable()->getShare()->db_low_byte_first)
108
int64_tstore(ptr,res);
113
int Int64::store(int64_t nr, bool )
117
ASSERT_COLUMN_MARKED_FOR_WRITE;
119
#ifdef WORDS_BIGENDIAN
120
if (getTable()->getShare()->db_low_byte_first)
126
int64_tstore(ptr,nr);
131
double Int64::val_real(void)
135
ASSERT_COLUMN_MARKED_FOR_READ;
137
#ifdef WORDS_BIGENDIAN
138
if (getTable()->getShare()->db_low_byte_first)
145
/* The following is open coded to avoid a bug in gcc 3.3 */
150
int64_t Int64::val_int(void)
154
ASSERT_COLUMN_MARKED_FOR_READ;
156
#ifdef WORDS_BIGENDIAN
157
if (getTable()->getShare()->db_low_byte_first)
166
String *Int64::val_str(String *val_buffer,
169
const CHARSET_INFO * const cs= &my_charset_bin;
171
uint32_t mlength= max(field_length+1,22*cs->mbmaxlen);
172
val_buffer->alloc(mlength);
173
char *to=(char*) val_buffer->ptr();
176
ASSERT_COLUMN_MARKED_FOR_READ;
178
#ifdef WORDS_BIGENDIAN
179
if (getTable()->getShare()->db_low_byte_first)
185
length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
186
val_buffer->length(length);
191
int Int64::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
194
#ifdef WORDS_BIGENDIAN
195
if (getTable()->getShare()->db_low_byte_first)
206
return (a < b) ? -1 : (a > b) ? 1 : 0;
209
void Int64::sort_string(unsigned char *to,uint32_t )
211
#ifdef WORDS_BIGENDIAN
212
if (!getTable()->getShare()->db_low_byte_first)
214
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
226
to[0] = (char) (ptr[7] ^ 128); /* Revers signbit */
238
void Int64::sql_type(String &res) const
240
const CHARSET_INFO * const cs=res.charset();
241
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "bigint"));
245
unsigned char *Int64::pack(unsigned char* to, const unsigned char *from,
247
#ifdef WORDS_BIGENDIAN
255
#ifdef WORDS_BIGENDIAN
256
if (getTable()->getShare()->db_low_byte_first)
257
val = sint8korr(from);
260
int64_tget(val, from);
262
#ifdef WORDS_BIGENDIAN
267
int64_tstore(to, val);
268
return to + sizeof(val);
272
const unsigned char *Int64::unpack(unsigned char* to, const unsigned char *from, uint32_t,
273
#ifdef WORDS_BIGENDIAN
281
#ifdef WORDS_BIGENDIAN
283
val = sint8korr(from);
286
int64_tget(val, from);
288
#ifdef WORDS_BIGENDIAN
289
if (getTable()->getShare()->db_low_byte_first)
293
int64_tstore(to, val);
294
return from + sizeof(val);
297
} /* namespace field */
298
} /* namespace drizzled */