item_strfunc.h 22.3 KB
Newer Older
unknown's avatar
unknown committed
1
/* Copyright (C) 2000-2003 MySQL AB
2

unknown's avatar
unknown committed
3 4
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
unknown's avatar
unknown committed
5
   the Free Software Foundation; version 2 of the License.
6

unknown's avatar
unknown committed
7 8 9 10
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
11

unknown's avatar
unknown committed
12 13 14 15 16 17 18
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */


/* This file defines all string functions */

19
#ifdef USE_PRAGMA_INTERFACE
unknown's avatar
unknown committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33
#pragma interface			/* gcc class implementation */
#endif

class Item_str_func :public Item_func
{
public:
  Item_str_func() :Item_func() { decimals=NOT_FIXED_DEC; }
  Item_str_func(Item *a) :Item_func(a) {decimals=NOT_FIXED_DEC; }
  Item_str_func(Item *a,Item *b) :Item_func(a,b) { decimals=NOT_FIXED_DEC; }
  Item_str_func(Item *a,Item *b,Item *c) :Item_func(a,b,c) { decimals=NOT_FIXED_DEC; }
  Item_str_func(Item *a,Item *b,Item *c,Item *d) :Item_func(a,b,c,d) {decimals=NOT_FIXED_DEC; }
  Item_str_func(Item *a,Item *b,Item *c,Item *d, Item* e) :Item_func(a,b,c,d,e) {decimals=NOT_FIXED_DEC; }
  Item_str_func(List<Item> &list) :Item_func(list) {decimals=NOT_FIXED_DEC; }
  longlong val_int();
34
  double val_real();
35
  my_decimal *val_decimal(my_decimal *);
unknown's avatar
unknown committed
36 37
  enum Item_result result_type () const { return STRING_RESULT; }
  void left_right_max_length();
38
  String *check_well_formed_result(String *str);
unknown's avatar
unknown committed
39
  bool fix_fields(THD *thd, Item **ref);
unknown's avatar
unknown committed
40 41 42 43 44 45
};

class Item_func_md5 :public Item_str_func
{
  String tmp_value;
public:
46 47 48 49
  Item_func_md5(Item *a) :Item_str_func(a)
  {
    collation.set(&my_charset_bin);
  }
unknown's avatar
unknown committed
50 51 52 53 54
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "md5"; }
};

55

56 57 58
class Item_func_sha :public Item_str_func
{
public:
59 60 61 62
  Item_func_sha(Item *a) :Item_str_func(a)
  {
    collation.set(&my_charset_bin);
  }
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
  String *val_str(String *);    
  void fix_length_and_dec();      
  const char *func_name() const { return "sha"; }	
};

class Item_func_aes_encrypt :public Item_str_func
{
public:
  Item_func_aes_encrypt(Item *a, Item *b) :Item_str_func(a,b) {}
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "aes_encrypt"; }
};

class Item_func_aes_decrypt :public Item_str_func	
{
public:
  Item_func_aes_decrypt(Item *a, Item *b) :Item_str_func(a,b) {}
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "aes_decrypt"; }
};


unknown's avatar
unknown committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
class Item_func_concat :public Item_str_func
{
  String tmp_value;
public:
  Item_func_concat(List<Item> &list) :Item_str_func(list) {}
  Item_func_concat(Item *a,Item *b) :Item_str_func(a,b) {}
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "concat"; }
};

class Item_func_concat_ws :public Item_str_func
{
  String tmp_value;
public:
102
  Item_func_concat_ws(List<Item> &list) :Item_str_func(list) {}
unknown's avatar
unknown committed
103 104
  String *val_str(String *);
  void fix_length_and_dec();
105
  const char *func_name() const { return "concat_ws"; }
unknown's avatar
unknown committed
106
  table_map not_null_tables() const { return 0; }
unknown's avatar
unknown committed
107 108 109 110
};

class Item_func_reverse :public Item_str_func
{
unknown's avatar
unknown committed
111
  String tmp_value;
unknown's avatar
unknown committed
112 113 114 115
public:
  Item_func_reverse(Item *a) :Item_str_func(a) {}
  String *val_str(String *);
  void fix_length_and_dec();
116
  const char *func_name() const { return "reverse"; }
unknown's avatar
unknown committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
};


class Item_func_replace :public Item_str_func
{
  String tmp_value,tmp_value2;
public:
  Item_func_replace(Item *org,Item *find,Item *replace)
    :Item_str_func(org,find,replace) {}
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "replace"; }
};


