item_func.h 34.7 KB
Newer Older
unknown's avatar
unknown committed
1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2

unknown's avatar
unknown committed
3 4 5 6
   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
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
7

unknown's avatar
unknown committed
8 9 10 11
   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.
12

unknown's avatar
unknown committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
   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 */


/* Function items used by mysql */

#ifdef __GNUC__
#pragma interface			/* gcc class implementation */
#endif

#ifdef HAVE_IEEEFP_H
extern "C"				/* Bug in BSDI include file */
{
#include <ieeefp.h>
}
#endif

class Item_func :public Item_result_field
{
protected:
34
  Item **args, *tmp_arg[2];
35 36 37 38
  /*
    Allowed numbers of columns in result (usually 1, which means scalar value)
    0 means get this number from first argument
  */
unknown's avatar
unknown committed
39
  uint allowed_arg_cols;
unknown's avatar
unknown committed
40 41
public:
  uint arg_count;
42
  table_map used_tables_cache, not_null_tables_cache;
unknown's avatar
unknown committed
43 44 45 46
  bool const_item_cache;
  enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
		  GE_FUNC,GT_FUNC,FT_FUNC,
		  LIKE_FUNC,NOTLIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
47 48
		  COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC,
                  BETWEEN, IN_FUNC, MULT_EQUAL_FUNC,
49
		  INTERVAL_FUNC, ISNOTNULLTEST_FUNC,
unknown's avatar
unknown committed
50 51 52 53
		  SP_EQUALS_FUNC, SP_DISJOINT_FUNC,SP_INTERSECTS_FUNC,
		  SP_TOUCHES_FUNC,SP_CROSSES_FUNC,SP_WITHIN_FUNC,
		  SP_CONTAINS_FUNC,SP_OVERLAPS_FUNC,
		  SP_STARTPOINT,SP_ENDPOINT,SP_EXTERIORRING,
54
		  SP_POINTN,SP_GEOMETRYN,SP_INTERIORRINGN,
unknown's avatar
unknown committed
55 56
                  NOT_FUNC, NOT_ALL_FUNC,
                  NOW_FUNC, TRIG_COND_FUNC,
57
                  GUSERVAR_FUNC};
58 59
  enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
                       OPTIMIZE_EQUAL };
unknown's avatar
unknown committed
60 61
  enum Type type() const { return FUNC_ITEM; }
  virtual enum Functype functype() const   { return UNKNOWN_FUNC; }
unknown's avatar
unknown committed
62 63
  Item_func(void):
    allowed_arg_cols(1), arg_count(0)
unknown's avatar
unknown committed
64
  {
65
    with_sum_func= 0;
unknown's avatar
unknown committed
66
  }
unknown's avatar
unknown committed
67 68
  Item_func(Item *a):
    allowed_arg_cols(1), arg_count(1)
unknown's avatar
unknown committed
69
  {
70
    args= tmp_arg;
71 72
    args[0]= a;
    with_sum_func= a->with_sum_func;
unknown's avatar
unknown committed
73
  }
unknown's avatar
unknown committed
74 75
  Item_func(Item *a,Item *b):
    allowed_arg_cols(1), arg_count(2)
unknown's avatar
unknown committed
76
  {
77
    args= tmp_arg;
78 79
    args[0]= a; args[1]= b;
    with_sum_func= a->with_sum_func || b->with_sum_func;
unknown's avatar
unknown committed
80
  }
unknown's avatar
unknown committed
81 82
  Item_func(Item *a,Item *b,Item *c):
    allowed_arg_cols(1)
unknown's avatar
unknown committed
83
  {
84 85
    arg_count= 0;
    if ((args= (Item**) sql_alloc(sizeof(Item*)*3)))
unknown's avatar
unknown committed
86
    {
87 88 89
      arg_count= 3;
      args[0]= a; args[1]= b; args[2]= c;
      with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
unknown's avatar
unknown committed
90 91
    }
  }
unknown's avatar
unknown committed
92 93
  Item_func(Item *a,Item *b,Item *c,Item *d):
    allowed_arg_cols(1)
unknown's avatar
unknown committed
94
  {
95 96
    arg_count= 0;
    if ((args= (Item**) sql_alloc(sizeof(Item*)*4)))
unknown's avatar
unknown committed
97
    {
98 99 100 101
      arg_count= 4;
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
      with_sum_func= a->with_sum_func || b->with_sum_func ||
	c->with_sum_func || d->with_sum_func;
unknown's avatar
unknown committed
102 103
    }
  }
unknown's avatar
unknown committed
104 105
  Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
    allowed_arg_cols(1)
unknown's avatar
unknown committed
106
  {
107 108
    arg_count= 5;
    if ((args= (Item**) sql_alloc(sizeof(Item*)*5)))
unknown's avatar
unknown committed
109
    {
110 111 112
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
      with_sum_func= a->with_sum_func || b->with_sum_func ||
	c->with_sum_func || d->with_sum_func || e->with_sum_func ;
unknown's avatar
unknown committed
113 114 115
    }
  }
  Item_func(List<Item> &list);
116
  // Constructor used for Item_cond_and/or (see Item comment)
117
  Item_func(THD *thd, Item_func *item);
unknown's avatar
unknown committed
118
  bool fix_fields(THD *,struct st_table_list *, Item **ref);
unknown's avatar
unknown committed
119
  table_map used_tables() const;
120
  table_map not_null_tables() const;
unknown's avatar
unknown committed
121
  void update_used_tables();
122
  bool eq(const Item *item, bool binary_cmp) const;
unknown's avatar
unknown committed
123 124 125 126 127 128
  virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
  virtual bool have_rev_func() const { return 0; }
  virtual Item *key_item() const { return args[0]; }
  virtual const char *func_name() const { return "?"; }
  virtual bool const_item() const { return const_item_cache; }
  inline Item **arguments() const { return args; }
129
  void set_arguments(List<Item> &list);
unknown's avatar
unknown committed
130 131
  inline uint argument_count() const { return arg_count; }
  inline void remove_arguments() { arg_count=0; }
132
  void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
unknown's avatar
unknown committed
133 134
  void print(String *str);
  void print_op(String *str);
unknown's avatar
unknown committed
135
  void print_args(String *str, uint from);
unknown's avatar
unknown committed
136 137 138 139
  virtual void fix_num_length_and_dec();
  void count_only_length();
  void count_real_length();
  void count_decimal_length();
140
  inline bool get_arg0_date(TIME *ltime, uint fuzzy_date)
unknown's avatar
unknown committed
141
  {
142
    return (null_value=args[0]->get_date(ltime, fuzzy_date));
unknown's avatar
unknown committed
143 144 145 146 147
  }
  inline bool get_arg0_time(TIME *ltime)
  {
    return (null_value=args[0]->get_time(ltime));
  }
unknown's avatar
unknown committed
148
  bool is_null() { (void) val_int(); return null_value; }
