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 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
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> |
2154.2.4
by Brian Aker
This fixes 716459 |
24 |
#include <drizzled/charset_info.h> |
642.1.62
by Lee
more header file cleanup |
25 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
26 |
namespace drizzled |
27 |
{
|
|
28 |
||
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
29 |
class Item_string :public Item_basic_constant |
30 |
{
|
|
31 |
public: |
|
32 |
Item_string(const char *str,uint32_t length, |
|
1022.1.3
by Brian Aker
Force UTF8 (remove the bits for looking for ascii). |
33 |
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE) |
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
34 |
: m_cs_specified(false) |
35 |
{
|
|
36 |
str_value.set_or_copy_aligned(str, length, cs); |
|
1022.1.3
by Brian Aker
Force UTF8 (remove the bits for looking for ascii). |
37 |
collation.set(cs, dv); |
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
38 |
/*
|
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
|
|
1052.2.3
by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards. |
42 |
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 |
43 |
divide the max_length with mbmaxlen).
|
44 |
*/
|
|
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)
|
|
49 |
fixed= 1; |
|
50 |
}
|
|
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) |
|
54 |
{
|
|
55 |
collation.set(cs, dv); |
|
56 |
max_length= 0; |
|
57 |
set_name(NULL, 0, cs); |
|
58 |
decimals= NOT_FIXED_DEC; |
|
59 |
fixed= 1; |
|
60 |
}
|
|
61 |
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). |
62 |
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE) |
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
63 |
: m_cs_specified(false) |
64 |
{
|
|
65 |
str_value.set_or_copy_aligned(str, length, cs); |
|
1022.1.3
by Brian Aker
Force UTF8 (remove the bits for looking for ascii). |
66 |
collation.set(cs, dv); |
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
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)
|
|
71 |
fixed= 1; |
|
72 |
}
|
|
73 |
enum Type type() const { return STRING_ITEM; } |
|
74 |
double val_real(); |
|
75 |
int64_t val_int(); |
|
76 |
String *val_str(String*) |
|
77 |
{
|
|
78 |
assert(fixed == 1); |
|
79 |
return (String*) &str_value; |
|
80 |
}
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
81 |
type::Decimal *val_decimal(type::Decimal *); |
642.1.6
by Lee
move functions from item.cc/item.h to item directory |
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; |
|
87 |
Item *clone_item() |
|
88 |
{
|
|
89 |
return new Item_string(name, str_value.ptr(), |
|
90 |
str_value.length(), collation.collation); |
|
91 |
}
|
|
92 |
Item *safe_charset_converter(const CHARSET_INFO * const tocs); |
|
93 |
inline void append(char *str, uint32_t length) |
|
94 |
{
|
|
95 |
str_value.append(str, length); |
|
96 |
max_length= str_value.numchars() * collation.collation->mbmaxlen; |
|
97 |
}
|
|
98 |
virtual void print(String *str, enum_query_type query_type); |
|
99 |
||
100 |
/**
|
|
101 |
Return true if character-set-introducer was explicitly specified in the
|
|
102 |
original query for this item (text literal).
|
|
103 |
||
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).
|
|
110 |
||
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.
|
|
113 |
||
114 |
@return This operation returns the value of m_cs_specified attribute.
|
|
115 |
@retval true if character set introducer was explicitly specified in
|
|
116 |
the original query.
|
|
117 |
@retval false otherwise.
|
|
118 |
*/
|
|
119 |
inline bool is_cs_specified() const |
|
120 |
{
|
|
121 |
return m_cs_specified; |
|
122 |
}
|
|
123 |
||
124 |
/**
|
|
125 |
Set the value of m_cs_specified attribute.
|
|
126 |
||
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.
|
|
130 |
||
131 |
This operation is to be called from the parser during parsing an input
|
|
132 |
query.
|
|
133 |
*/
|
|
134 |
inline void set_cs_specified(bool cs_specified) |
|
135 |
{
|
|
136 |
m_cs_specified= cs_specified; |
|
137 |
}
|
|
138 |
||
139 |
private: |
|
140 |
bool m_cs_specified; |
|
141 |
};
|
|
142 |
||
143 |
||
144 |
class Item_static_string_func :public Item_string |
|
145 |
{
|
|
146 |
const char *func_name; |
|
147 |
public: |
|
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) |
|
152 |
{}
|
|
153 |
Item *safe_charset_converter(const CHARSET_INFO * const tocs); |
|
154 |
||
155 |
virtual inline void print(String *str, enum_query_type) |
|
156 |
{
|
|
157 |
str->append(func_name); |
|
158 |
}
|
|
159 |
};
|
|
160 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
161 |
} /* namespace drizzled */ |
162 |
||
1122.2.10
by Monty Taylor
Fixed all of the include guards. |
163 |
#endif /* DRIZZLED_ITEM_STRING_H */ |