class Item_func_insert :public Item_str_func
{
  String tmp_value;
public:
  Item_func_insert(Item *org,Item *start,Item *length,Item *new_str)
    :Item_str_func(org,start,length,new_str) {}
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "insert"; }
};


class Item_str_conv :public Item_str_func
{
146 147
protected:
  uint multiply;
148 149
  size_t (*converter)(CHARSET_INFO *cs, char *src, size_t srclen,
                      char *dst, size_t dstlen);
150
  String tmp_value;
unknown's avatar
unknown committed
151 152
public:
  Item_str_conv(Item *item) :Item_str_func(item) {}
153
  String *val_str(String *);
unknown's avatar
unknown committed
154 155 156 157 158 159 160 161
};


class Item_func_lcase :public Item_str_conv
{
public:
  Item_func_lcase(Item *item) :Item_str_conv(item) {}
  const char *func_name() const { return "lcase"; }
162 163 164 165 166 167 168
  void fix_length_and_dec()
  {
    collation.set(args[0]->collation);
    multiply= collation.collation->casedn_multiply;
    converter= collation.collation->cset->casedn;
    max_length= args[0]->max_length * multiply;
  }
unknown's avatar
unknown committed
169 170 171 172 173 174 175
};

class Item_func_ucase :public Item_str_conv
{
public:
  Item_func_ucase(Item *item) :Item_str_conv(item) {}
  const char *func_name() const { return "ucase"; }
176 177 178 179 180 181 182
  void fix_length_and_dec()
  {
    collation.set(args[0]->collation);
    multiply= collation.collation->caseup_multiply;
    converter= collation.collation->cset->caseup;
    max_length= args[0]->max_length * multiply;
  }
unknown's avatar
unknown committed
183 184 185 186 187
};


class Item_func_left :public Item_str_func
{
188
  String tmp_value;
unknown's avatar
unknown committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
public:
  Item_func_left(Item *a,Item *b) :Item_str_func(a,b) {}
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "left"; }
};


class Item_func_right :public Item_str_func
{
  String tmp_value;
public:
  Item_func_right(Item *a,Item *b) :Item_str_func(a,b) {}
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "right"; }
};


class Item_func_substr :public Item_str_func
{
  String tmp_value;
public:
  Item_func_substr(Item *a,Item *b) :Item_str_func(a,b) {}
  Item_func_substr(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {}
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "substr"; }
};


