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/size.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 Size int (8 bytes)
43
****************************************************************************/
45
Size::Size(unsigned char *ptr_arg, uint32_t len_arg,
46
unsigned char *null_ptr_arg,
47
unsigned char null_bit_arg,
48
enum utype unireg_check_arg,
49
const char *field_name_arg) :
58
flags|= UNSIGNED_FLAG;
61
Size::Size(uint32_t len_arg,bool maybe_null_arg,
62
const char *field_name_arg,
64
Field_num((unsigned char*) 0,
65
len_arg, maybe_null_arg ? (unsigned char*) "": 0,
73
flags|= UNSIGNED_FLAG;
77
int Size::store(const char *from,uint32_t len, const CHARSET_INFO * const cs)
83
ASSERT_COLUMN_MARKED_FOR_WRITE;
85
tmp= cs->cset->strntoull10rnd(cs, from, len, false, &end,&error);
86
if (error == MY_ERRNO_ERANGE)
88
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
91
else if (getTable()->in_use->count_cuted_fields && check_int(cs, from, len, end, error))
100
int64_tstore(ptr,tmp);
106
int Size::store(double nr)
111
ASSERT_COLUMN_MARKED_FOR_WRITE;
115
if (nr <= (double) INT64_MIN)
118
error= (nr < (double) INT64_MIN);
120
else if (nr >= (double) (uint64_t) INT64_MAX)
123
error= (nr > (double) INT64_MAX);
132
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
136
int64_tstore(ptr, res);
142
int Size::store(int64_t nr, bool arg)
146
ASSERT_COLUMN_MARKED_FOR_WRITE;
148
if (not arg and nr < 0)
150
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
154
int64_tstore(ptr,nr);
160
double Size::val_real(void)
164
ASSERT_COLUMN_MARKED_FOR_READ;
172
int64_t Size::val_int(void)
176
ASSERT_COLUMN_MARKED_FOR_READ;
184
String *Size::val_str(String *val_buffer, String *)
186
const CHARSET_INFO * const cs= &my_charset_bin;
188
uint32_t mlength= max(field_length+1,22*cs->mbmaxlen);
189
val_buffer->alloc(mlength);
190
char *to=(char*) val_buffer->ptr();
193
ASSERT_COLUMN_MARKED_FOR_READ;
197
length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
198
val_buffer->length(length);
203
int Size::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
210
return (a < b) ? -1 : (a > b) ? 1 : 0;
213
void Size::sort_string(unsigned char *to,uint32_t )
215
#ifdef WORDS_BIGENDIAN
217
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
228
to[0] = (char) (ptr[7] ^ 128); /* Revers signbit */
241
void Size::sql_type(String &res) const
243
const CHARSET_INFO * const cs=res.charset();
244
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "unsigned integer"));
248
unsigned char *Size::pack(unsigned char* to, const unsigned char *from, uint32_t, bool)
252
int64_tget(val, from);
253
int64_tstore(to, val);
255
return to + sizeof(val);
259
const unsigned char *Size::unpack(unsigned char* to, const unsigned char *from, uint32_t, bool)
263
int64_tget(val, from);
264
int64_tstore(to, val);
266
return from + sizeof(val);
269
} /* namespace field */
270
} /* namespace drizzled */