22
22
#include <drizzled/item/basic_constant.h>
23
#include <drizzled/charset_info.h>
28
class Item_string :public Item_basic_constant
23
#include <drizzled/charset.h>
27
class Item_string : public Item_basic_constant
30
Item_string(str_ref str, const charset_info_st* cs, Derivation dv= DERIVATION_COERCIBLE)
32
assert(not (str.size() % cs->mbminlen));
33
str_value.set(str.data(), str.size(), cs);
34
collation.set(cs, dv);
36
We have to have a different max_length than 'length' here to
37
ensure that we get the right length if we do use the item
38
to create a new table. In this case max_length must be the maximum
39
number of chars for a string of this type because we in CreateField::
40
divide the max_length with mbmaxlen).
42
max_length= str_value.numchars() * cs->mbmaxlen;
43
set_name(str.data(), str.size(), cs);
44
decimals=NOT_FIXED_DEC;
45
// it is constant => can be used without fix_fields (and frequently used)
31
49
Item_string(const char *str,uint32_t length,
32
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
33
: m_cs_specified(false)
50
const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
35
str_value.set_or_copy_aligned(str, length, cs);
52
assert(not (length % cs->mbminlen));
53
str_value.set(str, length, cs);
36
54
collation.set(cs, dv);
38
56
We have to have a different max_length than 'length' here to
60
77
Item_string(const char *name_par, const char *str, uint32_t length,
61
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
62
: m_cs_specified(false)
78
const charset_info_st * const cs, Derivation dv= DERIVATION_COERCIBLE)
64
str_value.set_or_copy_aligned(str, length, cs);
80
assert(not (length % cs->mbminlen));
81
str_value.set(str, length, cs);
65
82
collation.set(cs, dv);
66
83
max_length= str_value.numchars()*cs->mbmaxlen;
67
84
set_name(name_par, 0, cs);
85
102
bool eq(const Item *item, bool binary_cmp) const;
86
103
Item *clone_item()
88
return new Item_string(name, str_value.ptr(),
89
str_value.length(), collation.collation);
105
return new Item_string(name, str_value.ptr(), str_value.length(), collation.collation);
91
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
92
inline void append(char *str, uint32_t length)
107
Item *safe_charset_converter(const charset_info_st * const tocs);
108
inline void append(str_ref v)
94
str_value.append(str, length);
95
111
max_length= str_value.numchars() * collation.collation->mbmaxlen;
97
113
virtual void print(String *str);
100
Return true if character-set-introducer was explicitly specified in the
101
original query for this item (text literal).
103
This operation is to be called from Item_string::print(). The idea is
104
that when a query is generated (re-constructed) from the Item-tree,
105
character-set-introducers should appear only for those literals, where
106
they were explicitly specified by the user. Otherwise, that may lead to
107
loss collation information (character set introducers implies default
108
collation for the literal).
110
Basically, that makes sense only for views and hopefully will be gone
111
one day when we start using original query as a view definition.
113
@return This operation returns the value of m_cs_specified attribute.
114
@retval true if character set introducer was explicitly specified in
116
@retval false otherwise.
118
inline bool is_cs_specified() const
120
return m_cs_specified;
124
Set the value of m_cs_specified attribute.
126
m_cs_specified attribute shows whether character-set-introducer was
127
explicitly specified in the original query for this text literal or
128
not. The attribute makes sense (is used) only for views.
130
This operation is to be called from the parser during parsing an input
133
inline void set_cs_specified(bool cs_specified)
135
m_cs_specified= cs_specified;
143
class Item_static_string_func :public Item_string
117
class Item_static_string_func : public Item_string
145
119
const char *func_name;
147
Item_static_string_func(const char *name_par, const char *str, uint32_t length,
148
const CHARSET_INFO * const cs,
149
Derivation dv= DERIVATION_COERCIBLE)
150
:Item_string(NULL, str, length, cs, dv), func_name(name_par)
121
Item_static_string_func(const char *name_par,
123
const charset_info_st* cs,
124
Derivation dv= DERIVATION_COERCIBLE) :
125
Item_string(NULL, str.data(), str.size(), cs, dv),
152
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
128
Item *safe_charset_converter(const charset_info_st*);
154
130
virtual inline void print(String *str)
156
str->append(func_name);
132
str->append(func_name, strlen(func_name));