unknown's avatar
unknown committed
149
  void signal_divide_by_null();
unknown's avatar
unknown committed
150
  friend class udf_handler;
151
  Field *tmp_table_field() { return result_field; }
152
  Field *tmp_table_field(TABLE *t_arg);
153
  Item *get_tmp_table_item(THD *thd);
unknown's avatar
unknown committed
154 155 156

  my_decimal *val_decimal(my_decimal *);

157
  bool agg_arg_collations(DTCollation &c, Item **items, uint nitems,
158
                          uint flags= 0);
159 160
  bool agg_arg_collations_for_comparison(DTCollation &c,
                                         Item **items, uint nitems,
161
                                         uint flags= 0);
unknown's avatar
unknown committed
162 163
  bool agg_arg_charsets(DTCollation &c, Item **items, uint nitems,
                        uint flags= 0);
unknown's avatar
unknown committed
164
  bool walk(Item_processor processor, byte *arg);
unknown's avatar
unknown committed
165
  Item *transform(Item_transformer transformer, byte *arg);
unknown's avatar
unknown committed
166 167 168 169 170 171 172 173 174 175 176
};


class Item_real_func :public Item_func
{
public:
  Item_real_func() :Item_func() {}
  Item_real_func(Item *a) :Item_func(a) {}
  Item_real_func(Item *a,Item *b) :Item_func(a,b) {}
  Item_real_func(List<Item> &list) :Item_func(list) {}
  String *val_str(String*str);
177 178
  longlong val_int()
    { DBUG_ASSERT(fixed == 1); return (longlong) val_real(); }
unknown's avatar
unknown committed
179
  enum Item_result result_type () const { return REAL_RESULT; }
unknown's avatar
unknown committed
180 181
  void fix_length_and_dec()
  { decimals= NOT_FIXED_DEC; max_length= float_length(decimals); }
unknown's avatar
unknown committed
182 183
};

184

unknown's avatar
unknown committed
185
class Item_func_numhybrid: public Item_func
unknown's avatar
unknown committed
186
{
unknown's avatar
unknown committed
187
protected:
unknown's avatar
unknown committed
188 189
  Item_result hybrid_type;
public:
unknown's avatar
unknown committed
190 191 192 193 194 195
  Item_func_numhybrid(Item *a) :Item_func(a),hybrid_type(REAL_RESULT)
  {}
  Item_func_numhybrid(Item *a,Item *b)
    :Item_func(a,b),hybrid_type(REAL_RESULT)
  {}

unknown's avatar
unknown committed
196
  enum Item_result result_type () const { return hybrid_type; }
unknown's avatar
unknown committed
197 198 199 200 201 202 203 204 205 206 207 208
  void fix_length_and_dec();
  void fix_num_length_and_dec();
  virtual void find_num_type()= 0; /* To be called from fix_length_and_dec */

  double val_real();
  longlong val_int();
  my_decimal *val_decimal(my_decimal *);
  String *val_str(String*str);

  virtual longlong int_op()= 0;
  virtual double real_op()= 0;
  virtual my_decimal *decimal_op(my_decimal *)= 0;
209
  bool is_null() { (void) val_real(); return null_value; }
unknown's avatar
unknown committed
210 211
};

unknown's avatar
unknown committed
212 213 214 215 216 217
/* function where type of result detected by first argument */
class Item_func_num1: public Item_func_numhybrid
{
public:
  Item_func_num1(Item *a) :Item_func_numhybrid(a) {}
  Item_func_num1(Item *a, Item *b) :Item_func_numhybrid(a, b) {}
unknown's avatar
unknown committed
218

unknown's avatar
unknown committed
219 220 221 222 223 224 225
  void fix_num_length_and_dec();
  void find_num_type();
};


/* Base class for operations like '+', '-', '*' */
class Item_num_op :public Item_func_numhybrid
unknown's avatar
unknown committed
226 227
{
 public:
unknown's avatar
unknown committed
228 229
  Item_num_op(Item *a,Item *b) :Item_func_numhybrid(a, b) {}
  virtual void result_precision()= 0;
unknown's avatar
unknown committed
230
  void print(String *str) { print_op(str); }
unknown's avatar
unknown committed
231
  void find_num_type();
unknown's avatar
unknown committed
232 233 234 235 236 237
};


class Item_int_func :public Item_func
{
public:
unknown's avatar
unknown committed
238 239 240 241 242 243
  Item_int_func() :Item_func() { max_length= 21; }
  Item_int_func(Item *a) :Item_func(a) { max_length= 21; }
  Item_int_func(Item *a,Item *b) :Item_func(a,b) { max_length= 21; }
  Item_int_func(Item *a,Item *b,Item *c) :Item_func(a,b,c)
  { max_length= 21; }
  Item_int_func(List<Item> &list) :Item_func(list) { max_length= 21; }
244
  Item_int_func(THD *thd, Item_int_func *item) :Item_func(thd, item) {}
245
  double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
unknown's avatar
unknown committed
246 247
  String *val_str(String*str);
  enum Item_result result_type () const { return INT_RESULT; }
unknown's avatar
unknown committed
248
  void fix_length_and_dec() {}
unknown's avatar
unknown committed
249 250
};

251

252 253 254 255
class Item_func_signed :public Item_int_func
{
public:
  Item_func_signed(Item *a) :Item_int_func(a) {}
256
  const char *func_name() const { return "cast_as_signed"; }
257
  double val_real()
unknown's avatar
unknown committed
258
  {
259
    double tmp= args[0]->val_real();
unknown's avatar
unknown committed
260 261 262 263 264 265 266 267 268
    null_value= args[0]->null_value;
    return tmp;
  }
  longlong val_int()
  {
    longlong tmp= args[0]->val_int();
    null_value= args[0]->null_value; 
    return tmp;
  }
269
  void fix_length_and_dec()
unknown's avatar
unknown committed
270
  { max_length=args[0]->max_length; unsigned_flag=0; }
271
  void print(String *str);
272 273
};

274

unknown's avatar
unknown committed
275
class Item_func_unsigned :public Item_func_signed
276 277
{
public:
unknown's avatar
unknown committed
278
  Item_func_unsigned(Item *a) :Item_func_signed(a) {}
279
  const char *func_name() const { return "cast_as_unsigned"; }
280
  void fix_length_and_dec()
unknown's avatar
unknown committed
281
  { max_length=args[0]->max_length; unsigned_flag=1; }
282
  void print(String *str);
283 284 285
};


