642.1.6
by Lee
move functions from item.cc/item.h to item directory |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
5 |
*
|
|
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.
|
|
9 |
*
|
|
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.
|
|
14 |
*
|
|
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
|
|
18 |
*/
|
|
19 |
||
1122.2.10
by Monty Taylor
Fixed all of the include guards. |
20 |
#ifndef DRIZZLED_ITEM_STRING_H
|
21 |
#define DRIZZLED_ITEM_STRING_H
|
|
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
22 |
|
642.1.62
by Lee
more header file cleanup |
23 |
#include <drizzled/item/basic_constant.h> |
24 |
||
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
25 |
class Item_string :public Item_basic_constant |
26 |
{
|
|
27 |
public: |
|
28 |
Item_string(const char *str,uint32_t length, |
|
1022.1.3
by Brian Aker
Force UTF8 (remove the bits for looking for ascii). |
29 |
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE) |
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
30 |
: m_cs_specified(false) |
31 |
{
|
|
32 |
str_value.set_or_copy_aligned(str, length, cs); |
|
1022.1.3
by Brian Aker
Force UTF8 (remove the bits for looking for ascii). |
33 |
collation.set(cs, dv); |
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
34 |
/*
|
35 |
We have to have a different max_length than 'length' here to
|
|
36 |
ensure that we get the right length if we do use the item
|
|
37 |
to create a new table. In this case max_length must be the maximum
|
|
1052.2.3
by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards. |
38 |
number of chars for a string of this type because we in CreateField::
|
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
39 |
divide the max_length with mbmaxlen).
|
40 |
*/
|
|
41 |
max_length= str_value.numchars()*cs->mbmaxlen; |
|
42 |
set_name(str, length, cs); |
|
43 |
decimals=NOT_FIXED_DEC; |
|
44 |
// it is constant => can be used without fix_fields (and frequently used)
|
|
45 |
fixed= 1; |
|
46 |
}
|
|
47 |
/* Just create an item and do not fill string representation */
|
|
48 |
Item_string(const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE) |
|
49 |
: m_cs_specified(false) |
|
50 |
{
|
|
51 |
collation.set(cs, dv); |
|
52 |
max_length= 0; |
|
53 |
set_name(NULL, 0, cs); |
|
54 |
decimals= NOT_FIXED_DEC; |
|
55 |
fixed= 1; |
|
56 |
}
|
|
57 |
Item_string(const char *name_par, const char *str, uint32_t length, |
|
1022.1.3
by Brian Aker
Force UTF8 (remove the bits for looking for ascii). |
58 |
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE) |
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
59 |
: m_cs_specified(false) |
60 |
{
|
|
61 |
str_value.set_or_copy_aligned(str, length, cs); |
|
1022.1.3
by Brian Aker
Force UTF8 (remove the bits for looking for ascii). |
62 |
collation.set(cs, dv); |
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
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)
|
|
67 |
fixed= 1; |
|
68 |
}
|
|
69 |
enum Type type() const { return STRING_ITEM; } |
|
70 |
double val_real(); |
|
71 |
int64_t val_int(); |
|
72 |
String *val_str(String*) |
|
73 |
{
|
|
74 |
assert(fixed == 1); |
|
75 |
return (String*) &str_value; |
|
76 |
}
|
|
77 |
my_decimal *val_decimal(my_decimal *); |
|
78 |
int save_in_field(Field *field, bool no_conversions); |
|
79 |
enum Item_result result_type () const { return STRING_RESULT; } |
|
80 |
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; } |
|
81 |
bool basic_const_item() const { return 1; } |
|
82 |
bool eq(const Item *item, bool binary_cmp) const; |
|
83 |
Item *clone_item() |
|
84 |
{
|
|
85 |
return new Item_string(name, str_value.ptr(), |
|
86 |
str_value.length(), collation.collation); |
|
87 |
}
|
|
88 |
Item *safe_charset_converter(const CHARSET_INFO * const tocs); |
|
89 |
inline void append(char *str, uint32_t length) |
|
90 |
{
|
|
91 |
str_value.append(str, length); |
|
92 |
max_length= str_value.numchars() * collation.collation->mbmaxlen; |
|
93 |
}
|
|
94 |
virtual void print(String *str, enum_query_type query_type); |
|
95 |
||
96 |
/**
|
|
97 |
Return true if character-set-introducer was explicitly specified in the
|
|
98 |
original query for this item (text literal).
|
|
99 |
||
100 |
This operation is to be called from Item_string::print(). The idea is
|
|
101 |
that when a query is generated (re-constructed) from the Item-tree,
|
|
102 |
character-set-introducers should appear only for those literals, where
|
|
103 |
they were explicitly specified by the user. Otherwise, that may lead to
|
|
104 |
loss collation information (character set introducers implies default
|
|
105 |
collation for the literal).
|
|
106 |
||
107 |
Basically, that makes sense only for views and hopefully will be gone
|
|
108 |
one day when we start using original query as a view definition.
|
|
109 |
||
110 |
@return This operation returns the value of m_cs_specified attribute.
|
|
111 |
@retval true if character set introducer was explicitly specified in
|
|
112 |
the original query.
|
|
113 |
@retval false otherwise.
|
|
114 |
*/
|
|
115 |
inline bool is_cs_specified() const |
|
116 |
{
|
|
117 |
return m_cs_specified; |
|
118 |
}
|
|
119 |
||
120 |
/**
|
|
121 |
Set the value of m_cs_specified attribute.
|
|
122 |
||
123 |
m_cs_specified attribute shows whether character-set-introducer was
|
|
124 |
explicitly specified in the original query for this text literal or
|
|
125 |
not. The attribute makes sense (is used) only for views.
|
|
126 |
||
127 |
This operation is to be called from the parser during parsing an input
|
|
128 |
query.
|
|
129 |
*/
|
|
130 |
inline void set_cs_specified(bool cs_specified) |
|
131 |
{
|
|
132 |
m_cs_specified= cs_specified; |
|
133 |
}
|
|
134 |
||
135 |
private: |
|
136 |
bool m_cs_specified; |
|
137 |
};
|
|
138 |
||
139 |
||
140 |
class Item_static_string_func :public Item_string |
|
141 |
{
|
|
142 |
const char *func_name; |
|
143 |
public: |
|
144 |
Item_static_string_func(const char *name_par, const char *str, uint32_t length, |
|
145 |
const CHARSET_INFO * const cs, |
|
146 |
Derivation dv= DERIVATION_COERCIBLE) |
|
147 |
:Item_string(NULL, str, length, cs, dv), func_name(name_par) |
|
148 |
{}
|
|
149 |
Item *safe_charset_converter(const CHARSET_INFO * const tocs); |
|
150 |
||
151 |
virtual inline void print(String *str, enum_query_type) |
|
152 |
{
|
|
153 |
str->append(func_name); |
|
154 |
}
|
|
155 |
};
|
|
156 |
||
1122.2.10
by Monty Taylor
Fixed all of the include guards. |
157 |
#endif /* DRIZZLED_ITEM_STRING_H */ |