~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_strfunc.h

  • Committer: Brian Aker
  • Date: 2008-07-08 16:17:31 UTC
  • Revision ID: brian@tangent.org-20080708161731-io36j7igglok79py
DATE cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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,
 
400
                    bool no_conversions __attribute__((__unused__)))
 
401
  {
 
402
    return save_str_value_in_field(field, &str_value);
 
403
  }
 
404
};
 
405
 
 
406
 
 
407
class Item_func_current_user :public Item_func_user
 
408
{
 
409
  Name_resolution_context *context;
 
410
 
 
411
public:
 
412
  Item_func_current_user(Name_resolution_context *context_arg)
 
413
    : context(context_arg) {}
 
414
  bool fix_fields(THD *thd, Item **ref);
 
415
  const char *func_name() const { return "current_user"; }
 
416
  const char *fully_qualified_func_name() const { return "current_user()"; }
 
417
};
 
418
 
 
419
 
 
420
class Item_func_soundex :public Item_str_func
 
421
{
 
422
  String tmp_value;
 
423
public:
 
424
  Item_func_soundex(Item *a) :Item_str_func(a) {}
 
425
  String *val_str(String *);
 
426
  void fix_length_and_dec();
 
427
  const char *func_name() const { return "soundex"; }
 
428
};
 
429
 
 
430
 
 
431
class Item_func_elt :public Item_str_func
 
432
{
 
433
public:
 
434
  Item_func_elt(List<Item> &list) :Item_str_func(list) {}
 
435
  double val_real();
 
436
  longlong val_int();
 
437
  String *val_str(String *str);
 
438
  void fix_length_and_dec();
 
439
  const char *func_name() const { return "elt"; }
 
440
};
 
441
 
 
442
 
 
443
class Item_func_make_set :public Item_str_func
 
444
{
 
445
  Item *item;
 
446
  String tmp_str;
 
447
 
 
448
public:
 
449
  Item_func_make_set(Item *a,List<Item> &list) :Item_str_func(list),item(a) {}
 
450
  String *val_str(String *str);
 
451
  bool fix_fields(THD *thd, Item **ref)
 
452
  {
 
453
    DBUG_ASSERT(fixed == 0);
 
454
    return ((!item->fixed && item->fix_fields(thd, &item)) ||
 
455
            item->check_cols(1) ||
 
456
            Item_func::fix_fields(thd, ref));
 
457
  }
 
458
  void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
 
459
  void fix_length_and_dec();
 
460
  void update_used_tables();
 
461
  const char *func_name() const { return "make_set"; }
 
462
 
 
463
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
 
464
  {
 
465
    return item->walk(processor, walk_subquery, arg) ||
 
466
      Item_str_func::walk(processor, walk_subquery, arg);
 
467
  }
 
468
  Item *transform(Item_transformer transformer, uchar *arg);
 
469
  virtual void print(String *str, enum_query_type query_type);
 
470
};
 
471
 
 
472
 
 
473
class Item_func_format :public Item_str_func
 
474
{
 
475
  String tmp_str;
 
476
public:
 
477
  Item_func_format(Item *org, Item *dec);
 
478
  String *val_str(String *);
 
479
  void fix_length_and_dec();
 
480
  const char *func_name() const { return "format"; }
 
481
  virtual void print(String *str, enum_query_type query_type);
 
482
};
 
483
 
 
484
 
 
485
class Item_func_char :public Item_str_func
 
486
{
 
487
public:
 
488
  Item_func_char(List<Item> &list) :Item_str_func(list)
 
489
  { collation.set(&my_charset_bin); }
 
490
  Item_func_char(List<Item> &list, CHARSET_INFO *cs) :Item_str_func(list)
 
491
  { collation.set(cs); }  
 
492
  String *val_str(String *);
 
493
  void fix_length_and_dec() 
 
494
  {
 
495
    max_length= arg_count * 4;
 
496
  }
 
497
  const char *func_name() const { return "char"; }
 
498
};
 
499
 
 
500
 
 
501
class Item_func_repeat :public Item_str_func
 