unknown's avatar
unknown committed
286
class Item_decimal_typecast :public Item_func
unknown's avatar
unknown committed
287
{
unknown's avatar
unknown committed
288
  my_decimal decimal_value;
unknown's avatar
unknown committed
289
public:
unknown's avatar
unknown committed
290 291 292 293 294 295
  Item_decimal_typecast(Item *a, int len, int dec) :Item_func(a)
  {
    max_length= len + 2;
    decimals= dec;
  }
  String *val_str(String *str);
296
  double val_real();
unknown's avatar
unknown committed
297
  longlong val_int();
unknown's avatar
unknown committed
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
  my_decimal *val_decimal(my_decimal*);
  enum Item_result result_type () const { return DECIMAL_RESULT; }
  enum_field_types field_type() const { return MYSQL_TYPE_DECIMAL; }
  void fix_length_and_dec() {};
};


class Item_func_additive_op :public Item_num_op
{
public:
  Item_func_additive_op(Item *a,Item *b) :Item_num_op(a,b) {}
  void result_precision();
};


class Item_func_plus :public Item_func_additive_op
{
public:
  Item_func_plus(Item *a,Item *b) :Item_func_additive_op(a,b) {}
  const char *func_name() const { return "+"; }
  longlong int_op();
  double real_op();
  my_decimal *decimal_op(my_decimal *);
unknown's avatar
unknown committed
321 322
};

unknown's avatar
unknown committed
323
class Item_func_minus :public Item_func_additive_op
unknown's avatar
unknown committed
324 325
{
public:
unknown's avatar
unknown committed
326
  Item_func_minus(Item *a,Item *b) :Item_func_additive_op(a,b) {}
unknown's avatar
unknown committed
327
  const char *func_name() const { return "-"; }
unknown's avatar
unknown committed
328 329 330
  longlong int_op();
  double real_op();
  my_decimal *decimal_op(my_decimal *);
331
  void fix_length_and_dec();
unknown's avatar
unknown committed
332 333
};

334

unknown's avatar
unknown committed
335 336 337 338 339
class Item_func_mul :public Item_num_op
{
public:
  Item_func_mul(Item *a,Item *b) :Item_num_op(a,b) {}
  const char *func_name() const { return "*"; }
unknown's avatar
unknown committed
340 341 342 343
  longlong int_op();
  double real_op();
  my_decimal *decimal_op(my_decimal *);
  void result_precision();
unknown's avatar
unknown committed
344 345 346 347 348 349 350
};


class Item_func_div :public Item_num_op
{
public:
  Item_func_div(Item *a,Item *b) :Item_num_op(a,b) {}
unknown's avatar
unknown committed
351 352 353
  longlong int_op() { DBUG_ASSERT(0); }
  double real_op();
  my_decimal *decimal_op(my_decimal *);
unknown's avatar
unknown committed
354 355
  const char *func_name() const { return "/"; }
  void fix_length_and_dec();
unknown's avatar
unknown committed
356
  void result_precision();
unknown's avatar
unknown committed
357 358 359
};


unknown's avatar
unknown committed
360
class Item_func_int_div :public Item_func
361 362
{
public:
unknown's avatar
unknown committed
363 364
  Item_func_int_div(Item *a,Item *b) :Item_func(a,b)
  {}
365
  double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
366
  longlong val_int();
unknown's avatar
unknown committed
367
  String *val_str(String*str);
368 369
  const char *func_name() const { return "DIV"; }
  void fix_length_and_dec();
unknown's avatar
unknown committed
370 371
  void print(String *str) { print_op(str); }
  enum Item_result result_type () const { return INT_RESULT; }
372 373 374
};


unknown's avatar
unknown committed
375 376 377 378
class Item_func_mod :public Item_num_op
{
public:
  Item_func_mod(Item *a,Item *b) :Item_num_op(a,b) {}
unknown's avatar
unknown committed
379 380 381
  longlong int_op();
  double real_op();
  my_decimal *decimal_op(my_decimal *);
unknown's avatar
unknown committed
382
  const char *func_name() const { return "%"; }
unknown's avatar
unknown committed
383 384 385 386 387 388 389 390 391
  void result_precision();
};


class Item_func_signproc :public Item_func_num1
{
public:
  Item_func_signproc(Item *a) :Item_func_num1(a) {}
  Item_func_signproc(Item *a, Item *b) :Item_func_num1(a, b) {}
unknown's avatar
unknown committed
392 393 394 395
  void fix_length_and_dec();
};


unknown's avatar
unknown committed
396
class Item_func_neg :public Item_func_signproc
unknown's avatar
unknown committed
397 398
{
public:
unknown's avatar
unknown committed
399 400 401 402
  Item_func_neg(Item *a) :Item_func_signproc(a) {}
  double real_op();
  longlong int_op();
  my_decimal *decimal_op(my_decimal *);
unknown's avatar
unknown committed
403
  const char *func_name() const { return "-"; }
unknown's avatar
unknown committed
404
  void fix_num_length_and_dec();
unknown's avatar
unknown committed
405 406 407
};


unknown's avatar
unknown committed
408
class Item_func_abs :public Item_func_num1
unknown's avatar
unknown committed
409 410
{
public:
unknown's avatar
unknown committed
411 412 413 414
  Item_func_abs(Item *a) :Item_func_num1(a) {}
  double real_op();
  longlong int_op();
  my_decimal *decimal_op(my_decimal *);
unknown's avatar
unknown committed
415 416 417 418
  const char *func_name() const { return "abs"; }
  void fix_length_and_dec();
};

unknown's avatar
unknown committed
419
// A class to handle logarithmic and trigonometric functions
unknown's avatar
unknown committed
420 421 422 423 424 425 426 427

class Item_dec_func :public Item_real_func
{
 public:
  Item_dec_func(Item *a) :Item_real_func(a) {}
  Item_dec_func(Item *a,Item *b) :Item_real_func(a,b) {}
  void fix_length_and_dec()
  {
428
    decimals=NOT_FIXED_DEC; max_length=float_length(decimals);
unknown's avatar
unknown committed
429 430 431 432 433 434 435
    maybe_null=1;
  }
  inline double fix_result(double value)
  {
#ifndef HAVE_FINITE
    return value;
#else
436
    /* The following should be safe, even if we compare doubles */
unknown's avatar
unknown committed
437 438 439 440 441 442 443 444 445 446 447 448
    if (finite(value) && value != POSTFIX_ERROR)
      return value;
    null_value=1;
    return 0.0;
#endif
  }
};

class Item_func_exp :public Item_dec_func
{
public:
  Item_func_exp(Item *a) :Item_dec_func(a) {}
449
  double val_real();
unknown's avatar
unknown committed
450 451 452
  const char *func_name() const { return "exp"; }
};

453 454 455 456 457

class Item_func_ln :public Item_dec_func
{
public:
  Item_func_ln(Item *a) :Item_dec_func(a) {}
458
  double val_real();
459 460 461 462
  const char *func_name() const { return "ln"; }
};


unknown's avatar
unknown committed
463 464 465 466
class Item_func_log :public Item_dec_func
{
public:
  Item_func_log(Item *a) :Item_dec_func(a) {}
467
  Item_func_log(Item *a,Item *b) :Item_dec_func(a,b) {}
468
  double val_real();
unknown's avatar
unknown committed
469 470 471 472
  const char *func_name() const { return "log"; }
};


