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, Inc.
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
#ifndef DRIZZLED_ITEM_STRING_H
21
#define DRIZZLED_ITEM_STRING_H
23
#include <drizzled/item/basic_constant.h>
24
#include <drizzled/charset_info.h>
29
class Item_string :public Item_basic_constant
32
Item_string(const char *str,uint32_t length,
33
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
34
: m_cs_specified(false)
36
str_value.set_or_copy_aligned(str, length, cs);
37
collation.set(cs, dv);
39
We have to have a different max_length than 'length' here to
40
ensure that we get the right length if we do use the item
41
to create a new table. In this case max_length must be the maximum
42
number of chars for a string of this type because we in CreateField::
43
divide the max_length with mbmaxlen).
45
max_length= str_value.numchars()*cs->mbmaxlen;
46
set_name(str, length, cs);
47
decimals=NOT_FIXED_DEC;
48
// it is constant => can be used without fix_fields (and frequently used)
51
/* Just create an item and do not fill string representation */
52
Item_string(const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
53
: m_cs_specified(false)
55
collation.set(cs, dv);
57
set_name(NULL, 0, cs);
58
decimals= NOT_FIXED_DEC;
61
Item_string(const char *name_par, const char *str, uint32_t length,
62
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
63
: m_cs_specified(false)
65
str_value.set_or_copy_aligned(str, length, cs);
66
collation.set(cs, dv);
67
max_length= str_value.numchars()*cs->mbmaxlen;
68
set_name(name_par, 0, cs);
69
decimals=NOT_FIXED_DEC;
70
// it is constant => can be used without fix_fields (and frequently used)
73
enum Type type() const { return STRING_ITEM; }
76
String *val_str(String*)
79
return (String*) &str_value;
81
type::Decimal *val_decimal(type::Decimal *);
82
int save_in_field(Field *field, bool no_conversions);
83
enum Item_result result_type () const { return STRING_RESULT; }
84
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
85
bool basic_const_item() const { return 1; }
86
bool eq(const Item *item, bool binary_cmp) const;
89
return new Item_string(name, str_value.ptr(),
90
str_value.length(), collation.collation);
92
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
93
inline void append(char *str, uint32_t length)
95
str_value.append(str, length);
96
max_length= str_value.numchars() * collation.collation->mbmaxlen;
98
virtual void print(String *str, enum_query_type query_type);
101
Return true if character-set-introducer was explicitly specified in the
102
original query for this item (text literal).
104
This operation is to be called from Item_string::print(). The idea is
105
that when a query is generated (re-constructed) from the Item-tree,
106
character-set-introducers should appear only for those literals, where
107
they were explicitly specified by the user. Otherwise, that may lead to
108
loss collation information (character set introducers implies default
109
collation for the literal).
111
Basically, that makes sense only for views and hopefully will be gone
112
one day when we start using original query as a view definition.
114
@return This operation returns the value of m_cs_specified attribute.
115
@retval true if character set introducer was explicitly specified in
117
@retval false otherwise.
119
inline bool is_cs_specified() const
121
return m_cs_specified;
125
Set the value of m_cs_specified attribute.
127
m_cs_specified attribute shows whether character-set-introducer was
128
explicitly specified in the original query for this text literal or
129
not. The attribute makes sense (is used) only for views.
131
This operation is to be called from the parser during parsing an input
134
inline void set_cs_specified(bool cs_specified)
136
m_cs_specified= cs_specified;
144
class Item_static_string_func :public Item_string
146
const char *func_name;
148
Item_static_string_func(const char *name_par, const char *str, uint32_t length,
149
const CHARSET_INFO * const cs,
150
Derivation dv= DERIVATION_COERCIBLE)
151
:Item_string(NULL, str, length, cs, dv), func_name(name_par)
153
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
155
virtual inline void print(String *str, enum_query_type)
157
str->append(func_name);
161
} /* namespace drizzled */
163
#endif /* DRIZZLED_ITEM_STRING_H */