~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item_strfunc.h

  • Committer: Jay Pipes
  • Date: 2008-07-17 18:48:58 UTC
  • mto: This revision was merged to the branch mainline in revision 182.
  • Revision ID: jay@mysql.com-20080717184858-2mbouxl8xi41gcge
Removed DBUG from CSV and Blackhole storage engines

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
  int64_t 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
class Item_func_des_encrypt :public Item_str_func
 
262
{
 
263
  String tmp_value;
 
264
public:
 
265
  String *val_str(String *);
 
266
  void fix_length_and_dec()
 
267
  { maybe_null=1; max_length = args[0]->max_length+8; }
 
268
  const char *func_name() const { return "des_encrypt"; }
 
269
};
 
270
 
 
271
class Item_func_des_decrypt :public Item_str_func
 
272
{
 
273
  String tmp_value;
 
274
public:
 
275
  String *val_str(String *);
 
276
  void fix_length_and_dec() { maybe_null=1; max_length = args[0]->max_length; }
 
277
  const char *func_name() const { return "des_decrypt"; }
 
278
};
 
279
 
 
280
class Item_func_encrypt :public Item_str_func
 
281
{
 
282
  String tmp_value;
 
283
 
 
284
  /* Encapsulate common constructor actions */
 
285
  void constructor_helper()
 
286
  {
 
287
    collation.set(&my_charset_bin);
 
288
  }
 
289
public:
 
290
  Item_func_encrypt(Item *a) :Item_str_func(a)
 
291
  {
 
292
    constructor_helper();
 
293
  }
 
294
  Item_func_encrypt(Item *a, Item *b): Item_str_func(a,b)
 
295
  {
 
296
    constructor_helper();
 
297
  }
 
298
  String *val_str(String *);
 
299
  void fix_length_and_dec() { maybe_null=1; max_length = 13; }
 
300
  const char *func_name() const { return "encrypt"; }
 
301
};
 
302
 
 
303
#include "sql_crypt.h"
 
304
 
 
305
 
 
306
class Item_func_encode :public Item_str_func
 
307
{
 
308
public:
 
309
  Item_func_encode(Item *a, Item *seed):
 
310
    Item_str_func(a, seed) {}
 
311
  String *val_str(String *);
 
312
  void fix_length_and_dec();
 
313
  const char *func_name() const { return "encode"; }
 
314
};
 
315
 
 
316
 
 
317
class Item_func_decode :public Item_func_encode
 
318
{
 
319
public:
 
320
  Item_func_decode(Item *a, Item *seed): Item_func_encode(a, seed) {}
 
321
  String *val_str(String *);
 
322
  const char *func_name() const { return "decode"; }
 
323
};
 
324
 
 
325
 
 
326
class Item_func_sysconst :public Item_str_func
 
327
{
 
328
public:
 
329
  Item_func_sysconst()
 
330
  { collation.set(system_charset_info,DERIVATION_SYSCONST); }
 
331
  Item *safe_charset_converter(CHARSET_INFO *tocs);
 
332
  /*
 
333
    Used to create correct Item name in new converted item in
 
334
    safe_charset_converter, return string representation of this function
 
335
    call
 
336
  */
 
337
  virtual const char *fully_qualified_func_name() const = 0;
 
338
};
 
339
 
 
340
 
 
341
class Item_func_database :public Item_func_sysconst
 
342
{
 
343
public:
 
344
  Item_func_database() :Item_func_sysconst() {}
 
345
  String *val_str(String *);
 
346
  void fix_length_and_dec()
 
347
  {
 
348
    max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen;
 
349
    maybe_null=1;
 
350
  }
 
351
  const char *func_name() const { return "database"; }
 
352
  const char *fully_qualified_func_name() const { return "database()"; }
 
353
};
 
354
 
 
355
 
 
356
class Item_func_user :public Item_func_sysconst
 