473 474 475 476
class Item_func_log2 :public Item_dec_func
{
public:
  Item_func_log2(Item *a) :Item_dec_func(a) {}
477
  double val_real();
478 479 480 481
  const char *func_name() const { return "log2"; }
};


unknown's avatar
unknown committed
482 483 484 485
class Item_func_log10 :public Item_dec_func
{
public:
  Item_func_log10(Item *a) :Item_dec_func(a) {}
486
  double val_real();
unknown's avatar
unknown committed
487 488 489 490 491 492 493 494
  const char *func_name() const { return "log10"; }
};


class Item_func_sqrt :public Item_dec_func
{
public:
  Item_func_sqrt(Item *a) :Item_dec_func(a) {}
495
  double val_real();
unknown's avatar
unknown committed
496 497 498 499 500 501 502 503
  const char *func_name() const { return "sqrt"; }
};


class Item_func_pow :public Item_dec_func
{
public:
  Item_func_pow(Item *a,Item *b) :Item_dec_func(a,b) {}
504
  double val_real();
unknown's avatar
unknown committed
505 506 507 508 509 510 511 512
  const char *func_name() const { return "pow"; }
};


class Item_func_acos :public Item_dec_func
{
 public:
  Item_func_acos(Item *a) :Item_dec_func(a) {}
513
  double val_real();
unknown's avatar
unknown committed
514 515 516 517 518 519 520
  const char *func_name() const { return "acos"; }
};

class Item_func_asin :public Item_dec_func
{
 public:
  Item_func_asin(Item *a) :Item_dec_func(a) {}
521
  double val_real();
unknown's avatar
unknown committed
522 523 524 525 526 527 528 529
  const char *func_name() const { return "asin"; }
};

class Item_func_atan :public Item_dec_func
{
 public:
  Item_func_atan(Item *a) :Item_dec_func(a) {}
  Item_func_atan(Item *a,Item *b) :Item_dec_func(a,b) {}
530
  double val_real();
unknown's avatar
unknown committed
531 532 533 534 535 536 537
  const char *func_name() const { return "atan"; }
};

class Item_func_cos :public Item_dec_func
{
 public:
  Item_func_cos(Item *a) :Item_dec_func(a) {}
538
  double val_real();
unknown's avatar
unknown committed
539 540 541 542 543 544 545
  const char *func_name() const { return "cos"; }
};

class Item_func_sin :public Item_dec_func
{
 public:
  Item_func_sin(Item *a) :Item_dec_func(a) {}
546
  double val_real();
unknown's avatar
unknown committed
547 548 549 550 551 552 553
  const char *func_name() const { return "sin"; }
};

class Item_func_tan :public Item_dec_func
{
 public:
  Item_func_tan(Item *a) :Item_dec_func(a) {}
554
  double val_real();
unknown's avatar
unknown committed
555 556 557 558 559 560 561 562 563 564 565
  const char *func_name() const { return "tan"; }
};

class Item_func_integer :public Item_int_func
{
public:
  inline Item_func_integer(Item *a) :Item_int_func(a) {}
  void fix_length_and_dec();
};


unknown's avatar
unknown committed
566 567 568 569 570 571 572 573 574 575
class Item_func_int_val :public Item_func_num1
{
public:
  Item_func_int_val(Item *a) :Item_func_num1(a) {}
  void fix_num_length_and_dec();
  void find_num_type();
};


class Item_func_ceiling :public Item_func_int_val
unknown's avatar
unknown committed
576 577
{
public:
unknown's avatar
unknown committed
578
  Item_func_ceiling(Item *a) :Item_func_int_val(a) {}
unknown's avatar
unknown committed
579
  const char *func_name() const { return "ceiling"; }
unknown's avatar
unknown committed
580 581 582
  longlong int_op();
  double real_op();
  my_decimal *decimal_op(my_decimal *);
unknown's avatar
unknown committed
583 584
};

unknown's avatar
unknown committed
585 586

class Item_func_floor :public Item_func_int_val
unknown's avatar
unknown committed
587 588
{
public:
unknown's avatar
unknown committed
589
  Item_func_floor(Item *a) :Item_func_int_val(a) {}
unknown's avatar
unknown committed
590
  const char *func_name() const { return "floor"; }
unknown's avatar
unknown committed
591 592 593
  longlong int_op();
  double real_op();
  my_decimal *decimal_op(my_decimal *);
unknown's avatar
unknown committed
594 595 596 597
};

/* This handles round and truncate */

unknown's avatar
unknown committed
598
class Item_func_round :public Item_func_num1
unknown's avatar
unknown committed
599 600 601
{
  bool truncate;
public:
unknown's avatar
unknown committed
602 603
  Item_func_round(Item *a, Item *b, bool trunc_arg)
    :Item_func_num1(a,b), truncate(trunc_arg) {}
unknown's avatar
unknown committed
604
  const char *func_name() const { return truncate ? "truncate" : "round"; }
unknown's avatar
unknown committed
605 606 607 608
  double real_op();
  longlong int_op();
  my_decimal *decimal_op(my_decimal *);
  void fix_num_length_and_dec();
unknown's avatar
unknown committed
609 610 611 612 613
};


class Item_func_rand :public Item_real_func
{
614
  struct rand_struct *rand;
unknown's avatar
unknown committed
615
public:
616 617
  Item_func_rand(Item *a) :Item_real_func(a), rand(0) {}
  Item_func_rand()	  :Item_real_func() {}
618
  double val_real();
unknown's avatar
unknown committed
619 620
  const char *func_name() const { return "rand"; }
  bool const_item() const { return 0; }
unknown's avatar
unknown committed
621
  void update_used_tables();
622
  bool fix_fields(THD *thd, struct st_table_list *tables, Item **ref);
unknown's avatar
unknown committed
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
};


class Item_func_sign :public Item_int_func
{
public:
  Item_func_sign(Item *a) :Item_int_func(a) {}
  const char *func_name() const { return "sign"; }
  longlong val_int();
};


class Item_func_units :public Item_real_func
{
  char *name;
  double mul,add;
 public:
  Item_func_units(char *name_arg,Item *a,double mul_arg,double add_arg)
    :Item_real_func(a),name(name_arg),mul(mul_arg),add(add_arg) {}
642
  double val_real();
unknown's avatar
unknown committed
643
  const char *func_name() const { return name; }
unknown's avatar
unknown committed
644 645
  void fix_length_and_dec()
  { decimals= NOT_FIXED_DEC; max_length= float_length(decimals); }
unknown's avatar
unknown committed
646 647 648 649 650 651 652 653 654 655
};


class Item_func_min_max :public Item_func
{
  Item_result cmp_type;
  String tmp_value;
  int cmp_sign;
public:
  Item_func_min_max(List<Item> &list,int cmp_sign_arg) :Item_func(list),
656
    cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg) {}