502
{
 
503
  String tmp_value;
 
504
public:
 
505
  Item_func_repeat(Item *arg1,Item *arg2) :Item_str_func(arg1,arg2) {}
 
506
  String *val_str(String *);
 
507
  void fix_length_and_dec();
 
508
  const char *func_name() const { return "repeat"; }
 
509
};
 
510
 
 
511
 
 
512
class Item_func_rpad :public Item_str_func
 
513
{
 
514
  String tmp_value, rpad_str;
 
515
public:
 
516
  Item_func_rpad(Item *arg1,Item *arg2,Item *arg3)
 
517
    :Item_str_func(arg1,arg2,arg3) {}
 
518
  String *val_str(String *);
 
519
  void fix_length_and_dec();
 
520
  const char *func_name() const { return "rpad"; }
 
521
};
 
522
 
 
523
 
 
524
class Item_func_lpad :public Item_str_func
 
525
{
 
526
  String tmp_value, lpad_str;
 
527
public:
 
528
  Item_func_lpad(Item *arg1,Item *arg2,Item *arg3)
 
529
    :Item_str_func(arg1,arg2,arg3) {}
 
530
  String *val_str(String *);
 
531
  void fix_length_and_dec();
 
532
  const char *func_name() const { return "lpad"; }
 
533
};
 
534
 
 
535
 
 
536
class Item_func_conv :public Item_str_func
 
