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
#ifndef DRIZZLED_ITEM_ITEM_STRING_H
21
#define DRIZZLED_ITEM_ITEM_STRING_H
23
class Item_string :public Item_basic_constant
26
Item_string(const char *str,uint32_t length,
27
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
28
uint32_t repertoire= MY_REPERTOIRE_UNICODE30)
29
: m_cs_specified(false)
31
str_value.set_or_copy_aligned(str, length, cs);
32
collation.set(cs, dv, repertoire);
34
We have to have a different max_length than 'length' here to
35
ensure that we get the right length if we do use the item
36
to create a new table. In this case max_length must be the maximum
37
number of chars for a string of this type because we in Create_field::
38
divide the max_length with mbmaxlen).
40
max_length= str_value.numchars()*cs->mbmaxlen;
41
set_name(str, length, cs);
42
decimals=NOT_FIXED_DEC;
43
// it is constant => can be used without fix_fields (and frequently used)
46
/* Just create an item and do not fill string representation */
47
Item_string(const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
48
: m_cs_specified(false)
50
collation.set(cs, dv);
52
set_name(NULL, 0, cs);
53
decimals= NOT_FIXED_DEC;
56
Item_string(const char *name_par, const char *str, uint32_t length,
57
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
58
uint32_t repertoire= MY_REPERTOIRE_UNICODE30)
59
: m_cs_specified(false)
61
str_value.set_or_copy_aligned(str, length, cs);
62
collation.set(cs, dv, repertoire);
63
max_length= str_value.numchars()*cs->mbmaxlen;
64
set_name(name_par, 0, cs);
65
decimals=NOT_FIXED_DEC;
66
// it is constant => can be used without fix_fields (and frequently used)
69
void set_repertoire_from_value()
71
collation.repertoire= my_string_repertoire(str_value.charset(),
75
enum Type type() const { return STRING_ITEM; }
78
String *val_str(String*)
81
return (String*) &str_value;
83
my_decimal *val_decimal(my_decimal *);
84
int save_in_field(Field *field, bool no_conversions);
85
enum Item_result result_type () const { return STRING_RESULT; }
86
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
87
bool basic_const_item() const { return 1; }
88
bool eq(const Item *item, bool binary_cmp) const;
91
return new Item_string(name, str_value.ptr(),
92
str_value.length(), collation.collation);
94
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
95
inline void append(char *str, uint32_t length)
97
str_value.append(str, length);
98
max_length= str_value.numchars() * collation.collation->mbmaxlen;
100
virtual void print(String *str, enum_query_type query_type);
103
Return true if character-set-introducer was explicitly specified in the
104
original query for this item (text literal).
106
This operation is to be called from Item_string::print(). The idea is
107
that when a query is generated (re-constructed) from the Item-tree,
108
character-set-introducers should appear only for those literals, where
109
they were explicitly specified by the user. Otherwise, that may lead to
110
loss collation information (character set introducers implies default
111
collation for the literal).
113
Basically, that makes sense only for views and hopefully will be gone
114
one day when we start using original query as a view definition.
116
@return This operation returns the value of m_cs_specified attribute.
117
@retval true if character set introducer was explicitly specified in
119
@retval false otherwise.
121
inline bool is_cs_specified() const
123
return m_cs_specified;
127
Set the value of m_cs_specified attribute.
129
m_cs_specified attribute shows whether character-set-introducer was
130
explicitly specified in the original query for this text literal or
131
not. The attribute makes sense (is used) only for views.
133
This operation is to be called from the parser during parsing an input
136
inline void set_cs_specified(bool cs_specified)
138
m_cs_specified= cs_specified;
140
bool check_vcol_func_processor(unsigned char *)
148
class Item_static_string_func :public Item_string
150
const char *func_name;
152
Item_static_string_func(const char *name_par, const char *str, uint32_t length,
153
const CHARSET_INFO * const cs,
154
Derivation dv= DERIVATION_COERCIBLE)
155
:Item_string(NULL, str, length, cs, dv), func_name(name_par)
157
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
159
virtual inline void print(String *str, enum_query_type)
161
str->append(func_name);
163
bool check_vcol_func_processor(unsigned char *)
167
#endif /* DRIZZLED_ITEM_ITEM_STRING_H */