1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
22
#include <drizzled/item/cache_str.h>
27
Item_cache_str::Item_cache_str(const Item *item) :
28
Item_cache(), value(0),
29
is_varbinary(item->type() == FIELD_ITEM &&
30
((const Item_field *) item)->field->type() ==
31
DRIZZLE_TYPE_VARCHAR &&
32
!((const Item_field *) item)->field->has_charset())
35
void Item_cache_str::store(Item *item)
37
value_buff.set(buffer, sizeof(buffer), item->collation.collation);
38
value= item->str_result(&value_buff);
39
if ((null_value= item->null_value))
41
else if (value != &value_buff)
44
We copy string value to avoid changing value if 'item' is table field
45
in queries like following (where t1.c is varchar):
47
(select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),
48
(select c from t1 where a=t2.a)
51
value_buff.copy(*value);
56
double Item_cache_str::val_real()
62
return my_strntod(value->charset(), (char*) value->ptr(),
63
value->length(), &end_not_used, &err_not_used);
68
int64_t Item_cache_str::val_int()
73
return my_strntoll(value->charset(), value->ptr(),
74
value->length(), 10, (char**) 0, &err);
79
my_decimal *Item_cache_str::val_decimal(my_decimal *decimal_val)
83
string2my_decimal(E_DEC_FATAL_ERROR, value, decimal_val);
89
int Item_cache_str::save_in_field(Field *field, bool no_conversions)
91
int res= Item_cache::save_in_field(field, no_conversions);
96
} /* namespace drizzled */