657
  double val_real();
unknown's avatar
unknown committed
658 659
  longlong val_int();
  String *val_str(String *);
unknown's avatar
unknown committed
660
  my_decimal *val_decimal(my_decimal *);
unknown's avatar
unknown committed
661 662
  void fix_length_and_dec();
  enum Item_result result_type () const { return cmp_type; }
unknown's avatar
unknown committed
663
  table_map not_null_tables() const { return 0; }
unknown's avatar
unknown committed
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
};

class Item_func_min :public Item_func_min_max
{
public:
  Item_func_min(List<Item> &list) :Item_func_min_max(list,1) {}
  const char *func_name() const { return "least"; }
};

class Item_func_max :public Item_func_min_max
{
public:
  Item_func_max(List<Item> &list) :Item_func_min_max(list,-1) {}
  const char *func_name() const { return "greatest"; }
};

unknown's avatar
unknown committed
680

unknown's avatar
unknown committed
681 682 683 684 685 686 687 688 689 690
class Item_func_length :public Item_int_func
{
  String value;
public:
  Item_func_length(Item *a) :Item_int_func(a) {}
  longlong val_int();
  const char *func_name() const { return "length"; }
  void fix_length_and_dec() { max_length=10; }
};

unknown's avatar
unknown committed
691 692 693 694
class Item_func_bit_length :public Item_func_length
{
public:
  Item_func_bit_length(Item *a) :Item_func_length(a) {}
695 696
  longlong val_int()
    { DBUG_ASSERT(fixed == 1); return Item_func_length::val_int()*8; }
unknown's avatar
unknown committed
697 698 699
  const char *func_name() const { return "bit_length"; }
};

unknown's avatar
unknown committed
700 701 702 703 704 705 706 707 708 709
class Item_func_char_length :public Item_int_func
{
  String value;
public:
  Item_func_char_length(Item *a) :Item_int_func(a) {}
  longlong val_int();
  const char *func_name() const { return "char_length"; }
  void fix_length_and_dec() { max_length=10; }
};

unknown's avatar
unknown committed
710 711 712 713 714 715 716 717 718
class Item_func_coercibility :public Item_int_func
{
public:
  Item_func_coercibility(Item *a) :Item_int_func(a) {}
  longlong val_int();
  const char *func_name() const { return "coercibility"; }
  void fix_length_and_dec() { max_length=10; }
};