357
{
 
358
protected:
 
359
  bool init (const char *user, const char *host);
 
360
 
 
361
public:
 
362
  Item_func_user()
 
363
  {
 
364
    str_value.set("", 0, system_charset_info);
 
365
  }
 
366
  String *val_str(String *)
 
367
  {
 
368
    assert(fixed == 1);
 
369
    return (null_value ? 0 : &str_value);
 
370
  }
 
371
  bool fix_fields(THD *thd, Item **ref);
 
372
  void fix_length_and_dec()
 
373
  {
 
374
    max_length= (USERNAME_CHAR_LENGTH + HOSTNAME_LENGTH + 1) *
 
375
                system_charset_info->mbmaxlen;
 
376
  }
 
377
  const char *func_name() const { return "user"; }
 
378
  const char *fully_qualified_func_name() const { return "user()"; }
 
379
  int save_in_field(Field *field,
 
380
                    bool no_conversions __attribute__((__unused__)))
 
381
  {
 
382
    return save_str_value_in_field(field, &str_value);
 
383
  }
 
384
};
 
385
 
 
386
 
 
387
class Item_func_current_user :public Item_func_user
 
388
{
 
389
  Name_resolution_context *context;
 
390
 
 
391
public:
 
392
  Item_func_current_user(Name_resolution_context *context_arg)
 
393
    : context(context_arg) {}
 
394
  bool fix_fields(THD *thd, Item **ref);
 
395
  const char *func_name() const { return "current_user"; }
 
396
  const char *fully_qualified_func_name() const { return "current_user()"; }
 
397
};
 
398
 
 
399
 
 
400
class Item_func_soundex :public Item_str_func
 
401
{
 
402
  String tmp_value;
 
403
public:
 
404
  Item_func_soundex(Item *a) :Item_str_func(a) {}
 
405
  String *val_str(String *);
 
406
  void fix_length_and_dec();
 
407
  const char *func_name() const { return "soundex"; }
 
408
};
 
409
 
 
410
 
 
411
class Item_func_elt :public Item_str_func
 
412
{
 
413
public:
 
414
  Item_func_elt(List<Item> &list) :Item_str_func(list) {}
 
415
  double val_real();
 
416
  int64_t val_int();
 
417
  String *val_str(String *str);
 
418
  void fix_length_and_dec();
 
419
  const char *func_name() const { return "elt"; }
 
420
};
 
421
 
 
422
 
 
423
class Item_func_make_set :public Item_str_func
 
424
{
 
425
  Item *item;
 
426
  String tmp_str;
 
427
 
 
428
public:
 
429
  Item_func_make_set(Item *a,List<Item> &list) :Item_str_func(list),item(a) {}
 
430
  String *val_str(String *str);
 
431
  bool fix_fields(THD *thd, Item **ref)
 
432
  {
 
433
    assert(fixed == 0);
 
434
    return ((!item->fixed && item->fix_fields(thd, &item)) ||
 
435
            item->check_cols(1) ||
 
436
            Item_func::fix_fields(thd, ref));
 
437
  }
 
438
  void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
 
439
  void fix_length_and_dec();
 
440
  void update_used_tables();
 
441
  const char *func_name() const { return "make_set"; }
 
442
 
 
443
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
 
444
  {
 
445
    return item->walk(processor, walk_subquery, arg) ||
 
446
      Item_str_func::walk(processor, walk_subquery, arg);
 
447
  }
 
448
  Item *transform(Item_transformer transformer, uchar *arg);
 
449
  virtual void print(String *str, enum_query_type query_type);
 
450
};
 
451
 
 
452
 
 
453
class Item_func_format :public Item_str_func
 
454
{
 
455
  String tmp_str;
 
456
public:
 
457
  Item_func_format(Item *org, Item *dec);
 
458
  String *val_str(String *);
 
459
  void fix_length_and_dec();
 
460
  const char *func_name() const { return "format"; }
 
461
  virtual void print(String *str, enum_query_type query_type);
 
462
};
 
463
 
 
464
 
 
465
class Item_func_char :public Item_str_func
 
466
{
 
467
public:
 
468
  Item_func_char(List<Item> &list) :Item_str_func(list)
 
469
  { collation.set(&my_charset_bin); }
 
470
  Item_func_char(List<Item> &list, CHARSET_INFO *cs) :Item_str_func(list)
 
471
  { collation.set(cs); }  
 
472
  String *val_str(String *);
 
473
  void fix_length_and_dec() 
 
474
  {
 
475
    max_length= arg_count * 4;
 
476
  }
 
477
  const char *func_name() const { return "char"; }
 
478
};
 
