390.1.2
by Monty Taylor
Fixed copyright headers in drizzled/ |
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 |
*/
|
|
1
by brian
clean slate |
19 |
|
20 |
||
21 |
/* This file defines all string functions */
|
|
22 |
||
23 |
||
24 |
class Item_str_func :public Item_func |
|
25 |
{
|
|
26 |
public: |
|
27 |
Item_str_func() :Item_func() { decimals=NOT_FIXED_DEC; } |
|
28 |
Item_str_func(Item *a) :Item_func(a) {decimals=NOT_FIXED_DEC; } |
|
29 |
Item_str_func(Item *a,Item *b) :Item_func(a,b) { decimals=NOT_FIXED_DEC; } |
|
30 |
Item_str_func(Item *a,Item *b,Item *c) :Item_func(a,b,c) { decimals=NOT_FIXED_DEC; } |
|
31 |
Item_str_func(Item *a,Item *b,Item *c,Item *d) :Item_func(a,b,c,d) {decimals=NOT_FIXED_DEC; } |
|
32 |
Item_str_func(Item *a,Item *b,Item *c,Item *d, Item* e) :Item_func(a,b,c,d,e) {decimals=NOT_FIXED_DEC; } |
|
33 |
Item_str_func(List<Item> &list) :Item_func(list) {decimals=NOT_FIXED_DEC; } |
|
152
by Brian Aker
longlong replacement |
34 |
int64_t val_int(); |
1
by brian
clean slate |
35 |
double val_real(); |
36 |
my_decimal *val_decimal(my_decimal *); |
|
37 |
enum Item_result result_type () const { return STRING_RESULT; } |
|
38 |
void left_right_max_length(); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
39 |
bool fix_fields(Session *session, Item **ref); |
1
by brian
clean slate |
40 |
};
|
41 |
||
42 |
||
43 |
class Item_func_concat :public Item_str_func |
|
44 |
{
|
|
45 |
String tmp_value; |
|
46 |
public: |
|
47 |
Item_func_concat(List<Item> &list) :Item_str_func(list) {} |
|
48 |
Item_func_concat(Item *a,Item *b) :Item_str_func(a,b) {} |
|
49 |
String *val_str(String *); |
|
50 |
void fix_length_and_dec(); |
|
51 |
const char *func_name() const { return "concat"; } |
|
52 |
};
|
|
53 |
||
54 |
class Item_func_concat_ws :public Item_str_func |
|
55 |
{
|
|
56 |
String tmp_value; |
|
57 |
public: |
|
58 |
Item_func_concat_ws(List<Item> &list) :Item_str_func(list) {} |
|
59 |
String *val_str(String *); |
|
60 |
void fix_length_and_dec(); |
|
61 |
const char *func_name() const { return "concat_ws"; } |
|
62 |
table_map not_null_tables() const { return 0; } |
|
63 |
};
|
|
64 |
||
65 |
class Item_func_reverse :public Item_str_func |
|
66 |
{
|
|
67 |
String tmp_value; |
|
68 |
public: |
|
69 |
Item_func_reverse(Item *a) :Item_str_func(a) {} |
|
70 |
String *val_str(String *); |
|
71 |
void fix_length_and_dec(); |
|
72 |
const char *func_name() const { return "reverse"; } |
|
73 |
};
|
|
74 |
||
75 |
||
76 |
class Item_func_replace :public Item_str_func |
|
77 |
{
|
|
78 |
String tmp_value,tmp_value2; |
|
79 |
public: |
|
80 |
Item_func_replace(Item *org,Item *find,Item *replace) |
|
81 |
:Item_str_func(org,find,replace) {} |
|
82 |
String *val_str(String *); |
|
83 |
void fix_length_and_dec(); |
|
84 |
const char *func_name() const { return "replace"; } |
|
85 |
};
|
|
86 |
||
87 |
||
88 |
class Item_func_insert :public Item_str_func |
|
89 |
{
|
|
90 |
String tmp_value; |
|
91 |
public: |
|
92 |
Item_func_insert(Item *org,Item *start,Item *length,Item *new_str) |
|
93 |
:Item_str_func(org,start,length,new_str) {} |
|
94 |
String *val_str(String *); |
|
95 |
void fix_length_and_dec(); |
|
96 |
const char *func_name() const { return "insert"; } |
|
97 |
};
|
|
98 |
||
99 |
||
100 |
class Item_str_conv :public Item_str_func |
|
101 |
{
|
|
102 |
protected: |
|
482
by Brian Aker
Remove uint. |
103 |
uint32_t multiply; |
1
by brian
clean slate |
104 |
my_charset_conv_case converter; |
105 |
String tmp_value; |
|
106 |
public: |
|
107 |
Item_str_conv(Item *item) :Item_str_func(item) {} |
|
108 |
String *val_str(String *); |
|
109 |
};
|
|
110 |
||
111 |
||
112 |
class Item_func_lcase :public Item_str_conv |
|
113 |
{
|
|
114 |
public: |
|
115 |
Item_func_lcase(Item *item) :Item_str_conv(item) {} |
|
116 |
const char *func_name() const { return "lcase"; } |
|
117 |
void fix_length_and_dec(); |
|
118 |
};
|
|
119 |
||
120 |
class Item_func_ucase :public Item_str_conv |
|
121 |
{
|
|
122 |
public: |
|
123 |
Item_func_ucase(Item *item) :Item_str_conv(item) {} |
|
124 |
const char *func_name() const { return "ucase"; } |
|
125 |
void fix_length_and_dec(); |
|
126 |
};
|
|
127 |
||
128 |
||
129 |
class Item_func_left :public Item_str_func |
|
130 |
{
|
|
131 |
String tmp_value; |
|
132 |
public: |
|
133 |
Item_func_left(Item *a,Item *b) :Item_str_func(a,b) {} |
|
134 |
String *val_str(String *); |
|
135 |
void fix_length_and_dec(); |
|
136 |
const char *func_name() const { return "left"; } |
|
137 |
};
|
|
138 |
||
139 |
||
140 |
class Item_func_right :public Item_str_func |
|
141 |
{
|
|
142 |
String tmp_value; |
|
143 |
public: |
|
144 |
Item_func_right(Item *a,Item *b) :Item_str_func(a,b) {} |
|
145 |
String *val_str(String *); |
|
146 |
void fix_length_and_dec(); |
|
147 |
const char *func_name() const { return "right"; } |
|
148 |
};
|
|
149 |
||
150 |
||
151 |
class Item_func_substr :public Item_str_func |
|
152 |
{
|
|
153 |
String tmp_value; |
|
154 |
public: |
|
155 |
Item_func_substr(Item *a,Item *b) :Item_str_func(a,b) {} |
|
156 |
Item_func_substr(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} |
|
157 |
String *val_str(String *); |
|
158 |
void fix_length_and_dec(); |
|
159 |
const char *func_name() const { return "substr"; } |
|
160 |
};
|
|
161 |
||
162 |
||
163 |
class Item_func_substr_index :public Item_str_func |
|
164 |
{
|
|
165 |
String tmp_value; |
|
166 |
public: |
|
167 |
Item_func_substr_index(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} |
|
168 |
String *val_str(String *); |
|
169 |
void fix_length_and_dec(); |
|
170 |
const char *func_name() const { return "substring_index"; } |
|
171 |
};
|
|
172 |
||
173 |
||
174 |
class Item_func_trim :public Item_str_func |
|
175 |
{
|
|
176 |
protected: |
|
177 |
String tmp_value; |
|
178 |
String remove; |
|
179 |
public: |
|
180 |
Item_func_trim(Item *a,Item *b) :Item_str_func(a,b) {} |
|
181 |
Item_func_trim(Item *a) :Item_str_func(a) {} |
|
182 |
String *val_str(String *); |
|
183 |
void fix_length_and_dec(); |
|
184 |
const char *func_name() const { return "trim"; } |
|
185 |
virtual void print(String *str, enum_query_type query_type); |
|
186 |
virtual const char *mode_name() const { return "both"; } |
|
187 |
};
|
|
188 |
||
189 |
||
190 |
class Item_func_ltrim :public Item_func_trim |
|
191 |
{
|
|
192 |
public: |
|
193 |
Item_func_ltrim(Item *a,Item *b) :Item_func_trim(a,b) {} |
|
194 |
Item_func_ltrim(Item *a) :Item_func_trim(a) {} |
|
195 |
String *val_str(String *); |
|
196 |
const char *func_name() const { return "ltrim"; } |
|
197 |
const char *mode_name() const { return "leading"; } |
|
198 |
};
|
|
199 |
||
200 |
||
201 |
class Item_func_rtrim :public Item_func_trim |
|
202 |
{
|
|
203 |
public: |
|
204 |
Item_func_rtrim(Item *a,Item *b) :Item_func_trim(a,b) {} |
|
205 |
Item_func_rtrim(Item *a) :Item_func_trim(a) {} |
|
206 |
String *val_str(String *); |
|
207 |
const char *func_name() const { return "rtrim"; } |
|
208 |
const char *mode_name() const { return "trailing"; } |
|
209 |
};
|
|
210 |
||
211 |
||
212 |
class Item_func_sysconst :public Item_str_func |
|
213 |
{
|
|
214 |
public: |
|
215 |
Item_func_sysconst() |
|
216 |
{ collation.set(system_charset_info,DERIVATION_SYSCONST); } |
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
217 |
Item *safe_charset_converter(const CHARSET_INFO * const tocs); |
1
by brian
clean slate |
218 |
/*
|
219 |
Used to create correct Item name in new converted item in
|
|
220 |
safe_charset_converter, return string representation of this function
|
|
221 |
call
|
|
222 |
*/
|
|
223 |
virtual const char *fully_qualified_func_name() const = 0; |
|
481.3.1
by Monty Taylor
Merged vcol stuff. |
224 |
bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused))) |
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
225 |
{ return true; } |
1
by brian
clean slate |
226 |
};
|
227 |
||
228 |
||
229 |
class Item_func_database :public Item_func_sysconst |
|
230 |
{
|
|
231 |
public: |
|
232 |
Item_func_database() :Item_func_sysconst() {} |
|
233 |
String *val_str(String *); |
|
234 |
void fix_length_and_dec() |
|
235 |
{
|
|
236 |
max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen; |
|
237 |
maybe_null=1; |
|
238 |
}
|
|
239 |
const char *func_name() const { return "database"; } |
|
240 |
const char *fully_qualified_func_name() const { return "database()"; } |
|
241 |
};
|
|
242 |
||
243 |
||
244 |
class Item_func_user :public Item_func_sysconst |
|
245 |
{
|
|
246 |
protected: |
|
247 |
bool init (const char *user, const char *host); |
|
248 |
||
249 |
public: |
|
250 |
Item_func_user() |
|
251 |
{
|
|
252 |
str_value.set("", 0, system_charset_info); |
|
253 |
}
|
|
254 |
String *val_str(String *) |
|
255 |
{
|
|
51.1.23
by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE |
256 |
assert(fixed == 1); |
1
by brian
clean slate |
257 |
return (null_value ? 0 : &str_value); |
258 |
}
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
259 |
bool fix_fields(Session *session, Item **ref); |
1
by brian
clean slate |
260 |
void fix_length_and_dec() |
261 |
{
|
|
262 |
max_length= (USERNAME_CHAR_LENGTH + HOSTNAME_LENGTH + 1) * |
|
263 |
system_charset_info->mbmaxlen; |
|
264 |
}
|
|
265 |
const char *func_name() const { return "user"; } |
|
266 |
const char *fully_qualified_func_name() const { return "user()"; } |
|
77.1.7
by Monty Taylor
Heap builds clean. |
267 |
int save_in_field(Field *field, |
212.1.3
by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)). |
268 |
bool no_conversions __attribute__((unused))) |
1
by brian
clean slate |
269 |
{
|
270 |
return save_str_value_in_field(field, &str_value); |
|
271 |
}
|
|
272 |
};
|
|
273 |
||
274 |
||
275 |
class Item_func_current_user :public Item_func_user |
|
276 |
{
|
|
277 |
Name_resolution_context *context; |
|
278 |
||
279 |
public: |
|
280 |
Item_func_current_user(Name_resolution_context *context_arg) |
|
281 |
: context(context_arg) {} |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
282 |
bool fix_fields(Session *session, Item **ref); |
1
by brian
clean slate |
283 |
const char *func_name() const { return "current_user"; } |
284 |
const char *fully_qualified_func_name() const { return "current_user()"; } |
|
285 |
};
|
|
286 |
||
287 |
||
288 |
class Item_func_soundex :public Item_str_func |
|
289 |
{
|
|
290 |
String tmp_value; |
|
291 |
public: |
|
292 |
Item_func_soundex(Item *a) :Item_str_func(a) {} |
|
293 |
String *val_str(String *); |
|
294 |
void fix_length_and_dec(); |
|
295 |
const char *func_name() const { return "soundex"; } |
|
296 |
};
|
|
297 |
||
298 |
||
299 |
class Item_func_elt :public Item_str_func |
|
300 |
{
|
|
301 |
public: |
|
302 |
Item_func_elt(List<Item> &list) :Item_str_func(list) {} |
|
303 |
double val_real(); |
|
152
by Brian Aker
longlong replacement |
304 |
int64_t val_int(); |
1
by brian
clean slate |
305 |
String *val_str(String *str); |
306 |
void fix_length_and_dec(); |
|
307 |
const char *func_name() const { return "elt"; } |
|
308 |
};
|
|
309 |
||
310 |
||
311 |
class Item_func_make_set :public Item_str_func |
|
312 |
{
|
|
313 |
Item *item; |
|
314 |
String tmp_str; |
|
315 |
||
316 |
public: |
|
317 |
Item_func_make_set(Item *a,List<Item> &list) :Item_str_func(list),item(a) {} |
|
318 |
String *val_str(String *str); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
319 |
bool fix_fields(Session *session, Item **ref) |
1
by brian
clean slate |
320 |
{
|
51.1.23
by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE |
321 |
assert(fixed == 0); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
322 |
return ((!item->fixed && item->fix_fields(session, &item)) || |
1
by brian
clean slate |
323 |
item->check_cols(1) || |
520.1.22
by Brian Aker
Second pass of thd cleanup |
324 |
Item_func::fix_fields(session, ref)); |
1
by brian
clean slate |
325 |
}
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
326 |
void split_sum_func(Session *session, Item **ref_pointer_array, List<Item> &fields); |
1
by brian
clean slate |
327 |
void fix_length_and_dec(); |
328 |
void update_used_tables(); |
|
329 |
const char *func_name() const { return "make_set"; } |
|
330 |
||
481
by Brian Aker
Remove all of uchar. |
331 |
bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg) |
1
by brian
clean slate |
332 |
{
|
333 |
return item->walk(processor, walk_subquery, arg) || |
|
334 |
Item_str_func::walk(processor, walk_subquery, arg); |
|
335 |
}
|
|
481
by Brian Aker
Remove all of uchar. |
336 |
Item *transform(Item_transformer transformer, unsigned char *arg); |
1
by brian
clean slate |
337 |
virtual void print(String *str, enum_query_type query_type); |
338 |
};
|
|
339 |
||
340 |
||
341 |
class Item_func_format :public Item_str_func |
|
342 |
{
|
|
343 |
String tmp_str; |
|
344 |
public: |
|
345 |
Item_func_format(Item *org, Item *dec); |
|
346 |
String *val_str(String *); |
|
347 |
void fix_length_and_dec(); |
|
348 |
const char *func_name() const { return "format"; } |
|
349 |
virtual void print(String *str, enum_query_type query_type); |
|
350 |
};
|
|
351 |
||
352 |
||
353 |
class Item_func_char :public Item_str_func |
|
354 |
{
|
|
355 |
public: |
|
356 |
Item_func_char(List<Item> &list) :Item_str_func(list) |
|
357 |
{ collation.set(&my_charset_bin); } |
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
358 |
Item_func_char(List<Item> &list, const CHARSET_INFO * const cs) :Item_str_func(list) |
1
by brian
clean slate |
359 |
{ collation.set(cs); } |
360 |
String *val_str(String *); |
|
361 |
void fix_length_and_dec() |
|
362 |
{
|
|
363 |
max_length= arg_count * 4; |
|
364 |
}
|
|
365 |
const char *func_name() const { return "char"; } |
|
366 |
};
|
|
367 |
||
368 |
||
369 |
class Item_func_repeat :public Item_str_func |
|
370 |
{
|
|
371 |
String tmp_value; |
|
372 |
public: |
|
373 |
Item_func_repeat(Item *arg1,Item *arg2) :Item_str_func(arg1,arg2) {} |
|
374 |
String *val_str(String *); |
|
375 |
void fix_length_and_dec(); |
|
376 |
const char *func_name() const { return "repeat"; } |
|
377 |
};
|
|
378 |
||
379 |
||
380 |
class Item_func_rpad :public Item_str_func |
|
381 |
{
|
|
382 |
String tmp_value, rpad_str; |
|
383 |
public: |
|
384 |
Item_func_rpad(Item *arg1,Item *arg2,Item *arg3) |
|
385 |
:Item_str_func(arg1,arg2,arg3) {} |
|
386 |
String *val_str(String *); |
|
387 |
void fix_length_and_dec(); |
|
388 |
const char *func_name() const { return "rpad"; } |
|
389 |
};
|
|
390 |
||
391 |
||
392 |
class Item_func_lpad :public Item_str_func |
|
393 |
{
|
|
394 |
String tmp_value, lpad_str; |
|
395 |
public: |
|
396 |
Item_func_lpad(Item *arg1,Item *arg2,Item *arg3) |
|
397 |
:Item_str_func(arg1,arg2,arg3) {} |
|
398 |
String *val_str(String *); |
|
399 |
void fix_length_and_dec(); |
|
400 |
const char *func_name() const { return "lpad"; } |
|
401 |
};
|
|
402 |
||
403 |
||
404 |
class Item_func_conv :public Item_str_func |
|
405 |
{
|
|
406 |
public: |
|
407 |
Item_func_conv(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} |
|
408 |
const char *func_name() const { return "conv"; } |
|
409 |
String *val_str(String *); |
|
410 |
void fix_length_and_dec() |
|
411 |
{
|
|
412 |
collation.set(default_charset()); |
|
413 |
max_length=64; |
|
414 |
maybe_null= 1; |
|
415 |
}
|
|
416 |
};
|
|
417 |
||
418 |
||
419 |
class Item_func_hex :public Item_str_func |
|
420 |
{
|
|
421 |
String tmp_value; |
|
422 |
public: |
|
423 |
Item_func_hex(Item *a) :Item_str_func(a) {} |
|
424 |
const char *func_name() const { return "hex"; } |
|
425 |
String *val_str(String *); |
|
426 |
void fix_length_and_dec() |
|
427 |
{
|
|
428 |
collation.set(default_charset()); |
|
429 |
decimals=0; |
|
430 |
max_length=args[0]->max_length*2*collation.collation->mbmaxlen; |
|
431 |
}
|
|
432 |
};
|
|
433 |
||
434 |
class Item_func_unhex :public Item_str_func |
|
435 |
{
|
|
436 |
String tmp_value; |
|
437 |
public: |
|
438 |
Item_func_unhex(Item *a) :Item_str_func(a) |
|
439 |
{
|
|
440 |
/* there can be bad hex strings */
|
|
441 |
maybe_null= 1; |
|
442 |
}
|
|
443 |
const char *func_name() const { return "unhex"; } |
|
444 |
String *val_str(String *); |
|
445 |
void fix_length_and_dec() |
|
446 |
{
|
|
447 |
collation.set(&my_charset_bin); |
|
448 |
decimals=0; |
|
449 |
max_length=(1+args[0]->max_length)/2; |
|
450 |
}
|
|
451 |
};
|
|
452 |
||
453 |
||
454 |
class Item_func_binary :public Item_str_func |
|
455 |
{
|
|
456 |
public: |
|
457 |
Item_func_binary(Item *a) :Item_str_func(a) {} |
|
458 |
String *val_str(String *a) |
|
459 |
{
|
|
51.1.23
by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE |
460 |
assert(fixed == 1); |
1
by brian
clean slate |
461 |
String *tmp=args[0]->val_str(a); |
462 |
null_value=args[0]->null_value; |
|
463 |
if (tmp) |
|
464 |
tmp->set_charset(&my_charset_bin); |
|
465 |
return tmp; |
|
466 |
}
|
|
467 |
void fix_length_and_dec() |
|
468 |
{
|
|
469 |
collation.set(&my_charset_bin); |
|
470 |
max_length=args[0]->max_length; |
|
471 |
}
|
|
472 |
virtual void print(String *str, enum_query_type query_type); |
|
473 |
const char *func_name() const { return "cast_as_binary"; } |
|
474 |
};
|
|
475 |
||
476 |
||
477 |
class Item_load_file :public Item_str_func |
|
478 |
{
|
|
479 |
String tmp_value; |
|
480 |
public: |
|
481 |
Item_load_file(Item *a) :Item_str_func(a) {} |
|
482 |
String *val_str(String *); |
|
483 |
const char *func_name() const { return "load_file"; } |
|
484 |
void fix_length_and_dec() |
|
485 |
{
|
|
486 |
collation.set(&my_charset_bin, DERIVATION_COERCIBLE); |
|
487 |
maybe_null=1; |
|
488 |
max_length=MAX_BLOB_WIDTH; |
|
489 |
}
|
|
481.3.1
by Monty Taylor
Merged vcol stuff. |
490 |
bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused))) |
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
491 |
{ return true; } |
1
by brian
clean slate |
492 |
};
|
493 |
||
494 |
||
495 |
class Item_func_export_set: public Item_str_func |
|
496 |
{
|
|
497 |
public: |
|
498 |
Item_func_export_set(Item *a,Item *b,Item* c) :Item_str_func(a,b,c) {} |
|
499 |
Item_func_export_set(Item *a,Item *b,Item* c,Item* d) :Item_str_func(a,b,c,d) {} |
|
500 |
Item_func_export_set(Item *a,Item *b,Item* c,Item* d,Item* e) :Item_str_func(a,b,c,d,e) {} |
|
501 |
String *val_str(String *str); |
|
502 |
void fix_length_and_dec(); |
|
503 |
const char *func_name() const { return "export_set"; } |
|
504 |
};
|
|
505 |
||
506 |
class Item_func_quote :public Item_str_func |
|
507 |
{
|
|
508 |
String tmp_value; |
|
509 |
public: |
|
510 |
Item_func_quote(Item *a) :Item_str_func(a) {} |
|
511 |
const char *func_name() const { return "quote"; } |
|
512 |
String *val_str(String *); |
|
513 |
void fix_length_and_dec() |
|
514 |
{
|
|
515 |
collation.set(args[0]->collation); |
|
516 |
max_length= args[0]->max_length * 2 + 2; |
|
517 |
}
|
|
518 |
};
|
|
519 |
||
520 |
class Item_func_conv_charset :public Item_str_func |
|
521 |
{
|
|
522 |
bool use_cached_value; |
|
523 |
public: |
|
524 |
bool safe; |
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
525 |
const CHARSET_INFO *conv_charset; // keep it public |
526 |
Item_func_conv_charset(Item *a, const CHARSET_INFO * const cs) :Item_str_func(a) |
|
1
by brian
clean slate |
527 |
{ conv_charset= cs; use_cached_value= 0; safe= 0; } |
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
528 |
Item_func_conv_charset(Item *a, const CHARSET_INFO * const cs, bool cache_if_const) |
1
by brian
clean slate |
529 |
:Item_str_func(a) |
530 |
{
|
|
51.1.23
by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE |
531 |
assert(args[0]->fixed); |
1
by brian
clean slate |
532 |
conv_charset= cs; |
533 |
if (cache_if_const && args[0]->const_item()) |
|
534 |
{
|
|
482
by Brian Aker
Remove uint. |
535 |
uint32_t errors= 0; |
1
by brian
clean slate |
536 |
String tmp, *str= args[0]->val_str(&tmp); |
537 |
if (!str || str_value.copy(str->ptr(), str->length(), |
|
538 |
str->charset(), conv_charset, &errors)) |
|
539 |
null_value= 1; |
|
540 |
use_cached_value= 1; |
|
541 |
str_value.mark_as_const(); |
|
542 |
safe= (errors == 0); |
|
543 |
}
|
|
544 |
else
|
|
545 |
{
|
|
546 |
use_cached_value= 0; |
|
547 |
/*
|
|
548 |
Conversion from and to "binary" is safe.
|
|
549 |
Conversion to Unicode is safe.
|
|
550 |
Other kind of conversions are potentially lossy.
|
|
551 |
*/
|
|
552 |
safe= (args[0]->collation.collation == &my_charset_bin || |
|
553 |
cs == &my_charset_bin || |
|
554 |
(cs->state & MY_CS_UNICODE)); |
|
555 |
}
|
|
556 |
}
|
|
557 |
String *val_str(String *); |
|
558 |
void fix_length_and_dec(); |
|
559 |
const char *func_name() const { return "convert"; } |
|
560 |
virtual void print(String *str, enum_query_type query_type); |
|
561 |
};
|
|
562 |
||
563 |
class Item_func_set_collation :public Item_str_func |
|
564 |
{
|
|
565 |
public: |
|
566 |
Item_func_set_collation(Item *a, Item *b) :Item_str_func(a,b) {}; |
|
567 |
String *val_str(String *); |
|
568 |
void fix_length_and_dec(); |
|
569 |
bool eq(const Item *item, bool binary_cmp) const; |
|
570 |
const char *func_name() const { return "collate"; } |
|
571 |
enum Functype functype() const { return COLLATE_FUNC; } |
|
572 |
virtual void print(String *str, enum_query_type query_type); |
|
573 |
Item_field *filed_for_view_update() |
|
574 |
{
|
|
575 |
/* this function is transparent for view updating */
|
|
576 |
return args[0]->filed_for_view_update(); |
|
577 |
}
|
|
578 |
};
|
|
579 |
||
580 |
class Item_func_charset :public Item_str_func |
|
581 |
{
|
|
582 |
public: |
|
583 |
Item_func_charset(Item *a) :Item_str_func(a) {} |
|
584 |
String *val_str(String *); |
|
585 |
const char *func_name() const { return "charset"; } |
|
586 |
void fix_length_and_dec() |
|
587 |
{
|
|
588 |
collation.set(system_charset_info); |
|
589 |
max_length= 64 * collation.collation->mbmaxlen; // should be enough |
|
590 |
maybe_null= 0; |
|
591 |
};
|
|
592 |
table_map not_null_tables() const { return 0; } |
|
593 |
};
|
|
594 |
||
595 |
class Item_func_collation :public Item_str_func |
|
596 |
{
|
|
597 |
public: |
|
598 |
Item_func_collation(Item *a) :Item_str_func(a) {} |
|
599 |
String *val_str(String *); |
|
600 |
const char *func_name() const { return "collation"; } |
|
601 |
void fix_length_and_dec() |
|
602 |
{
|
|
603 |
collation.set(system_charset_info); |
|
604 |
max_length= 64 * collation.collation->mbmaxlen; // should be enough |
|
605 |
maybe_null= 0; |
|
606 |
};
|
|
607 |
table_map not_null_tables() const { return 0; } |
|
608 |
};
|
|
609 |
||
610 |
||
611 |
class Item_func_weight_string :public Item_str_func |
|
612 |
{
|
|
613 |
String tmp_value; |
|
482
by Brian Aker
Remove uint. |
614 |
uint32_t flags; |
615 |
uint32_t nweights; |
|
1
by brian
clean slate |
616 |
public: |
482
by Brian Aker
Remove uint. |
617 |
Item_func_weight_string(Item *a, uint32_t nweights_arg, uint32_t flags_arg) |
1
by brian
clean slate |
618 |
:Item_str_func(a) { nweights= nweights_arg; flags= flags_arg; } |
619 |
const char *func_name() const { return "weight_string"; } |
|
620 |
String *val_str(String *); |
|
621 |
void fix_length_and_dec(); |
|
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
622 |
/*
|
623 |
TODO: Currently this Item is not allowed for virtual columns
|
|
624 |
only due to a bug in generating virtual column value.
|
|
625 |
*/
|
|
481.3.1
by Monty Taylor
Merged vcol stuff. |
626 |
bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused))) |
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
627 |
{ return true; } |
1
by brian
clean slate |
628 |
};
|
629 |
||
630 |
#define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
|
|
631 |
class Item_func_uuid: public Item_str_func |
|
632 |
{
|
|
633 |
public: |
|
634 |
Item_func_uuid(): Item_str_func() {} |
|
635 |
void fix_length_and_dec() { |
|
636 |
collation.set(system_charset_info); |
|
637 |
/*
|
|
638 |
NOTE! uuid() should be changed to use 'ascii'
|
|
639 |
charset when hex(), format(), md5(), etc, and implicit
|
|
640 |
number-to-string conversion will use 'ascii'
|
|
641 |
*/
|
|
642 |
max_length= UUID_LENGTH * system_charset_info->mbmaxlen; |
|
643 |
}
|
|
644 |
const char *func_name() const{ return "uuid"; } |
|
645 |
String *val_str(String *); |
|
481.3.1
by Monty Taylor
Merged vcol stuff. |
646 |
bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused))) |
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
647 |
{ return true; } |
1
by brian
clean slate |
648 |
};
|
649 |