~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item_strfunc.h

Merge/fix in FAQ.

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 */
42
38
  bool fix_fields(THD *thd, Item **ref);
43
39
};
44
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
 
45
72
 
46
73
class Item_func_concat :public Item_str_func
47
74
{
103
130
class Item_str_conv :public Item_str_func
104
131
{
105
132
protected:
106
 
  uint32_t multiply;
 
133
  uint multiply;
107
134
  my_charset_conv_case converter;
108
135
  String tmp_value;
109
136
public:
212
239
};
213
240
 
214
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
 
215
326
class Item_func_sysconst :public Item_str_func
216
327
{
217
328
public:
218
329
  Item_func_sysconst()
219
330
  { collation.set(system_charset_info,DERIVATION_SYSCONST); }
220
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
331
  Item *safe_charset_converter(CHARSET_INFO *tocs);
221
332
  /*
222
333
    Used to create correct Item name in new converted item in
223
334
    safe_charset_converter, return string representation of this function
266
377
  const char *func_name() const { return "user"; }
267
378
  const char *fully_qualified_func_name() const { return "user()"; }
268
379
  int save_in_field(Field *field,
269
 
                    bool no_conversions __attribute__((unused)))
 
380
                    bool no_conversions __attribute__((__unused__)))
270
381
  {
271
382
    return save_str_value_in_field(field, &str_value);
272
383
  }
329
440
  void update_used_tables();
330
441
  const char *func_name() const { return "make_set"; }
331
442
 
332
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
 
443
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
333
444
  {
334
445
    return item->walk(processor, walk_subquery, arg) ||
335
446
      Item_str_func::walk(processor, walk_subquery, arg);
336
447
  }
337
 
  Item *transform(Item_transformer transformer, unsigned char *arg);
 
448
  Item *transform(Item_transformer transformer, uchar *arg);
338
449
  virtual void print(String *str, enum_query_type query_type);
339
450
};
340
451
 
356
467
public:
357
468
  Item_func_char(List<Item> &list) :Item_str_func(list)
358
469
  { collation.set(&my_charset_bin); }
359
 
  Item_func_char(List<Item> &list, const CHARSET_INFO * const cs) :Item_str_func(list)
 
470
  Item_func_char(List<Item> &list, CHARSET_INFO *cs) :Item_str_func(list)
360
471
  { collation.set(cs); }  
361
472
  String *val_str(String *);
362
473
  void fix_length_and_dec() 
521
632
  bool use_cached_value;
522
633
public:
523
634
  bool safe;
524
 
  const CHARSET_INFO *conv_charset; // keep it public
525
 
  Item_func_conv_charset(Item *a, const CHARSET_INFO * const cs) :Item_str_func(a) 
 
635
  CHARSET_INFO *conv_charset; // keep it public
 
636
  Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a) 
526
637
  { conv_charset= cs; use_cached_value= 0; safe= 0; }
527
 
  Item_func_conv_charset(Item *a, const CHARSET_INFO * const cs, bool cache_if_const) 
 
638
  Item_func_conv_charset(Item *a, CHARSET_INFO *cs, bool cache_if_const) 
528
639
    :Item_str_func(a) 
529
640
  {
530
641
    assert(args[0]->fixed);
531
642
    conv_charset= cs;
532
643
    if (cache_if_const && args[0]->const_item())
533
644
    {
534
 
      uint32_t errors= 0;
 
645
      uint errors= 0;
535
646
      String tmp, *str= args[0]->val_str(&tmp);
536
647
      if (!str || str_value.copy(str->ptr(), str->length(),
537
648
                                 str->charset(), conv_charset, &errors))
610
721
class Item_func_weight_string :public Item_str_func
611
722
{
612
723
  String tmp_value;
613
 
  uint32_t flags;
614
 
  uint32_t nweights;
 
724
  uint flags;
 
725
  uint nweights;
615
726
public:
616
 
  Item_func_weight_string(Item *a, uint32_t nweights_arg, uint32_t flags_arg)
 
727
  Item_func_weight_string(Item *a, uint nweights_arg, uint flags_arg)
617
728
  :Item_str_func(a) { nweights= nweights_arg; flags= flags_arg; }
618
729
  const char *func_name() const { return "weight_string"; }
619
730
  String *val_str(String *);
620
731
  void fix_length_and_dec();
621
732
};
622
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
 
623
781
#define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
624
782
class Item_func_uuid: public Item_str_func
625
783
{