class Item_func_substr_index :public Item_str_func
{
  String tmp_value;
public:
  Item_func_substr_index(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {}
  String *val_str(String *);
226
  void fix_length_and_dec();
227
  const char *func_name() const { return "substring_index"; }
unknown's avatar
unknown committed
228 229 230
};


231
class Item_func_trim :public Item_str_func
unknown's avatar
unknown committed
232
{
233
protected:
unknown's avatar
unknown committed
234
  String tmp_value;
235
  String remove;
unknown's avatar
unknown committed
236
public:
237 238
  Item_func_trim(Item *a,Item *b) :Item_str_func(a,b) {}
  Item_func_trim(Item *a) :Item_str_func(a) {}
unknown's avatar
unknown committed
239
  String *val_str(String *);
240 241
  void fix_length_and_dec();
  const char *func_name() const { return "trim"; }
242 243
  void print(String *str);
  virtual const char *mode_name() const { return "both"; }
unknown's avatar
unknown committed
244 245 246
};


247
class Item_func_ltrim :public Item_func_trim
unknown's avatar
unknown committed
248 249
{
public:
250 251
  Item_func_ltrim(Item *a,Item *b) :Item_func_trim(a,b) {}
  Item_func_ltrim(Item *a) :Item_func_trim(a) {}
unknown's avatar
unknown committed
252
  String *val_str(String *);
253
  const char *func_name() const { return "ltrim"; }
254
  const char *mode_name() const { return "leading"; }
unknown's avatar
unknown committed
255 256
};

257 258

class Item_func_rtrim :public Item_func_trim
unknown's avatar
unknown committed
259 260
{
public:
261 262
  Item_func_rtrim(Item *a,Item *b) :Item_func_trim(a,b) {}
  Item_func_rtrim(Item *a) :Item_func_trim(a) {}
unknown's avatar
unknown committed
263
  String *val_str(String *);
264
  const char *func_name() const { return "rtrim"; }
265
  const char *mode_name() const { return "trailing"; }
unknown's avatar
unknown committed
266 267 268
};


269 270 271 272 273
/*
  Item_func_password -- new (4.1.1) PASSWORD() function implementation.
  Returns strcat('*', octet2hex(sha1(sha1(password)))). '*' stands for new
  password format, sha1(sha1(password) is so-called hash_stage2 value.
  Length of returned string is always 41 byte. To find out how entire
274
  authentication procedure works, see comments in password.c.
275 276
*/

unknown's avatar
unknown committed
277 278
class Item_func_password :public Item_str_func
{
279
  char tmp_value[SCRAMBLED_PASSWORD_CHAR_LENGTH+1]; 
unknown's avatar
unknown committed
280 281
public:
  Item_func_password(Item *a) :Item_str_func(a) {}
282 283
  String *val_str(String *str);
  void fix_length_and_dec() { max_length= SCRAMBLED_PASSWORD_CHAR_LENGTH; }
unknown's avatar
unknown committed
284
  const char *func_name() const { return "password"; }
unknown's avatar
unknown committed
285
  static char *alloc(THD *thd, const char *password);
unknown's avatar
unknown committed
286 287
};

288

289 290 291
/*
  Item_func_old_password -- PASSWORD() implementation used in MySQL 3.21 - 4.0
  compatibility mode. This item is created in sql_yacc.yy when
292
  'old_passwords' session variable is set, and to handle OLD_PASSWORD()
293 294 295
  function.
*/

296 297
class Item_func_old_password :public Item_str_func
{
298
  char tmp_value[SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1];
299 300
public:
  Item_func_old_password(Item *a) :Item_str_func(a) {}
301 302
  String *val_str(String *str);
  void fix_length_and_dec() { max_length= SCRAMBLED_PASSWORD_CHAR_LENGTH_323; } 
303
  const char *func_name() const { return "old_password"; }
unknown's avatar
unknown committed
304
  static char *alloc(THD *thd, const char *password);
305 306 307
};


308 309 310 311 312 313 314
class Item_func_des_encrypt :public Item_str_func
{
  String tmp_value;
public:
  Item_func_des_encrypt(Item *a) :Item_str_func(a) {}
  Item_func_des_encrypt(Item *a, Item *b): Item_str_func(a,b) {}
  String *val_str(String *);
unknown's avatar
unknown committed
315 316
  void fix_length_and_dec()
  { maybe_null=1; max_length = args[0]->max_length+8; }
317
  const char *func_name() const { return "des_encrypt"; }
318 319 320 321 322 323 324 325 326
};

class Item_func_des_decrypt :public Item_str_func
{
  String tmp_value;
public:
  Item_func_des_decrypt(Item *a) :Item_str_func(a) {}
  Item_func_des_decrypt(Item *a, Item *b): Item_str_func(a,b) {}
  String *val_str(String *);
327
  void fix_length_and_dec() { maybe_null=1; max_length = args[0]->max_length; }
328
  const char *func_name() const { return "des_decrypt"; }
329 330
};

unknown's avatar
unknown committed
331 332 333
class Item_func_encrypt :public Item_str_func
{
  String tmp_value;
334 335 336 337 338 339