479
 
 
480
 
 
481
class Item_func_repeat :public Item_str_func
 
482
{
 
483
  String tmp_value;
 
484
public:
 
485
  Item_func_repeat(Item *arg1,Item *arg2) :Item_str_func(arg1,arg2) {}
 
486
  String *val_str(String *);
 
487
  void fix_length_and_dec();
 
488
  const char *func_name() const { return "repeat"; }
 
489
};
 
490
 
 
491
 
 
492
class Item_func_rpad :public Item_str_func
 
493
{
 
494
  String tmp_value, rpad_str;
 
495
public:
 
496
  Item_func_rpad(Item *arg1,Item *arg2,Item *arg3)
 
497
    :Item_str_func(arg1,arg2,arg3) {}
 
498
  String *val_str(String *);
 
499
  void fix_length_and_dec();
 
500
  const char *func_name() const { return "rpad"; }
 
501
};
 
502
 
 
503
 
 
504
class Item_func_lpad :public Item_str_func
 
505
{
 
506
  String tmp_value, lpad_str;
 
507
public:
 
508
  Item_func_lpad(Item *arg1,Item *arg2,Item *arg3)
 
509
    :Item_str_func(arg1,arg2,arg3) {}
 
510
  String *val_str(String *);
 
511
  void fix_length_and_dec();
 
512
  const char *func_name() const { return "lpad"; }
 
513
};
 
514
 
 
515
 
 
516
class Item_func_conv :public Item_str_func
 