unknown's avatar
unknown committed
719 720 721
class Item_func_locate :public Item_int_func
{
  String value1,value2;
722
  DTCollation cmp_collation;
unknown's avatar
unknown committed
723 724 725 726 727
public:
  Item_func_locate(Item *a,Item *b) :Item_int_func(a,b) {}
  Item_func_locate(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {}
  const char *func_name() const { return "locate"; }
  longlong val_int();
728
  void fix_length_and_dec();
729
  void print(String *str);
unknown's avatar
unknown committed
730 731 732 733 734 735
};


class Item_func_field :public Item_int_func
{
  String value,tmp;
736 737
  Item_result cmp_type;
  DTCollation cmp_collation;
unknown's avatar
unknown committed
738
public:
739
  Item_func_field(List<Item> &list) :Item_int_func(list) {}
unknown's avatar
unknown committed
740 741
  longlong val_int();
  const char *func_name() const { return "field"; }
742
  void fix_length_and_dec();
unknown's avatar
unknown committed
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
};


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

class Item_func_ord :public Item_int_func
{
  String value;
public:
  Item_func_ord(Item *a) :Item_int_func(a) {}
  longlong val_int();
  const char *func_name() const { return "ord"; }
};

class Item_func_find_in_set :public Item_int_func
{
  String value,value2;
  uint enum_value;
  ulonglong enum_bit;
770
  DTCollation cmp_collation;
unknown's avatar
unknown committed
771 772 773 774 775 776 777
public:
  Item_func_find_in_set(Item *a,Item *b) :Item_int_func(a,b),enum_value(0) {}
  longlong val_int();
  const char *func_name() const { return "find_in_set"; }
  void fix_length_and_dec();
};

778
/* Base class for all bit functions: '~', '|', '^', '&', '>>', '<<' */
unknown's avatar
unknown committed
779

780
class Item_func_bit: public Item_int_func
unknown's avatar
unknown committed
781 782
{
public:
783 784 785
  Item_func_bit(Item *a, Item *b) :Item_int_func(a, b) {}
  Item_func_bit(Item *a) :Item_int_func(a) {}
  void fix_length_and_dec() { unsigned_flag= 1; }
unknown's avatar
unknown committed
786
  void print(String *str) { print_op(str); }
787 788 789 790 791 792
};

class Item_func_bit_or :public Item_func_bit
{
public:
  Item_func_bit_or(Item *a, Item *b) :Item_func_bit(a, b) {}
unknown's avatar
unknown committed
793 794 795 796
  longlong val_int();
  const char *func_name() const { return "|"; }
};

797
class Item_func_bit_and :public Item_func_bit
unknown's avatar
unknown committed
798 799
{
public:
800
  Item_func_bit_and(Item *a, Item *b) :Item_func_bit(a, b) {}
unknown's avatar
unknown committed
801 802 803 804 805 806 807 808 809 810
  longlong val_int();
  const char *func_name() const { return "&"; }
};

class Item_func_bit_count :public Item_int_func
{
public:
  Item_func_bit_count(Item *a) :Item_int_func(a) {}
  longlong val_int();
  const char *func_name() const { return "bit_count"; }
unknown's avatar
unknown committed
811
  void fix_length_and_dec() { max_length=2; }
unknown's avatar
unknown committed
812 813
};

814
class Item_func_shift_left :public Item_func_bit
unknown's avatar
unknown committed
815 816
{
public:
817
  Item_func_shift_left(Item *a, Item *b) :Item_func_bit(a, b) {}
unknown's avatar
unknown committed
818 819 820 821
  longlong val_int();
  const char *func_name() const { return "<<"; }
};

822
class Item_func_shift_right :public Item_func_bit
unknown's avatar
unknown committed
823 824
{
public:
825
  Item_func_shift_right(Item *a, Item *b) :Item_func_bit(a, b) {}
unknown's avatar
unknown committed
826 827 828 829
  longlong val_int();
  const char *func_name() const { return ">>"; }
};

830
class Item_func_bit_neg :public Item_func_bit
unknown's avatar
unknown committed
831 832
{
public:
833
  Item_func_bit_neg(Item *a) :Item_func_bit(a) {}
unknown's avatar
unknown committed
834 835
  longlong val_int();
  const char *func_name() const { return "~"; }
unknown's avatar
unknown committed
836
  void print(String *str) { Item_func::print(str); }
unknown's avatar
unknown committed
837 838
};

unknown's avatar
unknown committed
839

840
class Item_func_last_insert_id :public Item_int_func
unknown's avatar
unknown committed
841 842
{
public:
843 844
  Item_func_last_insert_id() :Item_int_func() {}
  Item_func_last_insert_id(Item *a) :Item_int_func(a) {}
unknown's avatar
unknown committed
845 846
  longlong val_int();
  const char *func_name() const { return "last_insert_id"; }
unknown's avatar
unknown committed
847 848 849 850 851
  void fix_length_and_dec()
  {
    if (arg_count)
      max_length= args[0]->max_length;
  }
unknown's avatar
unknown committed
852 853 854 855 856 857 858 859 860 861 862
};

class Item_func_benchmark :public Item_int_func
{
  ulong loop_count;
 public:
  Item_func_benchmark(ulong loop_count_arg,Item *expr)
    :Item_int_func(expr), loop_count(loop_count_arg)
  {}
  longlong val_int();
  const char *func_name() const { return "benchmark"; }
unknown's avatar
unknown committed
863
  void fix_length_and_dec() { max_length=1; maybe_null=0; }
864
  void print(String *str);
unknown's avatar
unknown committed
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
};


#ifdef HAVE_DLOPEN

class Item_udf_func :public Item_func
{
 protected:
  udf_handler udf;

public:
  Item_udf_func(udf_func *udf_arg) :Item_func(), udf(udf_arg) {}
  Item_udf_func(udf_func *udf_arg, List<Item> &list)
    :Item_func(list), udf(udf_arg) {}
  const char *func_name() const { return udf.name(); }
unknown's avatar
unknown committed
880
  bool fix_fields(THD *thd, struct st_table_list *tables, Item **ref)
unknown's avatar
unknown committed
881
  {
882
    DBUG_ASSERT(fixed == 0);
unknown's avatar
unknown committed
883 884 885
    bool res= udf.fix_fields(thd, tables, this, arg_count, args);
    used_tables_cache= udf.used_tables_cache;
    const_item_cache= udf.const_item_cache;
886
    fixed= 1;
unknown's avatar
unknown committed
887 888 889
    return res;
  }
  Item_result result_type () const { return udf.result_type(); }
890
  table_map not_null_tables() const { return 0; }
unknown's avatar
unknown committed
891 892 893 894 895 896 897 898 899
};


class Item_func_udf_float :public Item_udf_func
{
 public:
  Item_func_udf_float(udf_func *udf_arg) :Item_udf_func(udf_arg) {}
  Item_func_udf_float(udf_func *udf_arg, List<Item> &list)
    :Item_udf_func(udf_arg,list) {}
900
  longlong val_int()
901 902 903 904
  {
    DBUG_ASSERT(fixed == 1);
    return (longlong) Item_func_udf_float::val_real();
  }
unknown's avatar
unknown committed
905 906 907 908 909 910 911 912
  my_decimal *val_decimal(my_decimal *dec_buf)
  {
    double res=val_real();
    if (null_value)
      return NULL;
    double2my_decimal(E_DEC_FATAL_ERROR, res, dec_buf);
    return dec_buf;
  }
913
  double val_real();
unknown's avatar
unknown committed
914 915 916 917 918 919 920 921 922 923 924 925
  String *val_str(String *str);
  void fix_length_and_dec() { fix_num_length_and_dec(); }
};


class Item_func_udf_int :public Item_udf_func
{
public:
  Item_func_udf_int(udf_func *udf_arg) :Item_udf_func(udf_arg) {}
  Item_func_udf_int(udf_func *udf_arg, List<Item> &list)
    :Item_udf_func(udf_arg,list) {}
  longlong val_int();
926
  double val_real() { return (double) Item_func_udf_int::val_int(); }
unknown's avatar
unknown committed
927 928
  String *val_str(String *str);
  enum Item_result result_type () const { return INT_RESULT; }
unknown's avatar
unknown committed
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
  void fix_length_and_dec() { decimals= 0; max_length= 21; }
};


class Item_func_udf_decimal :public Item_udf_func
{
public:
  Item_func_udf_decimal(udf_func *udf_arg) :Item_udf_func(udf_arg) {}
  Item_func_udf_decimal(udf_func *udf_arg, List<Item> &list)
    :Item_udf_func(udf_arg,list) {}
  longlong val_int();
  double val_real();
  my_decimal *val_decimal(my_decimal *);
  String *val_str(String *str);
  enum Item_result result_type () const { return DECIMAL_RESULT; }
  void fix_length_and_dec();
unknown's avatar
unknown committed
945 946 947 948 949 950 951 952 953 954
};


class Item_func_udf_str :public Item_udf_func
{
public:
  Item_func_udf_str(udf_func *udf_arg) :Item_udf_func(udf_arg) {}
  Item_func_udf_str(udf_func *udf_arg, List<Item> &list)
    :Item_udf_func(udf_arg,list) {}
  String *val_str(String *);
955
  double val_real()
unknown's avatar
unknown committed
956
  {
unknown's avatar
unknown committed
957 958 959 960 961 962
    int err_not_used;
    char *end_not_used;
    String *res;
    res= val_str(&str_value);
    return res ? my_strntod(res->charset(),(char*) res->ptr(), 
                            res->length(), &end_not_used, &err_not_used) : 0.0;
unknown's avatar
unknown committed
963 964 965
  }
  longlong val_int()
  {
unknown's avatar
unknown committed
966
    int err_not_used;
unknown's avatar
unknown committed
967
    String *res;  res=val_str(&str_value);
unknown's avatar
unknown committed
968 969
    return res ? my_strntoll(res->charset(),res->ptr(),res->length(),10,
                             (char**) 0, &err_not_used) : (longlong) 0;
unknown's avatar
unknown committed
970
  }
unknown's avatar
unknown committed
971 972 973 974 975 976 977 978
  my_decimal *val_decimal(my_decimal *dec_buf)
  {
    String *res=val_str(&str_value);
    if (!res)
      return NULL;
    string2my_decimal(E_DEC_FATAL_ERROR, res, dec_buf);
    return dec_buf;
  }
unknown's avatar
unknown committed
979 980 981 982 983 984 985 986 987 988 989
  enum Item_result result_type () const { return STRING_RESULT; }
  void fix_length_and_dec();
};

#else /* Dummy functions to get sql_yacc.cc compiled */

class Item_func_udf_float :public Item_real_func
{
 public:
  Item_func_udf_float(udf_func *udf_arg) :Item_real_func() {}
  Item_func_udf_float(udf_func *udf_arg, List<Item> &list) :Item_real_func(list) {}
990
  double val_real() { DBUG_ASSERT(fixed == 1); return 0.0; }
unknown's avatar
unknown committed
991 992 993 994 995 996 997 998
};


class Item_func_udf_int :public Item_int_func
{
public:
  Item_func_udf_int(udf_func *udf_arg) :Item_int_func() {}
  Item_func_udf_int(udf_func *udf_arg, List<Item> &list) :Item_int_func(list) {}
999
  longlong val_int() { DBUG_ASSERT(fixed == 1); return 0; }
unknown's avatar
unknown committed
1000 1001 1002
};


unknown's avatar
unknown committed
1003 1004 1005 1006 1007 1008 1009 1010 1011
class Item_func_udf_decimal :public Item_int_func
{
public:
  Item_func_udf_decimal(udf_func *udf_arg) :Item_int_func() {}
  Item_func_udf_decimal(udf_func *udf_arg, List<Item> &list) :Item_int_func(list) {}
  my_decimal *val_decimal(my_decimal *) { DBUG_ASSERT(fixed == 1); return 0; }
};


unknown's avatar
unknown committed
1012 1013 1014 1015 1016
class Item_func_udf_str :public Item_func
{
public:
  Item_func_udf_str(udf_func *udf_arg) :Item_func() {}
  Item_func_udf_str(udf_func *udf_arg, List<Item> &list)  :Item_func(list) {}
1017 1018
  String *val_str(String *)
    { DBUG_ASSERT(fixed == 1); null_value=1; return 0; }
1019
  double val_real() { DBUG_ASSERT(fixed == 1); null_value= 1; return 0.0; }
1020
  longlong val_int() { DBUG_ASSERT(fixed == 1); null_value=1; return 0; }
unknown's avatar
unknown committed
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
  enum Item_result result_type () const { return STRING_RESULT; }
  void fix_length_and_dec() { maybe_null=1; max_length=0; }
};

#endif /* HAVE_DLOPEN */

/*
** User level locks
*/

1031
class User_level_lock;
unknown's avatar
unknown committed
1032
void item_user_lock_init(void);
1033
void item_user_lock_release(User_level_lock *ull);
unknown's avatar
unknown committed
1034 1035 1036 1037 1038 1039 1040 1041 1042
void item_user_lock_free(void);

class Item_func_get_lock :public Item_int_func
{
  String value;
 public:
  Item_func_get_lock(Item *a,Item *b) :Item_int_func(a,b) {}
  longlong val_int();
  const char *func_name() const { return "get_lock"; }
unknown's avatar
unknown committed
1043
  void fix_length_and_dec() { max_length=1; maybe_null=1;}
unknown's avatar
unknown committed
1044 1045 1046 1047 1048 1049 1050 1051 1052
};

class Item_func_release_lock :public Item_int_func
{
  String value;
 public:
  Item_func_release_lock(Item *a) :Item_int_func(a) {}
  longlong val_int();
  const char *func_name() const { return "release_lock"; }
unknown's avatar
unknown committed
1053
  void fix_length_and_dec() { max_length=1; maybe_null=1;}
unknown's avatar
unknown committed
1054 1055
};

unknown's avatar
unknown committed
1056 1057 1058 1059 1060 1061 1062
/* replication functions */

class Item_master_pos_wait :public Item_int_func
{
  String value;
 public:
  Item_master_pos_wait(Item *a,Item *b) :Item_int_func(a,b) {}
1063
  Item_master_pos_wait(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {}
unknown's avatar
unknown committed
1064 1065
  longlong val_int();
  const char *func_name() const { return "master_pos_wait"; }
1066
  void fix_length_and_dec() { max_length=21; maybe_null=1;}
unknown's avatar
unknown committed
1067 1068
};

unknown's avatar
unknown committed
1069

unknown's avatar
unknown committed
1070
/* Handling of user definable variables */
unknown's avatar
unknown committed
1071 1072 1073 1074 1075 1076 1077 1078

class user_var_entry;

class Item_func_set_user_var :public Item_func
{
  enum Item_result cached_result_type;
  LEX_STRING name;
  user_var_entry *entry;
1079 1080
  char buffer[MAX_FIELD_WIDTH];
  String value;
unknown's avatar
unknown committed
1081
  my_decimal decimal_buff;
1082 1083 1084 1085 1086
  union
  {
    longlong vint;
    double vreal;
    String *vstr;
unknown's avatar
unknown committed
1087
    my_decimal *vdec;
1088 1089 1090
  } save_result;
  String save_buff;
  
unknown's avatar
unknown committed
1091 1092

public:
1093 1094 1095
  Item_func_set_user_var(LEX_STRING a,Item *b)
    :Item_func(b), cached_result_type(INT_RESULT), name(a)
  {}
1096
  double val_real();
unknown's avatar
unknown committed
1097 1098
  longlong val_int();
  String *val_str(String *str);
unknown's avatar
unknown committed
1099
  my_decimal *val_decimal(my_decimal *);
unknown's avatar
unknown committed
1100
  bool update_hash(void *ptr, uint length, enum Item_result type, 
1101
  		   CHARSET_INFO *cs, Derivation dv);
1102
  bool check();
unknown's avatar
unknown committed
1103 1104
  bool update();
  enum Item_result result_type () const { return cached_result_type; }
unknown's avatar
unknown committed
1105
  bool fix_fields(THD *thd, struct st_table_list *tables, Item **ref);
unknown's avatar
unknown committed
1106
  void fix_length_and_dec();
unknown's avatar
unknown committed
1107
  void print(String *str);
1108
  void print_as_stmt(String *str);
unknown's avatar
unknown committed
1109 1110 1111 1112 1113 1114 1115
  const char *func_name() const { return "set_user_var"; }
};


class Item_func_get_user_var :public Item_func
{
  LEX_STRING name;
1116
  user_var_entry *var_entry;
unknown's avatar
unknown committed
1117 1118

public:
1119
  Item_func_get_user_var(LEX_STRING a):
1120
    Item_func(), name(a) {}
1121 1122
  enum Functype functype() const { return GUSERVAR_FUNC; }
  LEX_STRING get_name() { return name; }
1123
  double val_real();
unknown's avatar
unknown committed
1124
  longlong val_int();
unknown's avatar
unknown committed
1125
  my_decimal *val_decimal(my_decimal*);
unknown's avatar
unknown committed
1126 1127
  String *val_str(String* str);
  void fix_length_and_dec();
unknown's avatar
unknown committed
1128
  void print(String *str);
unknown's avatar
unknown committed
1129
  enum Item_result result_type() const;
1130 1131 1132 1133
  /*
    We must always return variables as strings to guard against selects of type
    select @t1:=1,@t1,@t:="hello",@t from foo where (@t1:= t2.b)
  */
1134
  enum_field_types field_type() const  { return MYSQL_TYPE_VARCHAR; }
unknown's avatar
unknown committed
1135
  const char *func_name() const { return "get_user_var"; }
1136
  bool const_item() const;
1137
  table_map used_tables() const
1138
  { return const_item() ? 0 : RAND_TABLE_BIT; }
1139
  bool eq(const Item *item, bool binary_cmp) const;
1140
};
unknown's avatar
unknown committed
1141

unknown's avatar
unknown committed
1142

unknown's avatar
unknown committed
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
class Item_func_inet_aton : public Item_int_func
{
public:
   Item_func_inet_aton(Item *a) :Item_int_func(a) {}
   longlong val_int();
   const char *func_name() const { return "inet_aton"; }
   void fix_length_and_dec() { decimals = 0; max_length = 21; maybe_null=1;}
};


1153
/* for fulltext search */
1154
#include <ft_global.h>
unknown's avatar
unknown committed
1155 1156 1157 1158

class Item_func_match :public Item_real_func
{
public:
1159
  uint key, flags;
unknown's avatar
unknown committed
1160
  bool join_key;
1161 1162 1163 1164 1165 1166 1167
  DTCollation cmp_collation;
  FT_INFO *ft_handler;
  TABLE *table;
  Item_func_match *master;   // for master-slave optimization
  Item *concat;              // Item_func_concat_ws
  String value;              // value of concat
  String search_value;       // key_item()'s value converted to cmp_collation
unknown's avatar
unknown committed
1168

unknown's avatar
unknown committed
1169 1170
  Item_func_match(List<Item> &a, uint b): Item_real_func(a), key(0), flags(b),
       join_key(0), ft_handler(0), table(0), master(0), concat(0) { }
unknown's avatar
unknown committed
1171
  void cleanup()
1172
  {
unknown's avatar
unknown committed
1173
    DBUG_ENTER("Item_func_match");
1174
    Item_real_func::cleanup();
1175
    if (!master && ft_handler)
1176
    {
unknown's avatar
unknown committed
1177 1178
      ft_handler->please->close_search(ft_handler);
      ft_handler=0;
unknown's avatar
unknown committed
1179
      if (join_key)
1180
	table->file->ft_handler=0;
unknown's avatar
unknown committed
1181
      table->fulltext_searched=0;
1182
    }
unknown's avatar
unknown committed
1183
    concat= 0;
unknown's avatar
unknown committed
1184
    DBUG_VOID_RETURN;
1185
  }
unknown's avatar
unknown committed
1186
  enum Functype functype() const { return FT_FUNC; }
1187
  const char *func_name() const { return "match"; }
unknown's avatar
unknown committed
1188
  void update_used_tables() {}
1189
  table_map not_null_tables() const { return 0; }
unknown's avatar
unknown committed
1190
  bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref);
1191
  bool eq(const Item *, bool binary_cmp) const;
1192
  /* The following should be safe, even if we compare doubles */
1193 1194
  longlong val_int() { DBUG_ASSERT(fixed == 1); return val_real() != 0.0; }
  double val_real();
1195
  void print(String *str);
1196 1197

