~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2006 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
17
/* Function items used by mysql */
18
19
#ifdef USE_PRAGMA_INTERFACE
20
#pragma interface			/* gcc class implementation */
21
#endif
22
23
enum date_time_format_types 
24
{ 
25
  TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND
26
};
27
28
bool get_interval_value(Item *args,interval_type int_type,
29
			       String *str_value, INTERVAL *interval);
30
31
class Item_func_period_add :public Item_int_func
32
{
33
public:
34
  Item_func_period_add(Item *a,Item *b) :Item_int_func(a,b) {}
152 by Brian Aker
longlong replacement
35
  int64_t val_int();
1 by brian
clean slate
36
  const char *func_name() const { return "period_add"; }
37
  void fix_length_and_dec() 
38
  { 
39
    max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
40
  }
41
};
42
43
44
class Item_func_period_diff :public Item_int_func
45
{
46
public:
47
  Item_func_period_diff(Item *a,Item *b) :Item_int_func(a,b) {}
152 by Brian Aker
longlong replacement
48
  int64_t val_int();
1 by brian
clean slate
49
  const char *func_name() const { return "period_diff"; }
50
  void fix_length_and_dec()
51
  { 
52
    decimals=0;
53
    max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
54
  }
55
};
56
57
58
class Item_func_to_days :public Item_int_func
59
{
60
public:
61
  Item_func_to_days(Item *a) :Item_int_func(a) {}
152 by Brian Aker
longlong replacement
62
  int64_t val_int();
1 by brian
clean slate
63
  const char *func_name() const { return "to_days"; }
64
  void fix_length_and_dec() 
65
  { 
66
    decimals=0; 
67
    max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
68
    maybe_null=1; 
69
  }
70
  enum_monotonicity_info get_monotonicity_info() const;
152 by Brian Aker
longlong replacement
71
  int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
1 by brian
clean slate
72
};
73
74
75
class Item_func_dayofmonth :public Item_int_func
76
{
77
public:
78
  Item_func_dayofmonth(Item *a) :Item_int_func(a) {}
152 by Brian Aker
longlong replacement
79
  int64_t val_int();
1 by brian
clean slate
80
  const char *func_name() const { return "dayofmonth"; }
81
  void fix_length_and_dec() 
82
  { 
83
    decimals=0; 
84
    max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
85
    maybe_null=1; 
86
  }
87
};
88
89
90
class Item_func_month :public Item_func
91
{
92
public:
93
  Item_func_month(Item *a) :Item_func(a) {}
152 by Brian Aker
longlong replacement
94
  int64_t val_int();
1 by brian
clean slate
95
  double val_real()
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
96
  { assert(fixed == 1); return (double) Item_func_month::val_int(); }
1 by brian
clean slate
97
  String *val_str(String *str) 
98
  {
99
    str->set(val_int(), &my_charset_bin);
100
    return null_value ? 0 : str;
101
  }
102
  const char *func_name() const { return "month"; }
103
  enum Item_result result_type () const { return INT_RESULT; }
104
  void fix_length_and_dec() 
105
  { 
106
    collation.set(&my_charset_bin);
107
    decimals=0;
108
    max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
109
    maybe_null=1; 
110
  }
111
};
112
113
114
class Item_func_monthname :public Item_func_month
115
{
116
public:
117
  Item_func_monthname(Item *a) :Item_func_month(a) {}
118
  const char *func_name() const { return "monthname"; }
119
  String *val_str(String *str);
120
  enum Item_result result_type () const { return STRING_RESULT; }
121
  void fix_length_and_dec() 
122
  {
123
    collation.set(&my_charset_bin);
124
    decimals=0;
125
    max_length=10*my_charset_bin.mbmaxlen;
126
    maybe_null=1; 
127
  }
128
};
129
130
131
class Item_func_dayofyear :public Item_int_func
132
{
133
public:
134
  Item_func_dayofyear(Item *a) :Item_int_func(a) {}
152 by Brian Aker
longlong replacement
135
  int64_t val_int();
1 by brian
clean slate
136
  const char *func_name() const { return "dayofyear"; }
137
  void fix_length_and_dec() 
138
  { 
139
    decimals=0;
140
    max_length=3*MY_CHARSET_BIN_MB_MAXLEN;
141
    maybe_null=1; 
142
  }
143
};
144
145
146
class Item_func_hour :public Item_int_func
147
{
148
public:
149
  Item_func_hour(Item *a) :Item_int_func(a) {}
152 by Brian Aker
longlong replacement
150
  int64_t val_int();
1 by brian
clean slate
151
  const char *func_name() const { return "hour"; }
152
  void fix_length_and_dec()
153
  {
154
    decimals=0;
155
    max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
156
    maybe_null=1;
157
  }
158
};
159
160
161
class Item_func_minute :public Item_int_func
162
{
163
public:
164
  Item_func_minute(Item *a) :Item_int_func(a) {}
152 by Brian Aker
longlong replacement
165
  int64_t val_int();
1 by brian
clean slate
166
  const char *func_name() const { return "minute"; }
167
  void fix_length_and_dec()
168
  {
169
    decimals=0;
170
    max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
171
    maybe_null=1;
172
  }
173
};
174
175
176
class Item_func_quarter :public Item_int_func
177
{
178
public:
179
  Item_func_quarter(Item *a) :Item_int_func(a) {}
152 by Brian Aker
longlong replacement
180
  int64_t val_int();
1 by brian
clean slate
181
  const char *func_name() const { return "quarter"; }
182
  void fix_length_and_dec()
183
  { 
184
     decimals=0;
185
     max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
186
     maybe_null=1;
187
  }
188
};
189
190
191
class Item_func_second :public Item_int_func
192
{
193
public:
194
  Item_func_second(Item *a) :Item_int_func(a) {}
152 by Brian Aker
longlong replacement
195
  int64_t val_int();
1 by brian
clean slate
196
  const char *func_name() const { return "second"; }
197
  void fix_length_and_dec() 
198
  { 
199
    decimals=0;
200
    max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
201
    maybe_null=1;
202
  }
203
};
204
205
206
class Item_func_week :public Item_int_func
207
{
208
public:
209
  Item_func_week(Item *a,Item *b) :Item_int_func(a,b) {}
152 by Brian Aker
longlong replacement
210
  int64_t val_int();
1 by brian
clean slate
211
  const char *func_name() const { return "week"; }
212
  void fix_length_and_dec()
213
  { 
214
    decimals=0;
215
    max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
216
    maybe_null=1;
217
  }
218
};
219
220
class Item_func_yearweek :public Item_int_func
221
{
222
public:
223
  Item_func_yearweek(Item *a,Item *b) :Item_int_func(a,b) {}
152 by Brian Aker
longlong replacement
224
  int64_t val_int();
1 by brian
clean slate
225
  const char *func_name() const { return "yearweek"; }
226
  void fix_length_and_dec()
227
  { 
228
    decimals=0;
229
    max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
230
    maybe_null=1;
231
  }
232
};
233
234
235
class Item_func_year :public Item_int_func
236
{
237
public:
238
  Item_func_year(Item *a) :Item_int_func(a) {}
152 by Brian Aker
longlong replacement
239
  int64_t val_int();
1 by brian
clean slate
240
  const char *func_name() const { return "year"; }
241
  enum_monotonicity_info get_monotonicity_info() const;
152 by Brian Aker
longlong replacement
242
  int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
1 by brian
clean slate
243
  void fix_length_and_dec()
244
  { 
245
    decimals=0;
246
    max_length=4*MY_CHARSET_BIN_MB_MAXLEN;
247
    maybe_null=1;
248
  }
249
};
250
251
252
class Item_func_weekday :public Item_func
253
{
254
  bool odbc_type;
255
public:
256
  Item_func_weekday(Item *a,bool type_arg)
257
    :Item_func(a), odbc_type(type_arg) {}
152 by Brian Aker
longlong replacement
258
  int64_t val_int();
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
259
  double val_real() { assert(fixed == 1); return (double) val_int(); }
1 by brian
clean slate
260
  String *val_str(String *str)
261
  {
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
262
    assert(fixed == 1);
1 by brian
clean slate
263
    str->set(val_int(), &my_charset_bin);
264
    return null_value ? 0 : str;
265
  }
266
  const char *func_name() const
267
  {
268
     return (odbc_type ? "dayofweek" : "weekday");
269
  }
270
  enum Item_result result_type () const { return INT_RESULT; }
271
  void fix_length_and_dec()
272
  {
273
    collation.set(&my_charset_bin);
274
    decimals=0;
275
    max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
276
    maybe_null=1;
277
  }
278
};
279
280
class Item_func_dayname :public Item_func_weekday
281
{
282
 public:
283
  Item_func_dayname(Item *a) :Item_func_weekday(a,0) {}
284
  const char *func_name() const { return "dayname"; }
285
  String *val_str(String *str);
286
  enum Item_result result_type () const { return STRING_RESULT; }
287
  void fix_length_and_dec() 
288
  { 
289
    collation.set(&my_charset_bin);
290
    decimals=0; 
291
    max_length=9*MY_CHARSET_BIN_MB_MAXLEN;
292
    maybe_null=1; 
293
  }
294
};
295
296
297
class Item_func_unix_timestamp :public Item_int_func
298
{
299
  String value;
300
public:
301
  Item_func_unix_timestamp() :Item_int_func() {}
302
  Item_func_unix_timestamp(Item *a) :Item_int_func(a) {}
152 by Brian Aker
longlong replacement
303
  int64_t val_int();
1 by brian
clean slate
304
  const char *func_name() const { return "unix_timestamp"; }
305
  void fix_length_and_dec()
306
  {
307
    decimals=0;
308
    max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
309
  }
310
};
311
312
313
class Item_func_time_to_sec :public Item_int_func
314
{
315
public:
316
  Item_func_time_to_sec(Item *item) :Item_int_func(item) {}
152 by Brian Aker
longlong replacement
317
  int64_t val_int();
1 by brian
clean slate
318
  const char *func_name() const { return "time_to_sec"; }
319
  void fix_length_and_dec()
320
  {
321
    decimals=0;
322
    max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
323
  }
324
};
325
326
327
/*
328
  This can't be a Item_str_func, because the val_real() functions are special
329
*/
330
331
class Item_date :public Item_func
332
{
333
public:
334
  Item_date() :Item_func() {}
335
  Item_date(Item *a) :Item_func(a) {}
336
  enum Item_result result_type () const { return STRING_RESULT; }
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
337
  enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
1 by brian
clean slate
338
  String *val_str(String *str);
152 by Brian Aker
longlong replacement
339
  int64_t val_int();
1 by brian
clean slate
340
  double val_real() { return val_real_from_decimal(); }
341
  const char *func_name() const { return "date"; }
342
  void fix_length_and_dec()
343
  { 
344
    collation.set(&my_charset_bin);
345
    decimals=0;
346
    max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
347
  }
348
  Field *tmp_table_field(TABLE *table)
349
  {
350
    return tmp_table_field_from_field_type(table, 0);
351
  }
152 by Brian Aker
longlong replacement
352
  bool result_as_int64_t() { return true; }
1 by brian
clean slate
353
  my_decimal *val_decimal(my_decimal *decimal_value)
354
  {
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
355
    assert(fixed == 1);
1 by brian
clean slate
356
    return  val_decimal_from_date(decimal_value);
357
  }
77.1.7 by Monty Taylor
Heap builds clean.
358
  int save_in_field(Field *field,
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
359
                    bool no_conversions __attribute__((unused)))
1 by brian
clean slate
360
  {
361
    return save_date_in_field(field);
362
  }
363
};
364
365
366
class Item_date_func :public Item_str_func
367
{
368
public:
369
  Item_date_func() :Item_str_func() {}
370
  Item_date_func(Item *a) :Item_str_func(a) {}
371
  Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {}
372
  Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {}
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
373
  enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
1 by brian
clean slate
374
  Field *tmp_table_field(TABLE *table)
375
  {
376
    return tmp_table_field_from_field_type(table, 0);
377
  }
152 by Brian Aker
longlong replacement
378
  bool result_as_int64_t() { return true; }
1 by brian
clean slate
379
  double val_real() { return (double) val_int(); }
380
  my_decimal *val_decimal(my_decimal *decimal_value)
381
  {
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
382
    assert(fixed == 1);
1 by brian
clean slate
383
    return  val_decimal_from_date(decimal_value);
384
  }
77.1.7 by Monty Taylor
Heap builds clean.
385
  int save_in_field(Field *field,
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
386
                    bool no_conversions __attribute__((unused)))
1 by brian
clean slate
387
  {
388
    return save_date_in_field(field);
389
  }
390
};
391
392
393
class Item_str_timefunc :public Item_str_func
394
{
395
public:
396
  Item_str_timefunc() :Item_str_func() {}
397
  Item_str_timefunc(Item *a) :Item_str_func(a) {}
398
  Item_str_timefunc(Item *a,Item *b) :Item_str_func(a,b) {}
399
  Item_str_timefunc(Item *a, Item *b, Item *c) :Item_str_func(a, b ,c) {}
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
400
  enum_field_types field_type() const { return DRIZZLE_TYPE_TIME; }
1 by brian
clean slate
401
  void fix_length_and_dec()
402
  {
403
    decimals= DATETIME_DEC;
404
    max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
405
  }
406
  Field *tmp_table_field(TABLE *table)
407
  {
408
    return tmp_table_field_from_field_type(table, 0);
409
  }
410
  double val_real() { return val_real_from_decimal(); }
411
  my_decimal *val_decimal(my_decimal *decimal_value)
412
  {
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
413
    assert(fixed == 1);
1 by brian
clean slate
414
    return  val_decimal_from_time(decimal_value);
415
  }
77.1.7 by Monty Taylor
Heap builds clean.
416
  int save_in_field(Field *field,
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
417
                    bool no_conversions __attribute__((unused)))
1 by brian
clean slate
418
  {
419
    return save_time_in_field(field);
420
  }
421
};
422
423
424
/* Abstract CURTIME function. Children should define what time zone is used */
425
426
class Item_func_curtime :public Item_str_timefunc
427
{
152 by Brian Aker
longlong replacement
428
  int64_t value;
1 by brian
clean slate
429
  char buff[9*2+32];
430
  uint buff_length;
431
public:
432
  Item_func_curtime() :Item_str_timefunc() {}
433
  Item_func_curtime(Item *a) :Item_str_timefunc(a) {}
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
434
  double val_real() { assert(fixed == 1); return (double) value; }
152 by Brian Aker
longlong replacement
435
  int64_t val_int() { assert(fixed == 1); return value; }
1 by brian
clean slate
436
  String *val_str(String *str);
437
  void fix_length_and_dec();
438
  /* 
439
    Abstract method that defines which time zone is used for conversion.
440
    Converts time current time in my_time_t representation to broken-down
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
441
    DRIZZLE_TIME representation using UTC-SYSTEM or per-thread time zone.
1 by brian
clean slate
442
  */
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
443
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
152 by Brian Aker
longlong replacement
444
  bool result_as_int64_t() { return true; }
1 by brian
clean slate
445
};
446
447
448
class Item_func_curtime_local :public Item_func_curtime
449
{
450
public:
451
  Item_func_curtime_local() :Item_func_curtime() {}
452
  Item_func_curtime_local(Item *a) :Item_func_curtime(a) {}
453
  const char *func_name() const { return "curtime"; }
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
454
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
1 by brian
clean slate
455
};
456
457
458
class Item_func_curtime_utc :public Item_func_curtime
459
{
460
public:
461
  Item_func_curtime_utc() :Item_func_curtime() {}
462
  Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {}
463
  const char *func_name() const { return "utc_time"; }
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
464
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
1 by brian
clean slate
465
};
466
467
468
/* Abstract CURDATE function. See also Item_func_curtime. */
469
470
class Item_func_curdate :public Item_date
471
{
152 by Brian Aker
longlong replacement
472
  int64_t value;
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
473
  DRIZZLE_TIME ltime;
1 by brian
clean slate
474
public:
475
  Item_func_curdate() :Item_date() {}
152 by Brian Aker
longlong replacement
476
  int64_t val_int() { assert(fixed == 1); return (value) ; }
1 by brian
clean slate
477
  String *val_str(String *str);
478
  void fix_length_and_dec();
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
479
  bool get_date(DRIZZLE_TIME *res, uint fuzzy_date);
480
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
1 by brian
clean slate
481
};
482
483
484
class Item_func_curdate_local :public Item_func_curdate
485
{
486
public:
487
  Item_func_curdate_local() :Item_func_curdate() {}
488
  const char *func_name() const { return "curdate"; }
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
489
  void store_now_in_TIME(DRIZZLE_TIME *now_time);
1 by brian
clean slate
490
};
491
492
493
class Item_func_curdate_utc :public Item_func_curdate
494
{
495
public:
496
  Item_func_curdate_utc() :Item_func_curdate() {}
497
  const char *func_name() const { return "utc_date"; }
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
498
  void store_now_in_TIME(DRIZZLE_TIME *now_time);
1 by brian
clean slate
499
};
500
501
502
/* Abstract CURRENT_TIMESTAMP function. See also Item_func_curtime */
503
504
class Item_func_now :public Item_date_func
505
{
506
protected:
152 by Brian Aker
longlong replacement
507
  int64_t value;
1 by brian
clean slate
508
  char buff[20*2+32];	// +32 to make my_snprintf_{8bit|ucs2} happy
509
  uint buff_length;
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
510
  DRIZZLE_TIME ltime;
1 by brian
clean slate
511
public:
512
  Item_func_now() :Item_date_func() {}
513
  Item_func_now(Item *a) :Item_date_func(a) {}
514
  enum Item_result result_type () const { return STRING_RESULT; }
152 by Brian Aker
longlong replacement
515
  int64_t val_int() { assert(fixed == 1); return value; }
1 by brian
clean slate
516
  int save_in_field(Field *to, bool no_conversions);
517
  String *val_str(String *str);
518
  void fix_length_and_dec();
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
519
  bool get_date(DRIZZLE_TIME *res, uint fuzzy_date);
520
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
1 by brian
clean slate
521
};
522
523
524
class Item_func_now_local :public Item_func_now
525
{
526
public:
527
  Item_func_now_local() :Item_func_now() {}
528
  Item_func_now_local(Item *a) :Item_func_now(a) {}
529
  const char *func_name() const { return "now"; }
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
530
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
1 by brian
clean slate
531
  virtual enum Functype functype() const { return NOW_FUNC; }
532
};
533
534
535
class Item_func_now_utc :public Item_func_now
536
{
537
public:
538
  Item_func_now_utc() :Item_func_now() {}
539
  Item_func_now_utc(Item *a) :Item_func_now(a) {}
540
  const char *func_name() const { return "utc_timestamp"; }
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
541
  virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
1 by brian
clean slate
542
};
543
544
545
/*
546
  This is like NOW(), but always uses the real current time, not the
547
  query_start(). This matches the Oracle behavior.
548
*/
549
class Item_func_sysdate_local :public Item_func_now
550
{
551
public:
552
  Item_func_sysdate_local() :Item_func_now() {}
553
  Item_func_sysdate_local(Item *a) :Item_func_now(a) {}
554
  bool const_item() const { return 0; }
555
  const char *func_name() const { return "sysdate"; }
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
556
  void store_now_in_TIME(DRIZZLE_TIME *now_time);
1 by brian
clean slate
557
  double val_real();
152 by Brian Aker
longlong replacement
558
  int64_t val_int();
1 by brian
clean slate
559
  int save_in_field(Field *to, bool no_conversions);
560
  String *val_str(String *str);
561
  void fix_length_and_dec();
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
562
  bool get_date(DRIZZLE_TIME *res, uint fuzzy_date);
1 by brian
clean slate
563
  void update_used_tables()
564
  {
565
    Item_func_now::update_used_tables();
566
    used_tables_cache|= RAND_TABLE_BIT;
567
  }
568
};
569
570
571
class Item_func_from_days :public Item_date
572
{
573
public:
574
  Item_func_from_days(Item *a) :Item_date(a) {}
575
  const char *func_name() const { return "from_days"; }
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
576
  bool get_date(DRIZZLE_TIME *res, uint fuzzy_date);
1 by brian
clean slate
577
};
578
579
580
class Item_func_date_format :public Item_str_func
581
{
582
  int fixed_length;
583
  const bool is_time_format;
584
  String value;
585
public:
586
  Item_func_date_format(Item *a,Item *b,bool is_time_format_arg)
587
    :Item_str_func(a,b),is_time_format(is_time_format_arg) {}
588
  String *val_str(String *str);
589
  const char *func_name() const
590
    { return is_time_format ? "time_format" : "date_format"; }
591
  void fix_length_and_dec();
592
  uint format_length(const String *format);
593
  bool eq(const Item *item, bool binary_cmp) const;
594
};
595
596
597
class Item_func_from_unixtime :public Item_date_func
598
{
599
  THD *thd;
600
 public:
601
  Item_func_from_unixtime(Item *a) :Item_date_func(a) {}
152 by Brian Aker
longlong replacement
602
  int64_t val_int();
1 by brian
clean slate
603
  String *val_str(String *str);
604
  const char *func_name() const { return "from_unixtime"; }
605
  void fix_length_and_dec();
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
606
  bool get_date(DRIZZLE_TIME *res, uint fuzzy_date);
1 by brian
clean slate
607
};
608
609
610
/* 
611
  We need Time_zone class declaration for storing pointers in
612
  Item_func_convert_tz.
613
*/
614
class Time_zone;
615
616
/*
617
  This class represents CONVERT_TZ() function.
618
  The important fact about this function that it is handled in special way.
619
  When such function is met in expression time_zone system tables are added
620
  to global list of tables to open, so later those already opened and locked
621
  tables can be used during this function calculation for loading time zone
622
  descriptions.
623
*/
624
class Item_func_convert_tz :public Item_date_func
625
{
626
  /*
627
    If time zone parameters are constants we are caching objects that
628
    represent them (we use separate from_tz_cached/to_tz_cached members
629
    to indicate this fact, since NULL is legal value for from_tz/to_tz
630
    members.
631
  */
632
  bool from_tz_cached, to_tz_cached;
633
  Time_zone *from_tz, *to_tz;
634
 public:
635
  Item_func_convert_tz(Item *a, Item *b, Item *c):
636
    Item_date_func(a, b, c), from_tz_cached(0), to_tz_cached(0) {}
152 by Brian Aker
longlong replacement
637
  int64_t val_int();
1 by brian
clean slate
638
  String *val_str(String *str);
639
  const char *func_name() const { return "convert_tz"; }
640
  void fix_length_and_dec();
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
641
  bool get_date(DRIZZLE_TIME *res, uint fuzzy_date);
1 by brian
clean slate
642
  void cleanup();
643
};
644
645
646
class Item_func_sec_to_time :public Item_str_timefunc
647
{
648
public:
649
  Item_func_sec_to_time(Item *item) :Item_str_timefunc(item) {}
650
  double val_real()
651
  {
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
652
    assert(fixed == 1);
1 by brian
clean slate
653
    return (double) Item_func_sec_to_time::val_int();
654
  }
152 by Brian Aker
longlong replacement
655
  int64_t val_int();
1 by brian
clean slate
656
  String *val_str(String *);
657
  void fix_length_and_dec()
658
  { 
659
    Item_str_timefunc::fix_length_and_dec();
660
    collation.set(&my_charset_bin);
661
    maybe_null=1;
662
  }
663
  const char *func_name() const { return "sec_to_time"; }
152 by Brian Aker
longlong replacement
664
  bool result_as_int64_t() { return true; }
1 by brian
clean slate
665
};
666
667
668
class Item_date_add_interval :public Item_date_func
669
{
670
  String value;
671
  enum_field_types cached_field_type;
672
673
public:
674
  const interval_type int_type; // keep it public
675
  const bool date_sub_interval; // keep it public
676
  Item_date_add_interval(Item *a,Item *b,interval_type type_arg,bool neg_arg)
677
    :Item_date_func(a,b),int_type(type_arg), date_sub_interval(neg_arg) {}
678
  String *val_str(String *);
679
  const char *func_name() const { return "date_add_interval"; }
680
  void fix_length_and_dec();
681
  enum_field_types field_type() const { return cached_field_type; }
152 by Brian Aker
longlong replacement
682
  int64_t val_int();
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
683
  bool get_date(DRIZZLE_TIME *res, uint fuzzy_date);
1 by brian
clean slate
684
  bool eq(const Item *item, bool binary_cmp) const;
685
  virtual void print(String *str, enum_query_type query_type);
686
};
687
688
689
class Item_extract :public Item_int_func
690
{
691
  String value;
692
  bool date_value;
693
 public:
694
  const interval_type int_type; // keep it public
695
  Item_extract(interval_type type_arg, Item *a)
696
    :Item_int_func(a), int_type(type_arg) {}
152 by Brian Aker
longlong replacement
697
  int64_t val_int();
1 by brian
clean slate
698
  enum Functype functype() const { return EXTRACT_FUNC; }
699
  const char *func_name() const { return "extract"; }
700
  void fix_length_and_dec();
701
  bool eq(const Item *item, bool binary_cmp) const;
702
  virtual void print(String *str, enum_query_type query_type);
703
};
704
705
706
class Item_typecast :public Item_str_func
707
{
708
public:
709
  Item_typecast(Item *a) :Item_str_func(a) {}
710
  String *val_str(String *a)
711
  {
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
712
    assert(fixed == 1);
1 by brian
clean slate
713
    String *tmp=args[0]->val_str(a);
714
    null_value=args[0]->null_value;
715
    if (tmp)
716
      tmp->set_charset(collation.collation);
717
    return tmp;
718
  }
719
  void fix_length_and_dec()
720
  {
721
    collation.set(&my_charset_bin);
722
    max_length=args[0]->max_length;
723
  }
724
  virtual const char* cast_type() const= 0;
725
  virtual void print(String *str, enum_query_type query_type);
726
};
727
728
729
class Item_typecast_maybe_null :public Item_typecast
730
{
731
public:
732
  Item_typecast_maybe_null(Item *a) :Item_typecast(a) {}
733
  void fix_length_and_dec()
734
  {
735
    collation.set(&my_charset_bin);
736
    max_length=args[0]->max_length;
737
    maybe_null= 1;
738
  }
739
};
740
741
742
class Item_char_typecast :public Item_typecast
743
{
744
  int cast_length;
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
745
  const CHARSET_INFO *cast_cs, *from_cs;
1 by brian
clean slate
746
  bool charset_conversion;
747
  String tmp_value;
748
public:
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
749
  Item_char_typecast(Item *a, int length_arg, const CHARSET_INFO * const cs_arg)
1 by brian
clean slate
750
    :Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {}
751
  enum Functype functype() const { return CHAR_TYPECAST_FUNC; }
752
  bool eq(const Item *item, bool binary_cmp) const;
753
  const char *func_name() const { return "cast_as_char"; }
754
  const char* cast_type() const { return "char"; };
755
  String *val_str(String *a);
756
  void fix_length_and_dec();
757
  virtual void print(String *str, enum_query_type query_type);
758
};
759
760
761
class Item_date_typecast :public Item_typecast_maybe_null
762
{
763
public:
764
  Item_date_typecast(Item *a) :Item_typecast_maybe_null(a) {}
765
  const char *func_name() const { return "cast_as_date"; }
766
  String *val_str(String *str);
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
767
  bool get_date(DRIZZLE_TIME *ltime, uint fuzzy_date);
768
  bool get_time(DRIZZLE_TIME *ltime);
1 by brian
clean slate
769
  const char *cast_type() const { return "date"; }
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
770
  enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
1 by brian
clean slate
771
  Field *tmp_table_field(TABLE *table)
772
  {
773
    return tmp_table_field_from_field_type(table, 0);
774
  }  
775
  void fix_length_and_dec()
776
  {
777
    collation.set(&my_charset_bin);
778
    max_length= 10;
779
    maybe_null= 1;
780
  }
152 by Brian Aker
longlong replacement
781
  bool result_as_int64_t() { return true; }
782
  int64_t val_int();
1 by brian
clean slate
783
  double val_real() { return (double) val_int(); }
784
  my_decimal *val_decimal(my_decimal *decimal_value)
785
  {
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
786
    assert(fixed == 1);
1 by brian
clean slate
787
    return  val_decimal_from_date(decimal_value);
788
  }
77.1.7 by Monty Taylor
Heap builds clean.
789
  int save_in_field(Field *field,
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
790
                    bool no_conversions __attribute__((unused)))
1 by brian
clean slate
791
  {
792
    return save_date_in_field(field);
793
  }
794
};
795
796
797
class Item_time_typecast :public Item_typecast_maybe_null
798
{
799
public:
800
  Item_time_typecast(Item *a) :Item_typecast_maybe_null(a) {}
801
  const char *func_name() const { return "cast_as_time"; }
802
  String *val_str(String *str);
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
803
  bool get_time(DRIZZLE_TIME *ltime);
1 by brian
clean slate
804
  const char *cast_type() const { return "time"; }
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
805
  enum_field_types field_type() const { return DRIZZLE_TYPE_TIME; }
1 by brian
clean slate
806
  Field *tmp_table_field(TABLE *table)
807
  {
808
    return tmp_table_field_from_field_type(table, 0);
809
  }
152 by Brian Aker
longlong replacement
810
  bool result_as_int64_t() { return true; }
811
  int64_t val_int();
1 by brian
clean slate
812
  double val_real() { return val_real_from_decimal(); }
813
  my_decimal *val_decimal(my_decimal *decimal_value)
814
  {
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
815
    assert(fixed == 1);
1 by brian
clean slate
816
    return  val_decimal_from_time(decimal_value);
817
  }
77.1.7 by Monty Taylor
Heap builds clean.
818
  int save_in_field(Field *field,
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
819
                    bool no_conversions __attribute__((unused)))
1 by brian
clean slate
820
  {
821
    return save_time_in_field(field);
822
  }
823
};
824
825
826
class Item_datetime_typecast :public Item_typecast_maybe_null
827
{
828
public:
829
  Item_datetime_typecast(Item *a) :Item_typecast_maybe_null(a) {}
830
  const char *func_name() const { return "cast_as_datetime"; }
831
  String *val_str(String *str);
832
  const char *cast_type() const { return "datetime"; }
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
833
  enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
1 by brian
clean slate
834
  Field *tmp_table_field(TABLE *table)
835
  {
836
    return tmp_table_field_from_field_type(table, 0);
837
  }
838
  void fix_length_and_dec()
839
  {
840
    collation.set(&my_charset_bin);
841
    maybe_null= 1;
842
    max_length= MAX_DATETIME_FULL_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
843
    decimals= DATETIME_DEC;
844
  }
152 by Brian Aker
longlong replacement
845
  bool result_as_int64_t() { return true; }
846
  int64_t val_int();
1 by brian
clean slate
847
  double val_real() { return val_real_from_decimal(); }
848
  double val() { return (double) val_int(); }
849
  my_decimal *val_decimal(my_decimal *decimal_value)
850
  {
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
851
    assert(fixed == 1);
1 by brian
clean slate
852
    return  val_decimal_from_date(decimal_value);
853
  }
77.1.7 by Monty Taylor
Heap builds clean.
854
  int save_in_field(Field *field,
212.1.3 by Monty Taylor
Renamed __attribute__((__unused__)) to __attribute__((unused)).
855
                    bool no_conversions __attribute__((unused)))
1 by brian
clean slate
856
  {
857
    return save_date_in_field(field);
858
  }
859
};
860
861
class Item_func_makedate :public Item_date_func
862
{
863
public:
864
  Item_func_makedate(Item *a,Item *b) :Item_date_func(a,b) {}
865
  String *val_str(String *str);
866
  const char *func_name() const { return "makedate"; }
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
867
  enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
1 by brian
clean slate
868
  void fix_length_and_dec()
869
  { 
870
    decimals=0;
871
    max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
872
  }
152 by Brian Aker
longlong replacement
873
  int64_t val_int();
1 by brian
clean slate
874
};
875
876
877
class Item_func_add_time :public Item_str_func
878
{
879
  const bool is_date;
880
  int sign;
881
  enum_field_types cached_field_type;
882
883
public:
884
  Item_func_add_time(Item *a, Item *b, bool type_arg, bool neg_arg)
885
    :Item_str_func(a, b), is_date(type_arg) { sign= neg_arg ? -1 : 1; }
886
  String *val_str(String *str);
887
  enum_field_types field_type() const { return cached_field_type; }
888
  void fix_length_and_dec();
889
890
  Field *tmp_table_field(TABLE *table)
891
  {
892
    return tmp_table_field_from_field_type(table, 0);
893
  }
894
  virtual void print(String *str, enum_query_type query_type);
895
  const char *func_name() const { return "add_time"; }
896
  double val_real() { return val_real_from_decimal(); }
897
  my_decimal *val_decimal(my_decimal *decimal_value)
898
  {
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
899
    assert(fixed == 1);
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
900
    if (cached_field_type == DRIZZLE_TYPE_TIME)
1 by brian
clean slate
901
      return  val_decimal_from_time(decimal_value);
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
902
    if (cached_field_type == DRIZZLE_TYPE_DATETIME)
1 by brian
clean slate
903
      return  val_decimal_from_date(decimal_value);
904
    return Item_str_func::val_decimal(decimal_value);
905
  }
906
  int save_in_field(Field *field, bool no_conversions)
907
  {
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
908
    if (cached_field_type == DRIZZLE_TYPE_TIME)
1 by brian
clean slate
909
      return save_time_in_field(field);
212.2.2 by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE
910
    if (cached_field_type == DRIZZLE_TYPE_DATETIME)
1 by brian
clean slate
911
      return save_date_in_field(field);
912
    return Item_str_func::save_in_field(field, no_conversions);
913
  }
914
};
915
916
class Item_func_timediff :public Item_str_timefunc
917
{
918
public:
919
  Item_func_timediff(Item *a, Item *b)
920
    :Item_str_timefunc(a, b) {}
921
  String *val_str(String *str);
922
  const char *func_name() const { return "timediff"; }
923
  void fix_length_and_dec()
924
  {
925
    Item_str_timefunc::fix_length_and_dec();
926
    maybe_null= 1;
927
  }
928
};
929
930
class Item_func_maketime :public Item_str_timefunc
931
{
932
public:
933
  Item_func_maketime(Item *a, Item *b, Item *c)
934
    :Item_str_timefunc(a, b, c) 
935
  {
51.1.26 by Jay Pipes
Removed DBUG symbols and fixed TRUE/FALSE
936
    maybe_null= true;
1 by brian
clean slate
937
  }
938
  String *val_str(String *str);
939
  const char *func_name() const { return "maketime"; }
940
};
941
942
class Item_func_microsecond :public Item_int_func
943
{
944
public:
945
  Item_func_microsecond(Item *a) :Item_int_func(a) {}
152 by Brian Aker
longlong replacement
946
  int64_t val_int();
1 by brian
clean slate
947
  const char *func_name() const { return "microsecond"; }
948
  void fix_length_and_dec() 
949
  { 
950
    decimals=0;
951
    maybe_null=1;
952
  }
953
};
954
955
956
class Item_func_timestamp_diff :public Item_int_func
957
{
958
  const interval_type int_type;
959
public:
960
  Item_func_timestamp_diff(Item *a,Item *b,interval_type type_arg)
961
    :Item_int_func(a,b), int_type(type_arg) {}
962
  const char *func_name() const { return "timestampdiff"; }
152 by Brian Aker
longlong replacement
963
  int64_t val_int();
1 by brian
clean slate
964
  void fix_length_and_dec()
965
  {
966
    decimals=0;
967
    maybe_null=1;
968
  }
969
  virtual void print(String *str, enum_query_type query_type);
970
};
971
972
973
enum date_time_format
974
{
975
  USA_FORMAT, JIS_FORMAT, ISO_FORMAT, EUR_FORMAT, INTERNAL_FORMAT
976
};
977
978
class Item_func_get_format :public Item_str_func
979
{
980
public:
981
  const timestamp_type type; // keep it public
982
  Item_func_get_format(timestamp_type type_arg, Item *a)
983
    :Item_str_func(a), type(type_arg)
984
  {}
985
  String *val_str(String *str);
986
  const char *func_name() const { return "get_format"; }
987
  void fix_length_and_dec()
988
  {
989
    maybe_null= 1;
990
    decimals=0;
991
    max_length=17*MY_CHARSET_BIN_MB_MAXLEN;
992
  }
993
  virtual void print(String *str, enum_query_type query_type);
994
};
995
996
997
class Item_func_str_to_date :public Item_str_func
998
{
999
  enum_field_types cached_field_type;
1000
  date_time_format_types cached_format_type;
1001
  timestamp_type cached_timestamp_type;
1002
  bool const_item;
1003
public:
1004
  Item_func_str_to_date(Item *a, Item *b)
1005
    :Item_str_func(a, b), const_item(false)
1006
  {}
1007
  String *val_str(String *str);
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
1008
  bool get_date(DRIZZLE_TIME *ltime, uint fuzzy_date);
1 by brian
clean slate
1009
  const char *func_name() const { return "str_to_date"; }
1010
  enum_field_types field_type() const { return cached_field_type; }
1011
  void fix_length_and_dec();
1012
  Field *tmp_table_field(TABLE *table)
1013
  {
1014
    return tmp_table_field_from_field_type(table, 1);
1015
  }
1016
};
1017
1018
1019
class Item_func_last_day :public Item_date
1020
{
1021
public:
1022
  Item_func_last_day(Item *a) :Item_date(a) {}
1023
  const char *func_name() const { return "last_day"; }
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
1024
  bool get_date(DRIZZLE_TIME *res, uint fuzzy_date);
1 by brian
clean slate
1025
};