537
{
 
538
public:
 
539
  Item_func_conv(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {}
 
540
  const char *func_name() const { return "conv"; }
 
541
  String *val_str(String *);
 
542
  void fix_length_and_dec()
 
543
  {
 
544
    collation.set(default_charset());
 
545
    max_length=64;
 
546
    maybe_null= 1;
 
547
  }
 
548
};
 
549
 
 
550
 
 
551
class Item_func_hex :public Item_str_func
 
552
{
 
553
  String tmp_value;
 
554
public:
 
555
  Item_func_hex(Item *a) :Item_str_func(a) {}
 
556
  const char *func_name() const { return "hex"; }
 
557
  String *val_str(String *);
 
558
  void fix_length_and_dec()
 
559
  {
 
560
    collation.set(default_charset());
 
561
    decimals=0;
 
562
    max_length=args[0]->max_length*2*collation.collation->mbmaxlen;
 
563
  }
 
564
};
 
565
 
 
566
class Item_func_unhex :public Item_str_func
 
567
{
 
568
  String tmp_value;
 
569
public:
 
570
  Item_func_unhex(Item *a) :Item_str_func(a) 
 
571
  { 
 
572
    /* there can be bad hex strings */
 
573
    maybe_null= 1; 
 
574
  }
 
575
  const char *func_name() const { return "unhex"; }
 
576
  String *val_str(String *);
 
577
  void fix_length_and_dec()
 
578
  {
 
579
    collation.set(&my_charset_bin);
 
580
    decimals=0;
 
581
    max_length=(1+args[0]->max_length)/2;
 
582
  }
 
583
};
 
584
 
 
585
 
 
586
class Item_func_binary :public Item_str_func
 
587
{
 
588
public:
 
589
  Item_func_binary(Item *a) :Item_str_func(a) {}
 
590
  String *val_str(String *a)
 
591
  {
 
592
    DBUG_ASSERT(fixed == 1);
 
593
    String *tmp=args[0]->val_str(a);
 
594
    null_value=args[0]->null_value;
 
595
    if (tmp)
 
596
      tmp->set_charset(&my_charset_bin);
 
597
    return tmp;
 
598
  }
 
599
  void fix_length_and_dec()
 
600
  {
 
601
    collation.set(&my_charset_bin);
 
602
    max_length=args[0]->max_length;
 
603
  }
 
604
  virtual void print(String *str, enum_query_type query_type);
 
605
  const char *func_name() const { return "cast_as_binary"; }
 
606
};
 
607
 
 
608
 
 
609
class Item_load_file :public Item_str_func
 
610
{
 
611
  String tmp_value;
 
612
public:
 
613
  Item_load_file(Item *a) :Item_str_func(a) {}
 
614
  String *val_str(String *);
 
615
  const char *func_name() const { return "load_file"; }
 
616
  void fix_length_and_dec()
 
617
  {
 
618
    collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
 
619
    maybe_null=1;
 
620
    max_length=MAX_BLOB_WIDTH;
 
621
  }
 
622
};
 
623
 
 
624
 
 
625
class Item_func_export_set: public Item_str_func
 
626
{
 
627
 public:
 
628
  Item_func_export_set(Item *a,Item *b,Item* c) :Item_str_func(a,b,c) {}
 
629
  Item_func_export_set(Item *a,Item *b,Item* c,Item* d) :Item_str_func(a,b,c,d) {}
 
630
  Item_func_export_set(Item *a,Item *b,Item* c,Item* d,Item* e) :Item_str_func(a,b,c,d,e) {}
 
631
  String  *val_str(String *str);
 
632
  void fix_length_and_dec();
 
633
  const char *func_name() const { return "export_set"; }
 
634
};
 
635
 
 
636
class Item_func_quote :public Item_str_func
 
637
{
 
638
  String tmp_value;
 
639
public:
 
640
  Item_func_quote(Item *a) :Item_str_func(a) {}
 
641
  const char *func_name() const { return "quote"; }
 
642
  String *val_str(String *);
 
643
  void fix_length_and_dec()
 
644
  {
 
645
    collation.set(args[0]->collation);
 
646
    max_length= args[0]->max_length * 2 + 2;
 
647
  }
 
648
};
 
649
 
 
650
class Item_func_conv_charset :public Item_str_func
 
651
{
 
652
  bool use_cached_value;
 
653
public:
 
654
  bool safe;
 
655
  CHARSET_INFO *conv_charset; // keep it public
 
656
  Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a) 
 
657
  { conv_charset= cs; use_cached_value= 0; safe= 0; }
 
658
  Item_func_conv_charset(Item *a, CHARSET_INFO *cs, bool cache_if_const) 
 
659
    :Item_str_func(a) 
 
660
  {
 
661
    DBUG_ASSERT(args[0]->fixed);
 
662
    conv_charset= cs;
 
663
    if (cache_if_const && args[0]->const_item())
 
664
    {
 
665
      uint errors= 0;
 
666
      String tmp, *str= args[0]->val_str(&tmp);
 
667
      if (!str || str_value.copy(str->ptr(), str->length(),
 
668
                                 str->charset(), conv_charset, &errors))
 
669
        null_value= 1;
 
670
      use_cached_value= 1;
 
671
      str_value.mark_as_const();
 
672
      safe= (errors == 0);
 
673
    }
 
674
    else
 
675
    {
 
676
      use_cached_value= 0;
 
677
      /*
 
678
        Conversion from and to "binary" is safe.
 
679
        Conversion to Unicode is safe.
 
680
        Other kind of conversions are potentially lossy.
 
681
      */
 
682
      safe= (args[0]->collation.collation == &my_charset_bin ||
 
683
             cs == &my_charset_bin ||
 
684
             (cs->state & MY_CS_UNICODE));
 
685
    }
 
686
  }
 
687
  String *val_str(String *);
 
688
  void fix_length_and_dec();
 
689
  const char *func_name() const { return "convert"; }
 
690
  virtual void print(String *str, enum_query_type query_type);
 
691
};
 
692
 
 
693
class Item_func_set_collation :public Item_str_func
 
694
{
 
695
public:
 
696
  Item_func_set_collation(Item *a, Item *b) :Item_str_func(a,b) {};
 
697
  String *val_str(String *);
 
698
  void fix_length_and_dec();
 
699
  bool eq(const Item *item, bool binary_cmp) const;
 
700
  const char *func_name() const { return "collate"; }
 
701
  enum Functype functype() const { return COLLATE_FUNC; }
 
702
  virtual void print(String *str, enum_query_type query_type);
 
703
  Item_field *filed_for_view_update()
 
704
  {
 
705
    /* this function is transparent for view updating */
 
706
    return args[0]->filed_for_view_update();
 
707
  }
 
708
};
 
709
 
 
710
class Item_func_charset :public Item_str_func
 