  /* Encapsulate common constructor actions */
  void constructor_helper()
  {
    collation.set(&my_charset_bin);
  }
unknown's avatar
unknown committed
340
public:
341 342 343 344 345 346 347 348
  Item_func_encrypt(Item *a) :Item_str_func(a)
  {
    constructor_helper();
  }
  Item_func_encrypt(Item *a, Item *b): Item_str_func(a,b)
  {
    constructor_helper();
  }
unknown's avatar
unknown committed
349 350
  String *val_str(String *);
  void fix_length_and_dec() { maybe_null=1; max_length = 13; }
unknown's avatar
unknown committed
351
  const char *func_name() const { return "encrypt"; }
unknown's avatar
unknown committed
352 353 354 355
};

#include "sql_crypt.h"

356

unknown's avatar
unknown committed
357 358 359
class Item_func_encode :public Item_str_func
{
public:
360 361
  Item_func_encode(Item *a, Item *seed):
    Item_str_func(a, seed) {}
unknown's avatar
unknown committed
362 363
  String *val_str(String *);
  void fix_length_and_dec();
364
  const char *func_name() const { return "encode"; }
unknown's avatar
unknown committed
365 366
};

367

unknown's avatar
unknown committed
368 369 370
class Item_func_decode :public Item_func_encode
{
public:
371
  Item_func_decode(Item *a, Item *seed): Item_func_encode(a, seed) {}
unknown's avatar
unknown committed
372
  String *val_str(String *);
373
  const char *func_name() const { return "decode"; }
unknown's avatar
unknown committed
374 375 376
};


377
class Item_func_sysconst :public Item_str_func
unknown's avatar
unknown committed
378 379
{
public:
380 381 382
  Item_func_sysconst()
  { collation.set(system_charset_info,DERIVATION_SYSCONST); }
  Item *safe_charset_converter(CHARSET_INFO *tocs);
383 384 385 386 387 388
  /*
    Used to create correct Item name in new converted item in
    safe_charset_converter, return string representation of this function
    call
  */
  virtual const char *fully_qualified_func_name() const = 0;
389 390
};

391

392 393 394 395
class Item_func_database :public Item_func_sysconst
{
public:
  Item_func_database() :Item_func_sysconst() {}
unknown's avatar
unknown committed
396
  String *val_str(String *);
unknown's avatar
unknown committed
397 398
  void fix_length_and_dec()
  {
399
    max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen;
unknown's avatar
unknown committed
400
    maybe_null=1;
401
  }
unknown's avatar
unknown committed
402
  const char *func_name() const { return "database"; }
403
  const char *fully_qualified_func_name() const { return "database()"; }
unknown's avatar
unknown committed
404 405
};

406

407
class Item_func_user :public Item_func_sysconst
unknown's avatar
unknown committed
408
{
409 410
protected:
  bool init (const char *user, const char *host);
411

unknown's avatar
unknown committed
412
public:
413 414 415 416 417 418 419 420 421 422
  Item_func_user()
  {
    str_value.set("", 0, system_charset_info);
  }
  String *val_str(String *)
  {
    DBUG_ASSERT(fixed == 1);
    return (null_value ? 0 : &str_value);
  }
  bool fix_fields(THD *thd, Item **ref);
423 424
  void fix_length_and_dec()
  {
425 426
    max_length= (USERNAME_LENGTH +
                 (HOSTNAME_LENGTH + 1) * SYSTEM_CHARSET_MBMAXLEN);
427
  }
428 429
  const char *func_name() const { return "user"; }
  const char *fully_qualified_func_name() const { return "user()"; }
430 431 432 433
  int save_in_field(Field *field, bool no_conversions)
  {
    return save_str_value_in_field(field, &str_value);
  }
434 435 436 437 438 439 440 441 442 443 444 445 446
};


class Item_func_current_user :public Item_func_user
{
  Name_resolution_context *context;

public:
  Item_func_current_user(Name_resolution_context *context_arg)
    : context(context_arg) {}
  bool fix_fields(THD *thd, Item **ref);
  const char *func_name() const { return "current_user"; }
  const char *fully_qualified_func_name() const { return "current_user()"; }
unknown's avatar
unknown committed
447 448 449 450 451
};


class Item_func_soundex :public Item_str_func
{
unknown's avatar
unknown committed
452
  String tmp_value;
unknown's avatar
unknown committed
453 454 455 456 457 458 459 460 461 462 463
public:
  Item_func_soundex(Item *a) :Item_str_func(a) {}
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "soundex"; }
};


class Item_func_elt :public Item_str_func
{
public:
464
  Item_func_elt(List<Item> &list) :Item_str_func(list) {}
465
  double val_real();
unknown's avatar
unknown committed
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
  longlong val_int();
  String *val_str(String *str);
  void fix_length_and_dec();
  const char *func_name() const { return "elt"; }
};


class Item_func_make_set :public Item_str_func
{
  Item *item;
  String tmp_str;

public:
  Item_func_make_set(Item *a,List<Item> &list) :Item_str_func(list),item(a) {}
  String *val_str(String *str);
481
  bool fix_fields(THD *thd, Item **ref)
unknown's avatar
unknown committed
482
  {
483
    DBUG_ASSERT(fixed == 0);
484
    return ((!item->fixed && item->fix_fields(thd, &item)) ||
unknown's avatar
unknown committed
485
	    item->check_cols(1) ||
486
	    Item_func::fix_fields(thd, ref));
unknown's avatar
unknown committed
487
  }
488
  void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
unknown's avatar
unknown committed
489 490 491
  void fix_length_and_dec();
  void update_used_tables();
  const char *func_name() const { return "make_set"; }
unknown's avatar
unknown committed
492

493
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
unknown's avatar
unknown committed
494
  {
495 496
    return item->walk(processor, walk_subquery, arg) ||
      Item_str_func::walk(processor, walk_subquery, arg);
unknown's avatar
unknown committed
497
  }
498
  Item *transform(Item_transformer transformer, uchar *arg);
499
  void print(String *str);
unknown's avatar
unknown committed
500 501 502 503 504 505 506
};