  bool fix_index();
1198
  void init_search(bool no_order);
1199
};
unknown's avatar
unknown committed
1200

unknown's avatar
unknown committed
1201

1202
class Item_func_bit_xor : public Item_func_bit
unknown's avatar
unknown committed
1203 1204
{
public:
1205
  Item_func_bit_xor(Item *a, Item *b) :Item_func_bit(a, b) {}
unknown's avatar
unknown committed
1206 1207 1208 1209
  longlong val_int();
  const char *func_name() const { return "^"; }
};

1210
class Item_func_is_free_lock :public Item_int_func
unknown's avatar
unknown committed
1211 1212 1213
{
  String value;
public:
1214
  Item_func_is_free_lock(Item *a) :Item_int_func(a) {}
unknown's avatar
unknown committed
1215
  longlong val_int();
1216
  const char *func_name() const { return "is_free_lock"; }
unknown's avatar
unknown committed
1217
  void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;}
unknown's avatar
unknown committed
1218 1219
};

unknown's avatar
SCRUM  
unknown committed
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
class Item_func_is_used_lock :public Item_int_func
{
  String value;
public:
  Item_func_is_used_lock(Item *a) :Item_int_func(a) {}
  longlong val_int();
  const char *func_name() const { return "is_used_lock"; }
  void fix_length_and_dec() { decimals=0; max_length=10; maybe_null=1;}
};

