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
22
#include <drizzled/server_includes.h>
23
#include <drizzled/field/int64_t.h>
25
/****************************************************************************
26
Field type int64_t int (8 bytes)
27
****************************************************************************/
29
int Field_int64_t::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
35
tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
36
if (error == MY_ERRNO_ERANGE)
38
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
41
else if (table->in_use->count_cuted_fields &&
42
check_int(cs, from, len, end, error))
46
#ifdef WORDS_BIGENDIAN
47
if (table->s->db_low_byte_first)
53
int64_tstore(ptr,tmp);
58
int Field_int64_t::store(double nr)
65
if (nr <= (double) INT64_MIN)
68
error= (nr < (double) INT64_MIN);
70
else if (nr >= (double) (uint64_t) INT64_MAX)
73
error= (nr > (double) INT64_MAX);
79
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
81
#ifdef WORDS_BIGENDIAN
82
if (table->s->db_low_byte_first)
88
int64_tstore(ptr,res);
93
int Field_int64_t::store(int64_t nr, bool unsigned_val __attribute__((unused)))
97
#ifdef WORDS_BIGENDIAN
98
if (table->s->db_low_byte_first)
104
int64_tstore(ptr,nr);
109
double Field_int64_t::val_real(void)
112
#ifdef WORDS_BIGENDIAN
113
if (table->s->db_low_byte_first)
120
/* The following is open coded to avoid a bug in gcc 3.3 */
125
int64_t Field_int64_t::val_int(void)
128
#ifdef WORDS_BIGENDIAN
129
if (table->s->db_low_byte_first)
138
String *Field_int64_t::val_str(String *val_buffer,
139
String *val_ptr __attribute__((unused)))
141
const CHARSET_INFO * const cs= &my_charset_bin;
143
uint32_t mlength=cmax(field_length+1,22*cs->mbmaxlen);
144
val_buffer->alloc(mlength);
145
char *to=(char*) val_buffer->ptr();
147
#ifdef WORDS_BIGENDIAN
148
if (table->s->db_low_byte_first)
154
length=(uint) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
155
val_buffer->length(length);
161
bool Field_int64_t::send_binary(Protocol *protocol)
163
return protocol->store_int64_t(Field_int64_t::val_int(), false);
167
int Field_int64_t::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
170
#ifdef WORDS_BIGENDIAN
171
if (table->s->db_low_byte_first)
182
return (a < b) ? -1 : (a > b) ? 1 : 0;
185
void Field_int64_t::sort_string(unsigned char *to,uint32_t length __attribute__((unused)))
187
#ifdef WORDS_BIGENDIAN
188
if (!table->s->db_low_byte_first)
190
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
202
to[0] = (char) (ptr[7] ^ 128); /* Revers signbit */
214
void Field_int64_t::sql_type(String &res) const
216
const CHARSET_INFO * const cs=res.charset();
217
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "bigint"));