class Item_func_format :public Item_str_func
{
  String tmp_str;
public:
507
  Item_func_format(Item *org, Item *dec);
unknown's avatar
unknown committed
508
  String *val_str(String *);
509
  void fix_length_and_dec();
unknown's avatar
unknown committed
510
  const char *func_name() const { return "format"; }
511
  void print(String *);
unknown's avatar
unknown committed
512 513 514 515 516 517
};


class Item_func_char :public Item_str_func
{
public:
518 519 520 521
  Item_func_char(List<Item> &list) :Item_str_func(list)
  { collation.set(&my_charset_bin); }
  Item_func_char(List<Item> &list, CHARSET_INFO *cs) :Item_str_func(list)
  { collation.set(cs); }  
unknown's avatar
unknown committed
522
  String *val_str(String *);
523
  void fix_length_and_dec() 
unknown's avatar
unknown committed
524 525
  {
    max_length= arg_count * collation.collation->mbmaxlen;
526
  }
unknown's avatar
unknown committed
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
  const char *func_name() const { return "char"; }
};


class Item_func_repeat :public Item_str_func
{
  String tmp_value;
public:
  Item_func_repeat(Item *arg1,Item *arg2) :Item_str_func(arg1,arg2) {}
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "repeat"; }
};


class Item_func_rpad :public Item_str_func
{
544
  String tmp_value, rpad_str;
unknown's avatar
unknown committed
545 546 547 548 549 550 551 552 553 554 555
public:
  Item_func_rpad(Item *arg1,Item *arg2,Item *arg3)
    :Item_str_func(arg1,arg2,arg3) {}
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "rpad"; }
};


class Item_func_lpad :public Item_str_func
{
556
  String tmp_value, lpad_str;
unknown's avatar
unknown committed
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
public:
  Item_func_lpad(Item *arg1,Item *arg2,Item *arg3)
    :Item_str_func(arg1,arg2,arg3) {}
  String *val_str(String *);
  void fix_length_and_dec();
  const char *func_name() const { return "lpad"; }
};


