642.1.6
by Lee
move functions from item.cc/item.h to item directory |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
5 |
*
|
|
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; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
19 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
20 |
#include "config.h" |
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
21 |
#include <drizzled/item/int.h> |
1241.9.64
by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal. |
22 |
#include "drizzled/internal/m_string.h" |
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
23 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
24 |
namespace drizzled |
25 |
{
|
|
26 |
||
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
27 |
/**
|
28 |
Create an item from a string we KNOW points to a valid int64_t
|
|
29 |
end \\0 terminated number string.
|
|
30 |
This is always 'signed'. Unsigned values are created with Item_uint()
|
|
31 |
*/
|
|
32 |
||
33 |
Item_int::Item_int(const char *str_arg, uint32_t length) |
|
34 |
{
|
|
35 |
char *end_ptr= (char*) str_arg + length; |
|
36 |
int error; |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
37 |
value= internal::my_strtoll10(str_arg, &end_ptr, &error); |
895
by Brian Aker
Completion (?) of uint conversion. |
38 |
max_length= (uint32_t) (end_ptr - str_arg); |
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
39 |
name= (char*) str_arg; |
40 |
fixed= 1; |
|
41 |
}
|
|
42 |
||
43 |
my_decimal *Item_int::val_decimal(my_decimal *decimal_value) |
|
44 |
{
|
|
45 |
int2my_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_value); |
|
46 |
return decimal_value; |
|
47 |
}
|
|
48 |
||
49 |
String *Item_int::val_str(String *str) |
|
50 |
{
|
|
51 |
// following assert is redundant, because fixed=1 assigned in constructor
|
|
52 |
assert(fixed == 1); |
|
53 |
str->set(value, &my_charset_bin); |
|
54 |
return str; |
|
55 |
}
|
|
56 |
||
57 |
void Item_int::print(String *str, enum_query_type) |
|
58 |
{
|
|
59 |
// my_charset_bin is good enough for numbers
|
|
60 |
str_value.set(value, &my_charset_bin); |
|
61 |
str->append(str_value); |
|
62 |
}
|
|
63 |
||
64 |
int Item_int::save_in_field(Field *field, bool) |
|
65 |
{
|
|
66 |
int64_t nr=val_int(); |
|
67 |
if (null_value) |
|
68 |
return set_field_to_null(field); |
|
69 |
field->set_notnull(); |
|
70 |
return field->store(nr, unsigned_flag); |
|
71 |
}
|
|
72 |
||
73 |
bool Item_int::eq(const Item *arg, bool) const |
|
74 |
{
|
|
75 |
/* No need to check for null value as basic constant can't be NULL */
|
|
76 |
if (arg->basic_const_item() && arg->type() == type()) |
|
77 |
{
|
|
78 |
/*
|
|
79 |
We need to cast off const to call val_int(). This should be OK for
|
|
80 |
a basic constant.
|
|
81 |
*/
|
|
82 |
Item *item= (Item*) arg; |
|
83 |
return item->val_int() == value && item->unsigned_flag == unsigned_flag; |
|
84 |
}
|
|
85 |
return false; |
|
86 |
}
|
|
87 |
||
88 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
89 |
} /* namespace drizzled */ |