711
{
 
712
public:
 
713
  Item_func_charset(Item *a) :Item_str_func(a) {}
 
714
  String *val_str(String *);
 
715
  const char *func_name() const { return "charset"; }
 
716
  void fix_length_and_dec()
 
717
  {
 
718
     collation.set(system_charset_info);
 
719
     max_length= 64 * collation.collation->mbmaxlen; // should be enough
 
720
     maybe_null= 0;
 
721
  };
 
722
  table_map not_null_tables() const { return 0; }
 
723
};
 
724
 
 
725
class Item_func_collation :public Item_str_func
 
726
{
 
727
public:
 
728
  Item_func_collation(Item *a) :Item_str_func(a) {}
 
729
  String *val_str(String *);
 
730
  const char *func_name() const { return "collation"; }
 
731
  void fix_length_and_dec()
 
732
  {
 
733
     collation.set(system_charset_info);
 
734
     max_length= 64 * collation.collation->mbmaxlen; // should be enough
 
735
     maybe_null= 0;
 
736
  };
 
737
  table_map not_null_tables() const { return 0; }
 
738
};
 
739
 
 
740
 
 
741
class Item_func_weight_string :public Item_str_func
 
742
{
 
743
  String tmp_value;
 
744
  uint flags;
 
745
  uint nweights;
 
746
public:
 
747
  Item_func_weight_string(Item *a, uint nweights_arg, uint flags_arg)
 
748
  :Item_str_func(a) { nweights= nweights_arg; flags= flags_arg; }
 
749
  const char *func_name() const { return "weight_string"; }
 
750
  String *val_str(String *);
 
751
  void fix_length_and_dec();
 
752
};
 
753
 
 
754
 
 
755
class Item_func_crc32 :public Item_int_func
 
756
{
 
757
  String value;
 
758
public:
 
759
  Item_func_crc32(Item *a) :Item_int_func(a) { unsigned_flag= 1; }
 
760
  const char *func_name() const { return "crc32"; }
 
761
  void fix_length_and_dec() { max_length=10; }
 
762
  longlong val_int();
 
763
};
 
764
 
 
765
class Item_func_uncompressed_length : public Item_int_func
 
766
{
 
767
  String value;
 
768
public:
 
769
  Item_func_uncompressed_length(Item *a):Item_int_func(a){}
 
770
  const char *func_name() const{return "uncompressed_length";}
 
771
  void fix_length_and_dec() { max_length=10; }
 
772
  longlong val_int();
 
773
};
 
774
 
 
775
#ifdef HAVE_COMPRESS
 
776
#define ZLIB_DEPENDED_FUNCTION ;
 
777
#else
 
778
#define ZLIB_DEPENDED_FUNCTION { null_value=1; return 0; }
 
779
#endif
 
780
 
 
781
class Item_func_compress: public Item_str_func
 
782
{
 
783
  String buffer;
 
784
public:
 
785
  Item_func_compress(Item *a):Item_str_func(a){}
 
786
  void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;}
 
787
  const char *func_name() const{return "compress";}
 
788
  String *val_str(String *) ZLIB_DEPENDED_FUNCTION
 
789
};
 
790
 
 
791
class Item_func_uncompress: public Item_str_func
 
792
{
 
793
  String buffer;
 
794
public:
 
795
  Item_func_uncompress(Item *a): Item_str_func(a){}
 
796
  void fix_length_and_dec(){ maybe_null= 1; max_length= MAX_BLOB_WIDTH; }
 
797
  const char *func_name() const{return "uncompress";}
 
798
  String *val_str(String *) ZLIB_DEPENDED_FUNCTION
 
799
};
 
800
 
 
801
#define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
 
802
class Item_func_uuid: public Item_str_func
 
803
{
 
804
public:
 
805
  Item_func_uuid(): Item_str_func() {}
 
806
  void fix_length_and_dec() {
 
807
    collation.set(system_charset_info);
 
808
    /*
 
809
       NOTE! uuid() should be changed to use 'ascii'
 
810
       charset when hex(), format(), md5(), etc, and implicit
 
811
       number-to-string conversion will use 'ascii'
 
812
    */
 
813
    max_length= UUID_LENGTH * system_charset_info->mbmaxlen;
 
814
  }
 
815
  const char *func_name() const{ return "uuid"; }
 
816
  String *val_str(String *);
 
817
};
 
818