class Item_func_conv :public Item_str_func
{
public:
  Item_func_conv(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {}
  const char *func_name() const { return "conv"; }
  String *val_str(String *);
unknown's avatar
unknown committed
572 573
  void fix_length_and_dec()
  {
574
    collation.set(default_charset());
575
    max_length= 64;
576
  }
unknown's avatar
unknown committed
577 578
};

unknown's avatar
unknown committed
579 580 581 582 583 584 585 586

class Item_func_hex :public Item_str_func
{
  String tmp_value;
public:
  Item_func_hex(Item *a) :Item_str_func(a) {}
  const char *func_name() const { return "hex"; }
  String *val_str(String *);
unknown's avatar
unknown committed
587 588
  void fix_length_and_dec()
  {
589
    collation.set(default_charset());
unknown's avatar
unknown committed
590 591
    decimals=0;
    max_length=args[0]->max_length*2*collation.collation->mbmaxlen;
592
  }
unknown's avatar
unknown committed
593 594
};

unknown's avatar
unknown committed
595 596 597 598
class Item_func_unhex :public Item_str_func
{
  String tmp_value;
public:
599 600 601 602 603
  Item_func_unhex(Item *a) :Item_str_func(a) 
  { 
    /* there can be bad hex strings */
    maybe_null= 1; 
  }
unknown's avatar
unknown committed
604 605 606 607 608 609 610 611 612 613
  const char *func_name() const { return "unhex"; }
  String *val_str(String *);
  void fix_length_and_dec()
  {
    collation.set(&my_charset_bin);
    decimals=0;
    max_length=(1+args[0]->max_length)/2;
  }
};

unknown's avatar
unknown committed
614

unknown's avatar
unknown committed
615 616 617 618
class Item_func_binary :public Item_str_func
{
public:
  Item_func_binary(Item *a) :Item_str_func(a) {}
619
  String *val_str(String *a)
unknown's avatar
unknown committed
620
  {
621
    DBUG_ASSERT(fixed == 1);
unknown's avatar
unknown committed
622 623
    String *tmp=args[0]->val_str(a);
    null_value=args[0]->null_value;
624 625
    if (tmp)
      tmp->set_charset(&my_charset_bin);
unknown's avatar
unknown committed
626
    return tmp;
unknown's avatar
unknown committed
627
  }
unknown's avatar
unknown committed
628 629 630 631
  void fix_length_and_dec()
  {
    collation.set(&my_charset_bin);
    max_length=args[0]->max_length;
632
  }
633
  void print(String *str);
634
  const char *func_name() const { return "cast_as_binary"; }
unknown's avatar
unknown committed
635 636 637 638 639 640 641 642 643 644 645
};


class Item_load_file :public Item_str_func
{
  String tmp_value;
public:
  Item_load_file(Item *a) :Item_str_func(a) {}
  String *val_str(String *);
  const char *func_name() const { return "load_file"; }
  void fix_length_and_dec()
unknown's avatar
unknown committed
646
  {
647
    collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
unknown's avatar
unknown committed
648
    maybe_null=1;
649 650
    max_length=MAX_BLOB_WIDTH;
  }
unknown's avatar
unknown committed
651 652 653 654 655 656 657 658 659 660 661 662 663 664
};


class Item_func_export_set: public Item_str_func
{
 public:
  Item_func_export_set(Item *a,Item *b,Item* c) :Item_str_func(a,b,c) {}
  Item_func_export_set(Item *a,Item *b,Item* c,Item* d) :Item_str_func(a,b,c,d) {}
  Item_func_export_set(Item *a,Item *b,Item* c,Item* d,Item* e) :Item_str_func(a,b,c,d,e) {}
  String  *val_str(String *str);
  void fix_length_and_dec();
  const char *func_name() const { return "export_set"; }
};

unknown's avatar
unknown committed
665
class Item_func_inet_ntoa : public Item_str_func
unknown's avatar
unknown committed
666 667 668 669 670 671 672 673 674
{
public:
  Item_func_inet_ntoa(Item *a) :Item_str_func(a)
    {
    }
  String* val_str(String* str);
  const char *func_name() const { return "inet_ntoa"; }
  void fix_length_and_dec() { decimals = 0; max_length=3*8+7; }
};
unknown's avatar
unknown committed
675 676 677

class Item_func_quote :public Item_str_func
{
678
  String tmp_value;
unknown's avatar
unknown committed
679 680 681 682
public:
  Item_func_quote(Item *a) :Item_str_func(a) {}
  const char *func_name() const { return "quote"; }
  String *val_str(String *);
unknown's avatar
unknown committed
683 684
  void fix_length_and_dec()
  {
685
    collation.set(args[0]->collation);
unknown's avatar
unknown committed
686
    max_length= args[0]->max_length * 2 + 2;
687
  }
unknown's avatar
unknown committed
688
};
unknown's avatar
unknown committed
689

690 691
class Item_func_conv_charset :public Item_str_func
{
692
  bool use_cached_value;
693
public:
694
  bool safe;
695
  CHARSET_INFO *conv_charset; // keep it public
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
  Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a) 
  { conv_charset= cs; use_cached_value= 0; safe= 0; }
  Item_func_conv_charset(Item *a, CHARSET_INFO *cs, bool cache_if_const) 
    :Item_str_func(a) 
  {
    DBUG_ASSERT(args[0]->fixed);
    conv_charset= cs;
    if (cache_if_const && args[0]->const_item())
    {
      uint errors= 0;
      String tmp, *str= args[0]->val_str(&tmp);
      if (!str || str_value.copy(str->ptr(), str->length(),
                                 str->charset(), conv_charset, &errors))
        null_value= 1;
      use_cached_value= 1;
711
      str_value.mark_as_const();
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
      safe= (errors == 0);
    }
    else
    {
      use_cached_value= 0;
      /*
        Conversion from and to "binary" is safe.
        Conversion to Unicode is safe.
        Other kind of conversions are potentially lossy.
      */
      safe= (args[0]->collation.collation == &my_charset_bin ||
             cs == &my_charset_bin ||
             (cs->state & MY_CS_UNICODE));
    }
  }
727 728
  String *val_str(String *);
  void fix_length_and_dec();
729 730
  const char *func_name() const { return "convert"; }
  void print(String *str);
731 732
};