unknown's avatar
unknown committed
1230 1231
/* For type casts */

1232
enum Cast_target
unknown's avatar
unknown committed
1233 1234
{
  ITEM_CAST_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT,
unknown's avatar
unknown committed
1235 1236
  ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME, ITEM_CAST_CHAR,
  ITEM_CAST_DECIMAL
unknown's avatar
unknown committed
1237
};
1238 1239


1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
class Item_func_row_count :public Item_int_func
{
public:
  Item_func_row_count() :Item_int_func() {}
  longlong val_int();
  const char *func_name() const { return "row_count"; }
  void fix_length_and_dec() { decimals= 0; maybe_null=0; }
};


1250 1251 1252 1253 1254 1255 1256
/*
 *
 * Stored FUNCTIONs
 *
 */

class sp_head;
1257
class sp_name;
1258 1259 1260 1261

class Item_func_sp :public Item_func
{
private:
1262
  sp_name *m_name;
1263
  mutable sp_head *m_sp;
1264 1265 1266 1267 1268

  int execute(Item **itp);

public:

1269
  Item_func_sp(sp_name *name);
1270

1271
  Item_func_sp(sp_name *name, List<Item> &list);
1272 1273 1274 1275

  virtual ~Item_func_sp()
  {}

1276
  const char *func_name() const;
1277

1278 1279
  enum enum_field_types field_type() const;

1280 1281 1282 1283
  Item_result result_type() const;

  longlong val_int()
  {
1284
    return (longlong)Item_func_sp::val_real();
1285 1286
  }

1287
  double val_real()
1288 1289
  {
    Item *it;
1290
    double d;
1291 1292

    if (execute(&it))
1293 1294
    {
      null_value= 1;
1295
      return 0.0;
1296
    }
1297
    d= it->val_real();
1298 1299
    null_value= it->null_value;
    return d;
1300 1301
  }

unknown's avatar
unknown committed
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
  my_decimal *val_decimal(my_decimal *dec_buf)
  {
    Item *it;
    my_decimal *result;

    if (execute(&it))
    {
      null_value= 1;
      return NULL;
    }
    result= it->val_decimal(dec_buf);
    null_value= it->null_value;
    return result;
  }


1318 1319 1320
  String *val_str(String *str)
  {
    Item *it;
1321
    String *s;
1322 1323

    if (execute(&it))
1324 1325
    {
      null_value= 1;
1326
      return NULL;
1327
    }
1328 1329 1330
    s= it->val_str(str);
    null_value= it->null_value;
    return s;
1331 1332 1333 1334 1335
  }

  void fix_length_and_dec();

};
unknown's avatar
unknown committed
1336 1337


1338 1339 1340 1341 1342 1343 1344 1345
class Item_func_found_rows :public Item_int_func
{
public:
  Item_func_found_rows() :Item_int_func() {}
  longlong val_int();
  const char *func_name() const { return "found_rows"; }
  void fix_length_and_dec() { decimals= 0; maybe_null=0; }
};