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
int Size::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 && check_int(cs, from, len, end, error))
68
int64_tstore(ptr,tmp);
74
int Size::store(double nr)
79
ASSERT_COLUMN_MARKED_FOR_WRITE;
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);
100
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
104
int64_tstore(ptr, res);
110
int Size::store(int64_t nr, bool arg)
114
ASSERT_COLUMN_MARKED_FOR_WRITE;
116
if (not arg and nr < 0)
118
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
122
int64_tstore(ptr,nr);
128
double Size::val_real(void)
132
ASSERT_COLUMN_MARKED_FOR_READ;
140
int64_t Size::val_int(void)
144
ASSERT_COLUMN_MARKED_FOR_READ;
152
String *Size::val_str(String *val_buffer, String *)
154
const CHARSET_INFO * const cs= &my_charset_bin;
156
uint32_t mlength= max(field_length+1,22*cs->mbmaxlen);
157
val_buffer->alloc(mlength);
158
char *to=(char*) val_buffer->ptr();
161
ASSERT_COLUMN_MARKED_FOR_READ;
165
length=(uint32_t) (cs->cset->int64_t10_to_str)(cs,to,mlength, -10, j);
166
val_buffer->length(length);
171
int Size::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
178
return (a < b) ? -1 : (a > b) ? 1 : 0;
181
void Size::sort_string(unsigned char *to,uint32_t )
183
#ifdef WORDS_BIGENDIAN
185
to[0] = (char) (ptr[0] ^ 128); /* Revers signbit */
196
to[0] = (char) (ptr[7] ^ 128); /* Revers signbit */
209
void Size::sql_type(String &res) const
211
const CHARSET_INFO * const cs=res.charset();
212
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(), "unsigned integer"));
216
unsigned char *Size::pack(unsigned char* to, const unsigned char *from, uint32_t, bool)
220
int64_tget(val, from);
221
int64_tstore(to, val);
223
return to + sizeof(val);
227
const unsigned char *Size::unpack(unsigned char* to, const unsigned char *from, uint32_t, bool)
231
int64_tget(val, from);
232
int64_tstore(to, val);
234
return from + sizeof(val);
237
} /* namespace field */
238
} /* namespace drizzled */