1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2003 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
||
17 |
/* This file defines all string functions */
|
|
18 |
||
19 |
#ifdef USE_PRAGMA_INTERFACE
|
|
20 |
#pragma interface /* gcc class implementation */ |
|
21 |
#endif
|
|
22 |
||
23 |
class Item_str_func :public Item_func |
|
24 |
{
|
|
25 |
public: |
|
26 |
Item_str_func() :Item_func() { decimals=NOT_FIXED_DEC; } |
|
27 |
Item_str_func(Item *a) :Item_func(a) {decimals=NOT_FIXED_DEC; } |
|
28 |
Item_str_func(Item *a,Item *b) :Item_func(a,b) { decimals=NOT_FIXED_DEC; } |
|
29 |
Item_str_func(Item *a,Item *b,Item *c) :Item_func(a,b,c) { decimals=NOT_FIXED_DEC; } |
|
30 |
Item_str_func(Item *a,Item *b,Item *c,Item *d) :Item_func(a,b,c,d) {decimals=NOT_FIXED_DEC; } |
|
31 |
Item_str_func(Item *a,Item *b,Item *c,Item *d, Item* e) :Item_func(a,b,c,d,e) {decimals=NOT_FIXED_DEC; } |
|
32 |
Item_str_func(List<Item> &list) :Item_func(list) {decimals=NOT_FIXED_DEC; } |
|
33 |
longlong val_int(); |
|
34 |
double val_real(); |
|
35 |
my_decimal *val_decimal(my_decimal *); |
|
36 |
enum Item_result result_type () const { return STRING_RESULT; } |
|
37 |
void left_right_max_length(); |
|
38 |
bool fix_fields(THD *thd, Item **ref); |
|
39 |
};
|
|
40 |
||
41 |
class Item_func_md5 :public Item_str_func |
|
42 |
{
|
|
43 |
String tmp_value; |
|
44 |
public: |
|
45 |
Item_func_md5(Item *a) :Item_str_func(a) |
|
46 |
{
|
|
47 |
collation.set(&my_charset_bin); |
|
48 |
}
|
|
49 |
String *val_str(String *); |
|
50 |
void fix_length_and_dec(); |
|
51 |
const char *func_name() const { return "md5"; } |
|
52 |
};
|
|
53 |
||
54 |
class Item_func_aes_encrypt :public Item_str_func |
|
55 |
{
|
|
56 |
public: |
|
57 |
Item_func_aes_encrypt(Item *a, Item *b) :Item_str_func(a,b) {} |
|
58 |
String *val_str(String *); |
|
59 |
void fix_length_and_dec(); |
|
60 |
const char *func_name() const { return "aes_encrypt"; } |
|
61 |
};
|
|
62 |
||
63 |
class Item_func_aes_decrypt :public Item_str_func |
|
64 |
{
|
|
65 |
public: |
|
66 |
Item_func_aes_decrypt(Item *a, Item *b) :Item_str_func(a,b) {} |
|
67 |
String *val_str(String *); |
|
68 |
void fix_length_and_dec(); |
|
69 |
const char *func_name() const { return "aes_decrypt"; } |
|
70 |
};
|
|
71 |
||
72 |
||
73 |
class Item_func_concat :public Item_str_func |
|
74 |
{
|
|
75 |
String tmp_value; |
|
76 |
public: |
|
77 |
Item_func_concat(List<Item> &list) :Item_str_func(list) {} |
|
78 |
Item_func_concat(Item *a,Item *b) :Item_str_func(a,b) {} |
|
79 |
String *val_str(String *); |
|
80 |
void fix_length_and_dec(); |
|
81 |
const char *func_name() const { return "concat"; } |
|
82 |
};
|
|
83 |
||
84 |
class Item_func_concat_ws :public Item_str_func |
|
85 |
{
|
|
86 |
String tmp_value; |
|
87 |
public: |
|
88 |
Item_func_concat_ws(List<Item> &list) :Item_str_func(list) {} |
|
89 |
String *val_str(String *); |
|
90 |
void fix_length_and_dec(); |
|
91 |
const char *func_name() const { return "concat_ws"; } |
|
92 |
table_map not_null_tables() const { return 0; } |
|
93 |
};
|
|
94 |
||
95 |
class Item_func_reverse :public Item_str_func |
|
96 |
{
|
|
97 |
String tmp_value; |
|
98 |
public: |
|
99 |
Item_func_reverse(Item *a) :Item_str_func(a) {} |
|
100 |
String *val_str(String *); |
|
101 |
void fix_length_and_dec(); |
|
102 |
const char *func_name() const { return "reverse"; } |
|
103 |
};
|
|
104 |
||
105 |
||
106 |
class Item_func_replace :public Item_str_func |
|
107 |
{
|
|
108 |
String tmp_value,tmp_value2; |
|
109 |
public: |
|
110 |
Item_func_replace(Item *org,Item *find,Item *replace) |
|
111 |
:Item_str_func(org,find,replace) {} |
|
112 |
String *val_str(String *); |
|
113 |
void fix_length_and_dec(); |
|
114 |
const char *func_name() const { return "replace"; } |
|
115 |
};
|
|
116 |
||
117 |
||
118 |
class Item_func_insert :public Item_str_func |
|
119 |
{
|
|
120 |
String tmp_value; |
|
121 |
public: |
|
122 |
Item_func_insert(Item *org,Item *start,Item *length,Item *new_str) |
|
123 |
:Item_str_func(org,start,length,new_str) {} |
|
124 |
String *val_str(String *); |
|
125 |
void fix_length_and_dec(); |
|
126 |
const char *func_name() const { return "insert"; } |
|
127 |
};
|
|
128 |
||
129 |
||
130 |
class Item_str_conv :public Item_str_func |
|
131 |
{
|
|
132 |
protected: |
|
133 |
uint multiply; |
|
134 |
my_charset_conv_case converter; |
|
135 |
String tmp_value; |
|
136 |
public: |
|
137 |
Item_str_conv(Item *item) :Item_str_func(item) {} |
|
138 |
String *val_str(String *); |
|
139 |
};
|
|
140 |
||
141 |
||
142 |
class Item_func_lcase :public Item_str_conv |
|
143 |
{
|
|
144 |
public: |
|
145 |
Item_func_lcase(Item *item) :Item_str_conv(item) {} |
|
146 |
const char *func_name() const { return "lcase"; } |
|
147 |
void fix_length_and_dec(); |
|
148 |
};
|
|
149 |
||
150 |
class Item_func_ucase :public Item_str_conv |
|
151 |
{
|
|
152 |
public: |
|
153 |
Item_func_ucase(Item *item) :Item_str_conv(item) {} |
|
154 |
const char *func_name() const { return "ucase"; } |
|
155 |
void fix_length_and_dec(); |
|
156 |
};
|
|
157 |
||
158 |
||
159 |
class Item_func_left :public Item_str_func |
|
160 |
{
|
|
161 |
String tmp_value; |
|
162 |
public: |
|
163 |
Item_func_left(Item *a,Item *b) :Item_str_func(a,b) {} |
|
164 |
String *val_str(String *); |
|
165 |
void fix_length_and_dec(); |
|
166 |
const char *func_name() const { return "left"; } |
|
167 |
};
|
|
168 |
||
169 |
||
170 |
class Item_func_right :public Item_str_func |
|
171 |
{
|
|
172 |
String tmp_value; |
|
173 |
public: |
|
174 |
Item_func_right(Item *a,Item *b) :Item_str_func(a,b) {} |
|
175 |
String *val_str(String *); |
|
176 |
void fix_length_and_dec(); |
|
177 |
const char *func_name() const { return "right"; } |
|
178 |
};
|
|
179 |
||
180 |
||
181 |
class Item_func_substr :public Item_str_func |
|
182 |
{
|
|
183 |
String tmp_value; |
|
184 |
public: |
|
185 |
Item_func_substr(Item *a,Item *b) :Item_str_func(a,b) {} |
|
186 |
Item_func_substr(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} |
|
187 |
String *val_str(String *); |
|
188 |
void fix_length_and_dec(); |
|
189 |
const char *func_name() const { return "substr"; } |
|
190 |
};
|
|
191 |
||
192 |
||
193 |
class Item_func_substr_index :public Item_str_func |
|
194 |
{
|
|
195 |
String tmp_value; |
|
196 |
public: |
|
197 |
Item_func_substr_index(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} |
|
198 |
String *val_str(String *); |
|
199 |
void fix_length_and_dec(); |
|
200 |
const char *func_name() const { return "substring_index"; } |
|
201 |
};
|
|
202 |
||
203 |
||
204 |
class Item_func_trim :public Item_str_func |
|
205 |
{
|
|
206 |
protected: |
|
207 |
String tmp_value; |
|
208 |
String remove; |
|
209 |
public: |
|
210 |
Item_func_trim(Item *a,Item *b) :Item_str_func(a,b) {} |
|
211 |
Item_func_trim(Item *a) :Item_str_func(a) {} |
|
212 |
String *val_str(String *); |
|
213 |
void fix_length_and_dec(); |
|
214 |
const char *func_name() const { return "trim"; } |
|
215 |
virtual void print(String *str, enum_query_type query_type); |
|
216 |
virtual const char *mode_name() const { return "both"; } |
|
217 |
};
|
|
218 |
||
219 |
||
220 |
class Item_func_ltrim :public Item_func_trim |
|
221 |
{
|
|
222 |
public: |
|
223 |
Item_func_ltrim(Item *a,Item *b) :Item_func_trim(a,b) {} |
|
224 |
Item_func_ltrim(Item *a) :Item_func_trim(a) {} |
|
225 |
String *val_str(String *); |
|
226 |
const char *func_name() const { return "ltrim"; } |
|
227 |
const char *mode_name() const { return "leading"; } |
|
228 |
};
|
|
229 |
||
230 |
||
231 |
class Item_func_rtrim :public Item_func_trim |
|
232 |
{
|
|
233 |
public: |
|
234 |
Item_func_rtrim(Item *a,Item *b) :Item_func_trim(a,b) {} |
|
235 |
Item_func_rtrim(Item *a) :Item_func_trim(a) {} |
|
236 |
String *val_str(String *); |
|
237 |
const char *func_name() const { return "rtrim"; } |
|
238 |
const char *mode_name() const { return "trailing"; } |
|
239 |
};
|
|
240 |
||
241 |
||
242 |
/*
|
|
243 |
Item_func_password -- new (4.1.1) PASSWORD() function implementation.
|
|
244 |
Returns strcat('*', octet2hex(sha1(sha1(password)))). '*' stands for new
|
|
245 |
password format, sha1(sha1(password) is so-called hash_stage2 value.
|
|
246 |
Length of returned string is always 41 byte. To find out how entire
|
|
247 |
authentication procedure works, see comments in password.c.
|
|
248 |
*/
|
|
249 |
||
250 |
class Item_func_password :public Item_str_func |
|
251 |
{
|
|
252 |
char tmp_value[SCRAMBLED_PASSWORD_CHAR_LENGTH+1]; |
|
253 |
public: |
|
254 |
Item_func_password(Item *a) :Item_str_func(a) {} |
|
255 |
String *val_str(String *str); |
|
256 |
void fix_length_and_dec() { max_length= SCRAMBLED_PASSWORD_CHAR_LENGTH; } |
|
257 |
const char *func_name() const { return "password"; } |
|
258 |
static char *alloc(THD *thd, const char *password); |
|
259 |
};
|
|
260 |
||
261 |
||
262 |
/*
|
|
263 |
Item_func_old_password -- PASSWORD() implementation used in MySQL 3.21 - 4.0
|
|
264 |
compatibility mode. This item is created in sql_yacc.yy when
|
|
265 |
'old_passwords' session variable is set, and to handle OLD_PASSWORD()
|
|
266 |
function.
|
|
267 |
*/
|
|
268 |
||
269 |
class Item_func_old_password :public Item_str_func |
|
270 |
{
|
|
271 |
char tmp_value[SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1]; |
|
272 |
public: |
|
273 |
Item_func_old_password(Item *a) :Item_str_func(a) {} |
|
274 |
String *val_str(String *str); |
|
275 |
void fix_length_and_dec() { max_length= SCRAMBLED_PASSWORD_CHAR_LENGTH_323; } |
|
276 |
const char *func_name() const { return "old_password"; } |
|
277 |
static char *alloc(THD *thd, const char *password); |
|
278 |
};
|
|
279 |
||
280 |
||
281 |
class Item_func_des_encrypt :public Item_str_func |
|
282 |
{
|
|
283 |
String tmp_value; |
|
284 |
public: |
|
285 |
String *val_str(String *); |
|
286 |
void fix_length_and_dec() |
|
287 |
{ maybe_null=1; max_length = args[0]->max_length+8; } |
|
288 |
const char *func_name() const { return "des_encrypt"; } |
|
289 |
};
|
|
290 |
||
291 |
class Item_func_des_decrypt :public Item_str_func |
|
292 |
{
|
|
293 |
String tmp_value; |
|
294 |
public: |
|
295 |
String *val_str(String *); |
|
296 |
void fix_length_and_dec() { maybe_null=1; max_length = args[0]->max_length; } |
|
297 |
const char *func_name() const { return "des_decrypt"; } |
|
298 |
};
|
|
299 |
||
300 |
class Item_func_encrypt :public Item_str_func |
|
301 |
{
|
|
302 |
String tmp_value; |
|
303 |
||
304 |
/* Encapsulate common constructor actions */
|
|
305 |
void constructor_helper() |
|
306 |
{
|
|
307 |
collation.set(&my_charset_bin); |
|
308 |
}
|
|
309 |
public: |
|
310 |
Item_func_encrypt(Item *a) :Item_str_func(a) |
|
311 |
{
|
|
312 |
constructor_helper(); |
|
313 |
}
|
|
314 |
Item_func_encrypt(Item *a, Item *b): Item_str_func(a,b) |
|
315 |
{
|
|
316 |
constructor_helper(); |
|
317 |
}
|
|
318 |
String *val_str(String *); |
|
319 |
void fix_length_and_dec() { maybe_null=1; max_length = 13; } |
|
320 |
const char *func_name() const { return "encrypt"; } |
|
321 |
};
|
|
322 |
||
323 |
#include "sql_crypt.h" |
|
324 |
||
325 |
||
326 |
class Item_func_encode :public Item_str_func |
|
327 |
{
|
|
328 |
public: |
|
329 |
Item_func_encode(Item *a, Item *seed): |
|
330 |
Item_str_func(a, seed) {} |
|
331 |
String *val_str(String *); |
|
332 |
void fix_length_and_dec(); |
|
333 |
const char *func_name() const { return "encode"; } |
|
334 |
};
|
|
335 |
||
336 |
||
337 |
class Item_func_decode :public Item_func_encode |
|
338 |
{
|
|
339 |
public: |
|
340 |
Item_func_decode(Item *a, Item *seed): Item_func_encode(a, seed) {} |
|
341 |
String *val_str(String *); |
|
342 |
const char *func_name() const { return "decode"; } |
|
343 |
};
|
|
344 |
||
345 |
||
346 |
class Item_func_sysconst :public Item_str_func |
|
347 |
{
|
|
348 |
public: |
|
349 |
Item_func_sysconst() |
|
350 |
{ collation.set(system_charset_info,DERIVATION_SYSCONST); } |
|
351 |
Item *safe_charset_converter(CHARSET_INFO *tocs); |
|
352 |
/*
|
|
353 |
Used to create correct Item name in new converted item in
|
|
354 |
safe_charset_converter, return string representation of this function
|
|
355 |
call
|
|
356 |
*/
|
|
357 |
virtual const char *fully_qualified_func_name() const = 0; |
|
358 |
};
|
|
359 |
||
360 |
||
361 |
class Item_func_database :public Item_func_sysconst |
|
362 |
{
|
|
363 |
public: |
|
364 |
Item_func_database() :Item_func_sysconst() {} |
|
365 |
String *val_str(String *); |
|
366 |
void fix_length_and_dec() |
|
367 |
{
|
|
368 |
max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen; |
|
369 |
maybe_null=1; |
|
370 |
}
|
|
371 |
const char *func_name() const { return "database"; } |
|
372 |
const char *fully_qualified_func_name() const { return "database()"; } |
|
373 |
};
|
|
374 |
||
375 |
||
376 |
class Item_func_user :public Item_func_sysconst |
|
377 |
{
|
|
378 |
protected: |
|
379 |
bool init (const char *user, const char *host); |
|
380 |
||
381 |
public: |
|
382 |
Item_func_user() |
|
383 |
{
|
|
384 |
str_value.set("", 0, system_charset_info); |
|
385 |
}
|
|
386 |
String *val_str(String *) |
|
387 |
{
|
|
388 |
DBUG_ASSERT(fixed == 1); |
|
389 |
return (null_value ? 0 : &str_value); |
|
390 |
}
|
|
391 |
bool fix_fields(THD *thd, Item **ref); |
|
392 |
void fix_length_and_dec() |
|
393 |
{
|
|
394 |
max_length= (USERNAME_CHAR_LENGTH + HOSTNAME_LENGTH + 1) * |
|
395 |
system_charset_info->mbmaxlen; |
|
396 |
}
|
|
397 |
const char *func_name() const { return "user"; } |
|
398 |
const char *fully_qualified_func_name() const { return "user()"; } |
|
399 |
int save_in_field(Field *field, bool no_conversions) |
|
400 |
{
|
|
401 |
return save_str_value_in_field(field, &str_value); |
|
402 |
}
|
|
403 |
};
|
|
404 |
||
405 |
||
406 |
class Item_func_current_user :public Item_func_user |
|
407 |
{
|
|
408 |
Name_resolution_context *context; |
|
409 |
||
410 |
public: |
|
411 |
Item_func_current_user(Name_resolution_context *context_arg) |
|
412 |
: context(context_arg) {} |
|
413 |
bool fix_fields(THD *thd, Item **ref); |
|
414 |
const char *func_name() const { return "current_user"; } |
|
415 |
const char *fully_qualified_func_name() const { return "current_user()"; } |
|
416 |
};
|
|
417 |
||
418 |
||
419 |
class Item_func_soundex :public Item_str_func |
|
420 |
{
|
|
421 |
String tmp_value; |
|
422 |
public: |
|
423 |
Item_func_soundex(Item *a) :Item_str_func(a) {} |
|
424 |
String *val_str(String *); |
|
425 |
void fix_length_and_dec(); |
|
426 |
const char *func_name() const { return "soundex"; } |
|
427 |
};
|
|
428 |
||
429 |
||
430 |
class Item_func_elt :public Item_str_func |
|
431 |
{
|
|
432 |
public: |
|
433 |
Item_func_elt(List<Item> &list) :Item_str_func(list) {} |
|
434 |
double val_real(); |
|
435 |
longlong val_int(); |
|
436 |
String *val_str(String *str); |
|
437 |
void fix_length_and_dec(); |
|
438 |
const char *func_name() const { return "elt"; } |
|
439 |
};
|
|
440 |
||
441 |
||
442 |
class Item_func_make_set :public Item_str_func |
|
443 |
{
|
|
444 |
Item *item; |
|
445 |
String tmp_str; |
|
446 |
||
447 |
public: |
|
448 |
Item_func_make_set(Item *a,List<Item> &list) :Item_str_func(list),item(a) {} |
|
449 |
String *val_str(String *str); |
|
450 |
bool fix_fields(THD *thd, Item **ref) |
|
451 |
{
|
|
452 |
DBUG_ASSERT(fixed == 0); |
|
453 |
return ((!item->fixed && item->fix_fields(thd, &item)) || |
|
454 |
item->check_cols(1) || |
|
455 |
Item_func::fix_fields(thd, ref)); |
|
456 |
}
|
|
457 |
void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields); |
|
458 |
void fix_length_and_dec(); |
|
459 |
void update_used_tables(); |
|
460 |
const char *func_name() const { return "make_set"; } |
|
461 |
||
462 |
bool walk(Item_processor processor, bool walk_subquery, uchar *arg) |
|
463 |
{
|
|
464 |
return item->walk(processor, walk_subquery, arg) || |
|
465 |
Item_str_func::walk(processor, walk_subquery, arg); |
|
466 |
}
|
|
467 |
Item *transform(Item_transformer transformer, uchar *arg); |
|
468 |
virtual void print(String *str, enum_query_type query_type); |
|
469 |
};
|
|
470 |
||
471 |
||
472 |
class Item_func_format :public Item_str_func |
|
473 |
{
|
|
474 |
String tmp_str; |
|
475 |
public: |
|
476 |
Item_func_format(Item *org, Item *dec); |
|
477 |
String *val_str(String *); |
|
478 |
void fix_length_and_dec(); |
|
479 |
const char *func_name() const { return "format"; } |
|
480 |
virtual void print(String *str, enum_query_type query_type); |
|
481 |
};
|
|
482 |
||
483 |
||
484 |
class Item_func_char :public Item_str_func |
|
485 |
{
|
|
486 |
public: |
|
487 |
Item_func_char(List<Item> &list) :Item_str_func(list) |
|
488 |
{ collation.set(&my_charset_bin); } |
|
489 |
Item_func_char(List<Item> &list, CHARSET_INFO *cs) :Item_str_func(list) |
|
490 |
{ collation.set(cs); } |
|
491 |
String *val_str(String *); |
|
492 |
void fix_length_and_dec() |
|
493 |
{
|
|
494 |
max_length= arg_count * 4; |
|
495 |
}
|
|
496 |
const char *func_name() const { return "char"; } |
|
497 |
};
|
|
498 |
||
499 |
||
500 |
class Item_func_repeat :public Item_str_func |
|
501 |
{
|
|
502 |
String tmp_value; |
|
503 |
public: |
|
504 |
Item_func_repeat(Item *arg1,Item *arg2) :Item_str_func(arg1,arg2) {} |
|
505 |
String *val_str(String *); |
|
506 |
void fix_length_and_dec(); |
|
507 |
const char *func_name() const { return "repeat"; } |
|
508 |
};
|
|
509 |
||
510 |
||
511 |
class Item_func_rpad :public Item_str_func |
|
512 |
{
|
|
513 |
String tmp_value, rpad_str; |
|
514 |
public: |
|
515 |
Item_func_rpad(Item *arg1,Item *arg2,Item *arg3) |
|
516 |
:Item_str_func(arg1,arg2,arg3) {} |
|
517 |
String *val_str(String *); |
|
518 |
void fix_length_and_dec(); |
|
519 |
const char *func_name() const { return "rpad"; } |
|
520 |
};
|
|
521 |
||
522 |
||
523 |
class Item_func_lpad :public Item_str_func |
|
524 |
{
|
|
525 |
String tmp_value, lpad_str; |
|
526 |
public: |
|
527 |
Item_func_lpad(Item *arg1,Item *arg2,Item *arg3) |
|
528 |
:Item_str_func(arg1,arg2,arg3) {} |
|
529 |
String *val_str(String *); |
|
530 |
void fix_length_and_dec(); |
|
531 |
const char *func_name() const { return "lpad"; } |
|
532 |
};
|
|
533 |
||
534 |
||
535 |
class Item_func_conv :public Item_str_func |
|
536 |
{
|
|
537 |
public: |
|
538 |
Item_func_conv(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {} |
|
539 |
const char *func_name() const { return "conv"; } |
|
540 |
String *val_str(String *); |
|
541 |
void fix_length_and_dec() |
|
542 |
{
|
|
543 |
collation.set(default_charset()); |
|
544 |
max_length=64; |
|
545 |
maybe_null= 1; |
|
546 |
}
|
|
547 |
};
|
|
548 |
||
549 |
||
550 |
class Item_func_hex :public Item_str_func |
|
551 |
{
|
|
552 |
String tmp_value; |
|
553 |
public: |
|
554 |
Item_func_hex(Item *a) :Item_str_func(a) {} |
|
555 |
const char *func_name() const { return "hex"; } |
|
556 |
String *val_str(String *); |
|
557 |
void fix_length_and_dec() |
|
558 |
{
|
|
559 |
collation.set(default_charset()); |
|
560 |
decimals=0; |
|
561 |
max_length=args[0]->max_length*2*collation.collation->mbmaxlen; |
|
562 |
}
|
|
563 |
};
|
|
564 |
||
565 |
class Item_func_unhex :public Item_str_func |
|
566 |
{
|
|
567 |
String tmp_value; |
|
568 |
public: |
|
569 |
Item_func_unhex(Item *a) :Item_str_func(a) |
|
570 |
{
|
|
571 |
/* there can be bad hex strings */
|
|
572 |
maybe_null= 1; |
|
573 |
}
|
|
574 |
const char *func_name() const { return "unhex"; } |
|
575 |
String *val_str(String *); |
|
576 |
void fix_length_and_dec() |
|
577 |
{
|
|
578 |
collation.set(&my_charset_bin); |
|
579 |
decimals=0; |
|
580 |
max_length=(1+args[0]->max_length)/2; |
|
581 |
}
|
|
582 |
};
|
|
583 |
||
584 |
||
585 |
class Item_func_binary :public Item_str_func |
|
586 |
{
|
|
587 |
public: |
|
588 |
Item_func_binary(Item *a) :Item_str_func(a) {} |
|
589 |
String *val_str(String *a) |
|
590 |
{
|
|
591 |
DBUG_ASSERT(fixed == 1); |
|
592 |
String *tmp=args[0]->val_str(a); |
|
593 |
null_value=args[0]->null_value; |
|
594 |
if (tmp) |
|
595 |
tmp->set_charset(&my_charset_bin); |
|
596 |
return tmp; |
|
597 |
}
|
|
598 |
void fix_length_and_dec() |
|
599 |
{
|
|
600 |
collation.set(&my_charset_bin); |
|
601 |
max_length=args[0]->max_length; |
|
602 |
}
|
|
603 |
virtual void print(String *str, enum_query_type query_type); |
|
604 |
const char *func_name() const { return "cast_as_binary"; } |
|
605 |
};
|
|
606 |
||
607 |
||
608 |
class Item_load_file :public Item_str_func |
|
609 |
{
|
|
610 |
String tmp_value; |
|
611 |
public: |
|
612 |
Item_load_file(Item *a) :Item_str_func(a) {} |
|
613 |
String *val_str(String *); |
|
614 |
const char *func_name() const { return "load_file"; } |
|
615 |
void fix_length_and_dec() |
|
616 |
{
|
|
617 |
collation.set(&my_charset_bin, DERIVATION_COERCIBLE); |
|
618 |
maybe_null=1; |
|
619 |
max_length=MAX_BLOB_WIDTH; |
|
620 |
}
|
|
621 |
};
|
|
622 |
||
623 |
||
624 |
class Item_func_export_set: public Item_str_func |
|
625 |
{
|
|
626 |
public: |
|
627 |
Item_func_export_set(Item *a,Item *b,Item* c) :Item_str_func(a,b,c) {} |
|
628 |
Item_func_export_set(Item *a,Item *b,Item* c,Item* d) :Item_str_func(a,b,c,d) {} |
|
629 |
Item_func_export_set(Item *a,Item *b,Item* c,Item* d,Item* e) :Item_str_func(a,b,c,d,e) {} |
|
630 |
String *val_str(String *str); |
|
631 |
void fix_length_and_dec(); |
|
632 |
const char *func_name() const { return "export_set"; } |
|
633 |
};
|
|
634 |
||
635 |
class Item_func_quote :public Item_str_func |
|
636 |
{
|
|
637 |
String tmp_value; |
|
638 |
public: |
|
639 |
Item_func_quote(Item *a) :Item_str_func(a) {} |
|
640 |
const char *func_name() const { return "quote"; } |
|
641 |
String *val_str(String *); |
|
642 |
void fix_length_and_dec() |
|
643 |
{
|
|
644 |
collation.set(args[0]->collation); |
|
645 |
max_length= args[0]->max_length * 2 + 2; |
|
646 |
}
|
|
647 |
};
|
|
648 |
||
649 |
class Item_func_conv_charset :public Item_str_func |
|
650 |
{
|
|
651 |
bool use_cached_value; |
|
652 |
public: |
|
653 |
bool safe; |
|
654 |
CHARSET_INFO *conv_charset; // keep it public |
|
655 |
Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a) |
|
656 |
{ conv_charset= cs; use_cached_value= 0; safe= 0; } |
|
657 |
Item_func_conv_charset(Item *a, CHARSET_INFO *cs, bool cache_if_const) |
|
658 |
:Item_str_func(a) |
|
659 |
{
|
|
660 |
DBUG_ASSERT(args[0]->fixed); |
|
661 |
conv_charset= cs; |
|
662 |
if (cache_if_const && args[0]->const_item()) |
|
663 |
{
|
|
664 |
uint errors= 0; |
|
665 |
String tmp, *str= args[0]->val_str(&tmp); |
|
666 |
if (!str || str_value.copy(str->ptr(), str->length(), |
|
667 |
str->charset(), conv_charset, &errors)) |
|
668 |
null_value= 1; |
|
669 |
use_cached_value= 1; |
|
670 |
str_value.mark_as_const(); |
|
671 |
safe= (errors == 0); |
|
672 |
}
|
|
673 |
else
|
|
674 |
{
|
|
675 |
use_cached_value= 0; |
|
676 |
/*
|
|
677 |
Conversion from and to "binary" is safe.
|
|
678 |
Conversion to Unicode is safe.
|
|
679 |
Other kind of conversions are potentially lossy.
|
|
680 |
*/
|
|
681 |
safe= (args[0]->collation.collation == &my_charset_bin || |
|
682 |
cs == &my_charset_bin || |
|
683 |
(cs->state & MY_CS_UNICODE)); |
|
684 |
}
|
|
685 |
}
|
|
686 |
String *val_str(String *); |
|
687 |
void fix_length_and_dec(); |
|
688 |
const char *func_name() const { return "convert"; } |
|
689 |
virtual void print(String *str, enum_query_type query_type); |
|
690 |
};
|
|
691 |
||
692 |
class Item_func_set_collation :public Item_str_func |
|
693 |
{
|
|
694 |
public: |
|
695 |
Item_func_set_collation(Item *a, Item *b) :Item_str_func(a,b) {}; |
|
696 |
String *val_str(String *); |
|
697 |
void fix_length_and_dec(); |
|
698 |
bool eq(const Item *item, bool binary_cmp) const; |
|
699 |
const char *func_name() const { return "collate"; } |
|
700 |
enum Functype functype() const { return COLLATE_FUNC; } |
|
701 |
virtual void print(String *str, enum_query_type query_type); |
|
702 |
Item_field *filed_for_view_update() |
|
703 |
{
|
|
704 |
/* this function is transparent for view updating */
|
|
705 |
return args[0]->filed_for_view_update(); |
|
706 |
}
|
|
707 |
};
|
|
708 |
||
709 |
class Item_func_charset :public Item_str_func |
|
710 |
{
|
|
711 |
public: |
|
712 |
Item_func_charset(Item *a) :Item_str_func(a) {} |
|
713 |
String *val_str(String *); |
|
714 |
const char *func_name() const { return "charset"; } |
|
715 |
void fix_length_and_dec() |
|
716 |
{
|
|
717 |
collation.set(system_charset_info); |
|
718 |
max_length= 64 * collation.collation->mbmaxlen; // should be enough |
|
719 |
maybe_null= 0; |
|
720 |
};
|
|
721 |
table_map not_null_tables() const { return 0; } |
|
722 |
};
|
|
723 |
||
724 |
class Item_func_collation :public Item_str_func |
|
725 |
{
|
|
726 |
public: |
|
727 |
Item_func_collation(Item *a) :Item_str_func(a) {} |
|
728 |
String *val_str(String *); |
|
729 |
const char *func_name() const { return "collation"; } |
|
730 |
void fix_length_and_dec() |
|
731 |
{
|
|
732 |
collation.set(system_charset_info); |
|
733 |
max_length= 64 * collation.collation->mbmaxlen; // should be enough |
|
734 |
maybe_null= 0; |
|
735 |
};
|
|
736 |
table_map not_null_tables() const { return 0; } |
|
737 |
};
|
|
738 |
||
739 |
||
740 |
class Item_func_weight_string :public Item_str_func |
|
741 |
{
|
|
742 |
String tmp_value; |
|
743 |
uint flags; |
|
744 |
uint nweights; |
|
745 |
public: |
|
746 |
Item_func_weight_string(Item *a, uint nweights_arg, uint flags_arg) |
|
747 |
:Item_str_func(a) { nweights= nweights_arg; flags= flags_arg; } |
|
748 |
const char *func_name() const { return "weight_string"; } |
|
749 |
String *val_str(String *); |
|
750 |
void fix_length_and_dec(); |
|
751 |
};
|
|
752 |
||
753 |
||
754 |
class Item_func_crc32 :public Item_int_func |
|
755 |
{
|
|
756 |
String value; |
|
757 |
public: |
|
758 |
Item_func_crc32(Item *a) :Item_int_func(a) { unsigned_flag= 1; } |
|
759 |
const char *func_name() const { return "crc32"; } |
|
760 |
void fix_length_and_dec() { max_length=10; } |
|
761 |
longlong val_int(); |
|
762 |
};
|
|
763 |
||
764 |
class Item_func_uncompressed_length : public Item_int_func |
|
765 |
{
|
|
766 |
String value; |
|
767 |
public: |
|
768 |
Item_func_uncompressed_length(Item *a):Item_int_func(a){} |
|
769 |
const char *func_name() const{return "uncompressed_length";} |
|
770 |
void fix_length_and_dec() { max_length=10; } |
|
771 |
longlong val_int(); |
|
772 |
};
|
|
773 |
||
774 |
#ifdef HAVE_COMPRESS
|
|
775 |
#define ZLIB_DEPENDED_FUNCTION ;
|
|
776 |
#else
|
|
777 |
#define ZLIB_DEPENDED_FUNCTION { null_value=1; return 0; }
|
|
778 |
#endif
|
|
779 |
||
780 |
class Item_func_compress: public Item_str_func |
|
781 |
{
|
|
782 |
String buffer; |
|
783 |
public: |
|
784 |
Item_func_compress(Item *a):Item_str_func(a){} |
|
785 |
void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;} |
|
786 |
const char *func_name() const{return "compress";} |
|
787 |
String *val_str(String *) ZLIB_DEPENDED_FUNCTION |
|
788 |
};
|
|
789 |
||
790 |
class Item_func_uncompress: public Item_str_func |
|
791 |
{
|
|
792 |
String buffer; |
|
793 |
public: |
|
794 |
Item_func_uncompress(Item *a): Item_str_func(a){} |
|
795 |
void fix_length_and_dec(){ maybe_null= 1; max_length= MAX_BLOB_WIDTH; } |
|
796 |
const char *func_name() const{return "uncompress";} |
|
797 |
String *val_str(String *) ZLIB_DEPENDED_FUNCTION |
|
798 |
};
|
|
799 |
||
800 |
#define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
|
|
801 |
class Item_func_uuid: public Item_str_func |
|
802 |
{
|
|
803 |
public: |
|
804 |
Item_func_uuid(): Item_str_func() {} |
|
805 |
void fix_length_and_dec() { |
|
806 |
collation.set(system_charset_info); |
|
807 |
/*
|
|
808 |
NOTE! uuid() should be changed to use 'ascii'
|
|
809 |
charset when hex(), format(), md5(), etc, and implicit
|
|
810 |
number-to-string conversion will use 'ascii'
|
|
811 |
*/
|
|
812 |
max_length= UUID_LENGTH * system_charset_info->mbmaxlen; |
|
813 |
}
|
|
814 |
const char *func_name() const{ return "uuid"; } |
|
815 |
String *val_str(String *); |
|
816 |
};
|
|
817 |