unknown's avatar
unknown committed
733 734 735
class Item_func_set_collation :public Item_str_func
{
public:
unknown's avatar
unknown committed
736
  Item_func_set_collation(Item *a, Item *b) :Item_str_func(a,b) {};
unknown's avatar
unknown committed
737
  String *val_str(String *);
738
  void fix_length_and_dec();
739
  bool eq(const Item *item, bool binary_cmp) const;
740
  const char *func_name() const { return "collate"; }
741
  enum Functype functype() const { return COLLATE_FUNC; }
742
  void print(String *str);
743 744 745 746 747
  Item_field *filed_for_view_update()
  {
    /* this function is transparent for view updating */
    return args[0]->filed_for_view_update();
  }
unknown's avatar
unknown committed
748 749
};

unknown's avatar
unknown committed
750 751 752 753 754 755
class Item_func_charset :public Item_str_func
{
public:
  Item_func_charset(Item *a) :Item_str_func(a) {}
  String *val_str(String *);
  const char *func_name() const { return "charset"; }
unknown's avatar
unknown committed
756
  void fix_length_and_dec()
unknown's avatar
unknown committed
757
  {
758
     collation.set(system_charset_info);
759
     max_length= 64 * collation.collation->mbmaxlen; // should be enough
760
     maybe_null= 0;
unknown's avatar
unknown committed
761
  };
762
  table_map not_null_tables() const { return 0; }
unknown's avatar
unknown committed
763 764
};

unknown's avatar
unknown committed
765 766 767 768 769 770
class Item_func_collation :public Item_str_func
{
public:
  Item_func_collation(Item *a) :Item_str_func(a) {}
  String *val_str(String *);
  const char *func_name() const { return "collation"; }
771
  void fix_length_and_dec()
unknown's avatar
unknown committed
772
  {
773
     collation.set(system_charset_info);
774
     max_length= 64 * collation.collation->mbmaxlen; // should be enough
775
     maybe_null= 0;
unknown's avatar
unknown committed
776
  };
777
  table_map not_null_tables() const { return 0; }
unknown's avatar
unknown committed
778
};
779

780 781 782 783
class Item_func_crc32 :public Item_int_func
{
  String value;
public:
unknown's avatar
unknown committed
784
  Item_func_crc32(Item *a) :Item_int_func(a) { unsigned_flag= 1; }
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
  const char *func_name() const { return "crc32"; }
  void fix_length_and_dec() { max_length=10; }
  longlong val_int();
};

class Item_func_uncompressed_length : public Item_int_func
{
  String value;
public:
  Item_func_uncompressed_length(Item *a):Item_int_func(a){}
  const char *func_name() const{return "uncompressed_length";}
  void fix_length_and_dec() { max_length=10; }
  longlong val_int();
};

800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
#ifdef HAVE_COMPRESS
#define ZLIB_DEPENDED_FUNCTION ;
#else
#define ZLIB_DEPENDED_FUNCTION { null_value=1; return 0; }
#endif

class Item_func_compress: public Item_str_func
{
  String buffer;
public:
  Item_func_compress(Item *a):Item_str_func(a){}
  void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;}
  const char *func_name() const{return "compress";}
  String *val_str(String *) ZLIB_DEPENDED_FUNCTION
};

class Item_func_uncompress: public Item_str_func
{
  String buffer;
public:
  Item_func_uncompress(Item *a): Item_str_func(a){}
821
  void fix_length_and_dec(){ maybe_null= 1; max_length= MAX_BLOB_WIDTH; }
822 823 824 825
  const char *func_name() const{return "uncompress";}
  String *val_str(String *) ZLIB_DEPENDED_FUNCTION
};

unknown's avatar
unknown committed
826 827 828 829 830
#define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
class Item_func_uuid: public Item_str_func
{
public:
  Item_func_uuid(): Item_str_func() {}
unknown's avatar
unknown committed
831 832
  void fix_length_and_dec() {
    collation.set(system_charset_info);
833 834 835 836 837 838
    /*
       NOTE! uuid() should be changed to use 'ascii'
       charset when hex(), format(), md5(), etc, and implicit
       number-to-string conversion will use 'ascii'
    */
    max_length= UUID_LENGTH * system_charset_info->mbmaxlen;
unknown's avatar
unknown committed
839
  }
unknown's avatar
unknown committed
840 841 842 843
  const char *func_name() const{ return "uuid"; }
  String *val_str(String *);
};