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
20
#include <drizzled/server_includes.h>
22
#include <drizzled/session.h>
23
#include <drizzled/error.h>
24
#include <drizzled/item/istring.h>
26
Item *Item_string::safe_charset_converter(const CHARSET_INFO * const tocs)
31
String tmp, cstr, *ostr= val_str(&tmp);
32
cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
33
if (conv_errors || !(conv= new Item_string(cstr.ptr(), cstr.length(),
35
collation.derivation)))
38
Safe conversion is not possible (or EOM).
39
We could not convert a string into the requested character set
40
without data loss. The target charset does not cover all the
41
characters from the string. Operation cannot be done correctly.
45
if (!(ptr= current_session->strmake(cstr.ptr(), cstr.length())))
47
conv->str_value.set(ptr, cstr.length(), cstr.charset());
48
/* Ensure that no one is going to change the result string */
49
conv->str_value.mark_as_const();
54
Item *Item_static_string_func::safe_charset_converter(const CHARSET_INFO * const tocs)
58
String tmp, cstr, *ostr= val_str(&tmp);
59
cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
61
!(conv= new Item_static_string_func(func_name,
62
cstr.ptr(), cstr.length(),
64
collation.derivation)))
67
Safe conversion is not possible (or EOM).
68
We could not convert a string into the requested character set
69
without data loss. The target charset does not cover all the
70
characters from the string. Operation cannot be done correctly.
74
conv->str_value.copy();
75
/* Ensure that no one is going to change the result string */
76
conv->str_value.mark_as_const();
81
bool Item_string::eq(const Item *item, bool binary_cmp) const
83
if (type() == item->type() && item->basic_const_item())
86
return !stringcmp(&str_value, &item->str_value);
87
return (collation.collation == item->collation.collation &&
88
!sortcmp(&str_value, &item->str_value, collation.collation));
93
void Item_string::print(String *str, enum_query_type query_type)
95
if (query_type == QT_ORDINARY && is_cs_specified())
98
str->append(collation.collation->csname);
103
if (query_type == QT_ORDINARY ||
104
my_charset_same(str_value.charset(), system_charset_info))
106
str_value.print(str);
110
Session *session= current_session;
111
LEX_STRING utf8_lex_str;
113
session->convert_string(&utf8_lex_str,
115
str_value.c_ptr_safe(),
117
str_value.charset());
119
String utf8_str(utf8_lex_str.str,
121
system_charset_info);
129
double Item_string::val_real()
135
const CHARSET_INFO * const cs= str_value.charset();
137
org_end= (char*) str_value.ptr() + str_value.length();
138
tmp= my_strntod(cs, (char*) str_value.ptr(), str_value.length(), &end,
140
if (error || (end != org_end && !check_if_only_end_space(cs, end, org_end)))
143
We can use str_value.ptr() here as Item_string is gurantee to put an
146
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
147
ER_TRUNCATED_WRONG_VALUE,
148
ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
156
Give error if we wanted a signed integer and we got an unsigned one
158
int64_t Item_string::val_int()
163
char *end= (char*) str_value.ptr()+ str_value.length();
165
const CHARSET_INFO * const cs= str_value.charset();
167
tmp= (*(cs->cset->strtoll10))(cs, str_value.ptr(), &end, &err);
169
TODO: Give error if we wanted a signed integer and we got an unsigned
173
(end != org_end && !check_if_only_end_space(cs, end, org_end)))
175
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
176
ER_TRUNCATED_WRONG_VALUE,
177
ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
183
my_decimal *Item_string::val_decimal(my_decimal *decimal_value)
185
return val_decimal_from_string(decimal_value);
188
int Item_string::save_in_field(Field *field, bool)
191
result=val_str(&str_value);
192
return save_str_value_in_field(field, result);