~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_strfunc.h

  • Committer: Brian Aker
  • Date: 2008-07-06 15:03:34 UTC
  • Revision ID: brian@tangent.org-20080706150334-xv3xa202trvs0712
USE_RAID cleanup, along with ftbench tools.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
/* 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 */
19
15
 
20
16
 
21
17
/* This file defines all string functions */
22
18
 
 
19
#ifdef USE_PRAGMA_INTERFACE
 
20
#pragma interface                       /* gcc class implementation */
 
21
#endif
23
22
 
24
23
class Item_str_func :public Item_func
25
24
{
31
30
  Item_str_func(Item *a,Item *b,Item *c,Item *d) :Item_func(a,b,c,d) {decimals=NOT_FIXED_DEC; }
32
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; }
33
32
  Item_str_func(List<Item> &list) :Item_func(list) {decimals=NOT_FIXED_DEC; }
34
 
  int64_t val_int();
 
33
  longlong val_int();
35
34
  double val_real();
36
35
  my_decimal *val_decimal(my_decimal *);
37
36
  enum Item_result result_type () const { return STRING_RESULT; }
39
38
  bool fix_fields(THD *thd, Item **ref);
40
39
};
41
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
 
42
72
 
43
73
class Item_func_concat :public Item_str_func
44
74
{
100
130
class Item_str_conv :public Item_str_func
101
131
{
102
132
protected:
103
 
  uint32_t multiply;
 
133
  uint multiply;
104
134
  my_charset_conv_case converter;
105
135
  String tmp_value;
106
136
public:
209
239
};
210
240
 
211
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
 
212
346
class Item_func_sysconst :public Item_str_func
213
347
{
214
348
public:
215
349
  Item_func_sysconst()
216
350
  { collation.set(system_charset_info,DERIVATION_SYSCONST); }
217
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
351
  Item *safe_charset_converter(CHARSET_INFO *tocs);
218
352
  /*
219
353
    Used to create correct Item name in new converted item in
220
354
    safe_charset_converter, return string representation of this function
221
355
    call
222
356
  */
223
357
  virtual const char *fully_qualified_func_name() const = 0;
224
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
225
 
  { return true; }
226
358
};
227
359
 
228
360
 
253
385
  }
254
386
  String *val_str(String *)
255
387
  {
256
 
    assert(fixed == 1);
 
388
    DBUG_ASSERT(fixed == 1);
257
389
    return (null_value ? 0 : &str_value);
258
390
  }
259
391
  bool fix_fields(THD *thd, Item **ref);
264
396
  }
265
397
  const char *func_name() const { return "user"; }
266
398
  const char *fully_qualified_func_name() const { return "user()"; }
267
 
  int save_in_field(Field *field,
268
 
                    bool no_conversions __attribute__((unused)))
 
399
  int save_in_field(Field *field, bool no_conversions)
269
400
  {
270
401
    return save_str_value_in_field(field, &str_value);
271
402
  }
301
432
public:
302
433
  Item_func_elt(List<Item> &list) :Item_str_func(list) {}
303
434
  double val_real();
304
 
  int64_t val_int();
 
435
  longlong val_int();
305
436
  String *val_str(String *str);
306
437
  void fix_length_and_dec();
307
438
  const char *func_name() const { return "elt"; }
318
449
  String *val_str(String *str);
319
450
  bool fix_fields(THD *thd, Item **ref)
320
451
  {
321
 
    assert(fixed == 0);
 
452
    DBUG_ASSERT(fixed == 0);
322
453
    return ((!item->fixed && item->fix_fields(thd, &item)) ||
323
454
            item->check_cols(1) ||
324
455
            Item_func::fix_fields(thd, ref));
328
459
  void update_used_tables();
329
460
  const char *func_name() const { return "make_set"; }
330
461
 
331
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
 
462
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
332
463
  {
333
464
    return item->walk(processor, walk_subquery, arg) ||
334
465
      Item_str_func::walk(processor, walk_subquery, arg);
335
466
  }
336
 
  Item *transform(Item_transformer transformer, unsigned char *arg);
 
467
  Item *transform(Item_transformer transformer, uchar *arg);
337
468
  virtual void print(String *str, enum_query_type query_type);
338
469
};
339
470
 
355
486
public:
356
487
  Item_func_char(List<Item> &list) :Item_str_func(list)
357
488
  { collation.set(&my_charset_bin); }
358
 
  Item_func_char(List<Item> &list, const CHARSET_INFO * const cs) :Item_str_func(list)
 
489
  Item_func_char(List<Item> &list, CHARSET_INFO *cs) :Item_str_func(list)
359
490
  { collation.set(cs); }  
360
491
  String *val_str(String *);
361
492
  void fix_length_and_dec() 
457
588
  Item_func_binary(Item *a) :Item_str_func(a) {}
458
589
  String *val_str(String *a)
459
590
  {
460
 
    assert(fixed == 1);
 
591
    DBUG_ASSERT(fixed == 1);
461
592
    String *tmp=args[0]->val_str(a);
462
593
    null_value=args[0]->null_value;
463
594
    if (tmp)
487
618
    maybe_null=1;
488
619
    max_length=MAX_BLOB_WIDTH;
489
620
  }
490
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
491
 
  { return true; }
492
621
};
493
622
 
494
623
 
522
651
  bool use_cached_value;
523
652
public:
524
653
  bool safe;
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) 
 
654
  CHARSET_INFO *conv_charset; // keep it public
 
655
  Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a) 
527
656
  { conv_charset= cs; use_cached_value= 0; safe= 0; }
528
 
  Item_func_conv_charset(Item *a, const CHARSET_INFO * const cs, bool cache_if_const) 
 
657
  Item_func_conv_charset(Item *a, CHARSET_INFO *cs, bool cache_if_const) 
529
658
    :Item_str_func(a) 
530
659
  {
531
 
    assert(args[0]->fixed);
 
660
    DBUG_ASSERT(args[0]->fixed);
532
661
    conv_charset= cs;
533
662
    if (cache_if_const && args[0]->const_item())
534
663
    {
535
 
      uint32_t errors= 0;
 
664
      uint errors= 0;
536
665
      String tmp, *str= args[0]->val_str(&tmp);
537
666
      if (!str || str_value.copy(str->ptr(), str->length(),
538
667
                                 str->charset(), conv_charset, &errors))
611
740
class Item_func_weight_string :public Item_str_func
612
741
{
613
742
  String tmp_value;
614
 
  uint32_t flags;
615
 
  uint32_t nweights;
 
743
  uint flags;
 
744
  uint nweights;
616
745
public:
617
 
  Item_func_weight_string(Item *a, uint32_t nweights_arg, uint32_t flags_arg)
 
746
  Item_func_weight_string(Item *a, uint nweights_arg, uint flags_arg)
618
747
  :Item_str_func(a) { nweights= nweights_arg; flags= flags_arg; }
619
748
  const char *func_name() const { return "weight_string"; }
620
749
  String *val_str(String *);
621
750
  void fix_length_and_dec();
622
 
  /*
623
 
    TODO: Currently this Item is not allowed for virtual columns
624
 
    only due to a bug in generating virtual column value.
625
 
  */
626
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
627
 
  { return true; }
 
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
628
798
};
629
799
 
630
800
#define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
643
813
  }
644
814
  const char *func_name() const{ return "uuid"; }
645
815
  String *val_str(String *);
646
 
  bool check_vcol_func_processor(unsigned char *int_arg __attribute__((unused)))
647
 
  { return true; }
648
816
};
649
817