517
{
 
518
public:
 
519
  Item_func_conv(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {}
 
520
  const char *func_name() const { return "conv"; }
 
521
  String *val_str(String *);
 
522
  void fix_length_and_dec()
 
523
  {
 
524
    collation.set(default_charset());
 
525
    max_length=64;
 
526
    maybe_null= 1;
 
527
  }
 
528
};
 
529
 
 
530
 
 
531
class Item_func_hex :public Item_str_func
 
532
{
 
533
  String tmp_value;
 
534
public:
 
535
  Item_func_hex(Item *a) :Item_str_func(a) {}
 
536
  const char *func_name() const { return "hex"; }
 
537
  String *val_str(String *);
 
538
  void fix_length_and_dec()
 
539
  {
 
540
    collation.set(default_charset());
 
541
    decimals=0;
 
542
    max_length=args[0]->max_length*2*collation.collation->mbmaxlen;
 
543
  }
 
544
};
 
545
 
 
546
class Item_func_unhex :public Item_str_func
 
547
{
 
548
  String tmp_value;
 
549
public:
 
550
  Item_func_unhex(Item *a) :Item_str_func(a) 
 
551
  { 
 
552
    /* there can be bad hex strings */
 
553
    maybe_null= 1; 
 
554
  }
 
555
  const char *func_name() const { return "unhex"; }
 
556
  String *val_str(String *);
 
557
  void fix_length_and_dec()
 
558
  {
 
559
    collation.set(&my_charset_bin);
 
560
    decimals=0;
 
561
    max_length=(1+args[0]->max_length)/2;
 
562
  }
 
563
};
 
564
 
 
565
 
 
566
class Item_func_binary :public Item_str_func
 
567
{
 
568
public:
 
569
  Item_func_binary(Item *a) :Item_str_func(a) {}
 
570
  String *val_str(String *a)
 
571
  {
 
572
    assert(fixed == 1);
 
573
    String *tmp=args[0]->val_str(a);
 
574
    null_value=args[0]->null_value;
 
575
    if (tmp)
 
576
      tmp->set_charset(&my_charset_bin);
 
577
    return tmp;
 
578
  }
 
579
  void fix_length_and_dec()
 
580
  {
 
581
    collation.set(&my_charset_bin);
 
582
    max_length=args[0]->max_length;
 
583
  }
 
584
  virtual void print(String *str, enum_query_type query_type);
 
585
  const char *func_name() const { return "cast_as_binary"; }
 
586
};
 
587
 
 
588
 
 
589
class Item_load_file :public Item_str_func
 
590
{
 
591
  String tmp_value;
 
592
public:
 
593
  Item_load_file(Item *a) :Item_str_func(a) {}
 
594
  String *val_str(String *);
 
595
  const char *func_name() const { return "load_file"; }
 
596
  void fix_length_and_dec()
 
597
  {
 
598
    collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
 
599
    maybe_null=1;
 
600
    max_length=MAX_BLOB_WIDTH;
 
601
  }
 
602
};
 
603
 
 
604
 
 
605
class Item_func_export_set: public Item_str_func
 
606
{
 
607
 public:
 
608
  Item_func_export_set(Item *a,Item *b,Item* c) :Item_str_func(a,b,c) {}
 
609
  Item_func_export_set(Item *a,Item *b,Item* c,Item* d) :Item_str_func(a,b,c,d) {}
 
610
  Item_func_export_set(Item *a,Item *b,Item* c,Item* d,Item* e) :Item_str_func(a,b,c,d,e) {}
 
611
  String  *val_str(String *str);
 
612
  void fix_length_and_dec();
 
613
  const char *func_name() const { return "export_set"; }
 
614
};
 
615
 
 
616
class Item_func_quote :public Item_str_func
 
617
{
 
618
  String tmp_value;
 
619
public:
 
620
  Item_func_quote(Item *a) :Item_str_func(a) {}
 
621
  const char *func_name() const { return "quote"; }
 
622
  String *val_str(String *);
 
623
  void fix_length_and_dec()
 
624
  {
 
625
    collation.set(args[0]->collation);
 
626
    max_length= args[0]->max_length * 2 + 2;
 
627
  }
 
628
};
 
629
 
 
630
class Item_func_conv_charset :public Item_str_func
 
631
{
 
632
  bool use_cached_value;
 
633
public:
 
634
  bool safe;
 
635
  CHARSET_INFO *conv_charset; // keep it public
 
636
  Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a) 
 
637
  { conv_charset= cs; use_cached_value= 0; safe= 0; }
 
638
  Item_func_conv_charset(Item *a, CHARSET_INFO *cs, bool cache_if_const) 
 
639
    :Item_str_func(a) 
 
640
  {
 
641
    assert(args[0]->fixed);
 
642
    conv_charset= cs;
 
643
    if (cache_if_const && args[0]->const_item())
 
644
    {
 
645
      uint errors= 0;
 
646
      String tmp, *str= args[0]->val_str(&tmp);
 
647
      if (!str || str_value.copy(str->ptr(), str->length(),
 
648
                                 str->charset(), conv_charset, &errors))
 
649
        null_value= 1;
 
650
      use_cached_value= 1;
 
651
      str_value.mark_as_const();
 
652
      safe= (errors == 0);
 
653
    }
 
654
    else
 
655
    {
 
656
      use_cached_value= 0;
 
657
      /*
 
658
        Conversion from and to "binary" is safe.
 
659
        Conversion to Unicode is safe.
 
660
        Other kind of conversions are potentially lossy.
 
661
      */
 
662
      safe= (args[0]->collation.collation == &my_charset_bin ||
 
663
             cs == &my_charset_bin ||
 
664
             (cs->state & MY_CS_UNICODE));
 
665
    }
 
666
  }
 
667
  String *val_str(String *);
 
668
  void fix_length_and_dec();
 
669
  const char *func_name() const { return "convert"; }
 
670
  virtual void print(String *str, enum_query_type query_type);
 
671
};
 
672
 
 
673
class Item_func_set_collation :public Item_str_func
 
674
{
 
675
public:
 
676
  Item_func_set_collation(Item *a, Item *b) :Item_str_func(a,b) {};
 
677
  String *val_str(String *);
 
678
  void fix_length_and_dec();
 
679
  bool eq(const Item *item, bool binary_cmp) const;
 
680
  const char *func_name() const { return "collate"; }
 
681
  enum Functype functype() const { return COLLATE_FUNC; }
 
682
  virtual void print(String *str, enum_query_type query_type);
 
683
  Item_field *filed_for_view_update()
 
684
  {
 
685
    /* this function is transparent for view updating */
 
686
    return args[0]->filed_for_view_update();
 
687
  }
 
688
};
 
689
 
 
690
class Item_func_charset :public Item_str_func
 
691
{
 
692
public:
 
693
  Item_func_charset(Item *a) :Item_str_func(a) {}
 
694
  String *val_str(String *);
 
695
  const char *func_name() const { return "charset"; }
 
696
  void fix_length_and_dec()
 
697
  {
 
698
     collation.set(system_charset_info);
 
699
     max_length= 64 * collation.collation->mbmaxlen; // should be enough
 
700
     maybe_null= 0;
 
701
  };
 
702
  table_map not_null_tables() const { return 0; }
 
703
};
 
704
 
 
705
class Item_func_collation :public Item_str_func
 
706
{
 
707
public:
 
708
  Item_func_collation(Item *a) :Item_str_func(a) {}
 
709
  String *val_str(String *);
 
710
  const char *func_name() const { return "collation"; }
 
711
  void fix_length_and_dec()
 
712
  {
 
713
     collation.set(system_charset_info);
 
714
     max_length= 64 * collation.collation->mbmaxlen; // should be enough
 
715
     maybe_null= 0;
 
716
  };
 
717
  table_map not_null_tables() const { return 0; }
 
718
};
 
719
 
 
720
 
 
721
class Item_func_weight_string :public Item_str_func
 
722
{
 
723
  String tmp_value;
 
724
  uint flags;
 
725
  uint nweights;
 
726
public:
 
727
  Item_func_weight_string(Item *a, uint nweights_arg, uint flags_arg)
 
728
  :Item_str_func(a) { nweights= nweights_arg; flags= flags_arg; }
 
729
  const char *func_name() const { return "weight_string"; }
 
730
  String *val_str(String *);
 
731
  void fix_length_and_dec();
 
732
};
 
733
 
 
734
 
 
735
class Item_func_crc32 :public Item_int_func
 
736
{
 
737
  String value;
 
738
public:
 
739
  Item_func_crc32(Item *a) :Item_int_func(a) { unsigned_flag= 1; }
 
740
  const char *func_name() const { return "crc32"; }
 
741
  void fix_length_and_dec() { max_length=10; }
 
742
  int64_t val_int();
 
743
};
 
744
 
 
745
class Item_func_uncompressed_length : public Item_int_func
 
746
{
 
747
  String value;
 
748
public:
 
749
  Item_func_uncompressed_length(Item *a):Item_int_func(a){}
 
750
  const char *func_name() const{return "uncompressed_length";}
 
751
  void fix_length_and_dec() { max_length=10; }
 
752
  int64_t val_int();
 
753
};
 
754
 
 
755
#ifdef HAVE_COMPRESS
 
756
#define ZLIB_DEPENDED_FUNCTION ;
 
757
#else
 
758
#define ZLIB_DEPENDED_FUNCTION { null_value=1; return 0; }
 
759
#endif
 
760
 
 
761
class Item_func_compress: public Item_str_func
 
762
{
 
763
  String buffer;
 
764
public:
 
765
  Item_func_compress(Item *a):Item_str_func(a){}
 
766
  void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;}
 
767
  const char *func_name() const{return "compress";}
 
768
  String *val_str(String *) ZLIB_DEPENDED_FUNCTION
 
769
};
 
770
 
 
771
class Item_func_uncompress: public Item_str_func
 
772
{
 
773
  String buffer;
 
774
public:
 
775
  Item_func_uncompress(Item *a): Item_str_func(a){}
 
776
  void fix_length_and_dec(){ maybe_null= 1; max_length= MAX_BLOB_WIDTH; }
 
777
  const char *func_name() const{return "uncompress";}
 
778
  String *val_str(String *) ZLIB_DEPENDED_FUNCTION
 
779
};
 
780
 
 
781
#define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
 
782
class Item_func_uuid: public Item_str_func
 
783
{
 
784
public:
 
785
  Item_func_uuid(): Item_str_func() {}
 
786
  void fix_length_and_dec() {
 
787
    collation.set(system_charset_info);
 
788
    /*
 
789
       NOTE! uuid() should be changed to use 'ascii'
 
790
       charset when hex(), format(), md5(), etc, and implicit
 
791
       number-to-string conversion will use 'ascii'
 
792
    */
 
793
    max_length= UUID_LENGTH * system_charset_info->mbmaxlen;
 
794
  }
 
795
  const char *func_name() const{ return "uuid"; }
 
796
  String *val_str(String *);
 
797
};
 
798