1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
/* Function items used by mysql */
23
#ifdef USE_PRAGMA_INTERFACE
24
#pragma interface /* gcc class implementation */
27
enum date_time_format_types
29
TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND
32
bool get_interval_value(Item *args,interval_type int_type,
33
String *str_value, INTERVAL *interval);
35
class Item_func_period_add :public Item_int_func
38
Item_func_period_add(Item *a,Item *b) :Item_int_func(a,b) {}
40
const char *func_name() const { return "period_add"; }
41
void fix_length_and_dec()
43
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
48
class Item_func_period_diff :public Item_int_func
51
Item_func_period_diff(Item *a,Item *b) :Item_int_func(a,b) {}
53
const char *func_name() const { return "period_diff"; }
54
void fix_length_and_dec()
57
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
62
class Item_func_to_days :public Item_int_func
65
Item_func_to_days(Item *a) :Item_int_func(a) {}
67
const char *func_name() const { return "to_days"; }
68
void fix_length_and_dec()
71
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
74
enum_monotonicity_info get_monotonicity_info() const;
75
int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
79
class Item_func_dayofmonth :public Item_int_func
82
Item_func_dayofmonth(Item *a) :Item_int_func(a) {}
84
const char *func_name() const { return "dayofmonth"; }
85
void fix_length_and_dec()
88
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
94
class Item_func_month :public Item_func
97
Item_func_month(Item *a) :Item_func(a) {}
100
{ assert(fixed == 1); return (double) Item_func_month::val_int(); }
101
String *val_str(String *str)
103
str->set(val_int(), &my_charset_bin);
104
return null_value ? 0 : str;
106
const char *func_name() const { return "month"; }
107
enum Item_result result_type () const { return INT_RESULT; }
108
void fix_length_and_dec()
110
collation.set(&my_charset_bin);
112
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
118
class Item_func_monthname :public Item_func_month
121
Item_func_monthname(Item *a) :Item_func_month(a) {}
122
const char *func_name() const { return "monthname"; }
123
String *val_str(String *str);
124
enum Item_result result_type () const { return STRING_RESULT; }
125
void fix_length_and_dec()
127
collation.set(&my_charset_bin);
129
max_length=10*my_charset_bin.mbmaxlen;
135
class Item_func_dayofyear :public Item_int_func
138
Item_func_dayofyear(Item *a) :Item_int_func(a) {}
140
const char *func_name() const { return "dayofyear"; }
141
void fix_length_and_dec()
144
max_length=3*MY_CHARSET_BIN_MB_MAXLEN;
150
class Item_func_hour :public Item_int_func
153
Item_func_hour(Item *a) :Item_int_func(a) {}
155
const char *func_name() const { return "hour"; }
156
void fix_length_and_dec()
159
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
165
class Item_func_minute :public Item_int_func
168
Item_func_minute(Item *a) :Item_int_func(a) {}
170
const char *func_name() const { return "minute"; }
171
void fix_length_and_dec()
174
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
180
class Item_func_quarter :public Item_int_func
183
Item_func_quarter(Item *a) :Item_int_func(a) {}
185
const char *func_name() const { return "quarter"; }
186
void fix_length_and_dec()
189
max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
195
class Item_func_second :public Item_int_func
198
Item_func_second(Item *a) :Item_int_func(a) {}
200
const char *func_name() const { return "second"; }
201
void fix_length_and_dec()
204
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
210
class Item_func_week :public Item_int_func
213
Item_func_week(Item *a,Item *b) :Item_int_func(a,b) {}
215
const char *func_name() const { return "week"; }
216
void fix_length_and_dec()
219
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
224
class Item_func_yearweek :public Item_int_func
227
Item_func_yearweek(Item *a,Item *b) :Item_int_func(a,b) {}
229
const char *func_name() const { return "yearweek"; }
230
void fix_length_and_dec()
233
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
239
class Item_func_year :public Item_int_func
242
Item_func_year(Item *a) :Item_int_func(a) {}
244
const char *func_name() const { return "year"; }
245
enum_monotonicity_info get_monotonicity_info() const;
246
int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
247
void fix_length_and_dec()
250
max_length=4*MY_CHARSET_BIN_MB_MAXLEN;
256
class Item_func_weekday :public Item_func
260
Item_func_weekday(Item *a,bool type_arg)
261
:Item_func(a), odbc_type(type_arg) {}
263
double val_real() { assert(fixed == 1); return (double) val_int(); }
264
String *val_str(String *str)
267
str->set(val_int(), &my_charset_bin);
268
return null_value ? 0 : str;
270
const char *func_name() const
272
return (odbc_type ? "dayofweek" : "weekday");
274
enum Item_result result_type () const { return INT_RESULT; }
275
void fix_length_and_dec()
277
collation.set(&my_charset_bin);
279
max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
284
class Item_func_dayname :public Item_func_weekday
287
Item_func_dayname(Item *a) :Item_func_weekday(a,0) {}
288
const char *func_name() const { return "dayname"; }
289
String *val_str(String *str);
290
enum Item_result result_type () const { return STRING_RESULT; }
291
void fix_length_and_dec()
293
collation.set(&my_charset_bin);
295
max_length=9*MY_CHARSET_BIN_MB_MAXLEN;
301
class Item_func_unix_timestamp :public Item_int_func
305
Item_func_unix_timestamp() :Item_int_func() {}
306
Item_func_unix_timestamp(Item *a) :Item_int_func(a) {}
308
const char *func_name() const { return "unix_timestamp"; }
309
void fix_length_and_dec()
312
max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
317
class Item_func_time_to_sec :public Item_int_func
320
Item_func_time_to_sec(Item *item) :Item_int_func(item) {}
322
const char *func_name() const { return "time_to_sec"; }
323
void fix_length_and_dec()
326
max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
332
This can't be a Item_str_func, because the val_real() functions are special
335
class Item_date :public Item_func
338
Item_date() :Item_func() {}
339
Item_date(Item *a) :Item_func(a) {}
340
enum Item_result result_type () const { return STRING_RESULT; }
341
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
342
String *val_str(String *str);
344
double val_real() { return val_real_from_decimal(); }
345
const char *func_name() const { return "date"; }
346
void fix_length_and_dec()
348
collation.set(&my_charset_bin);
350
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
352
Field *tmp_table_field(Table *table)
354
return tmp_table_field_from_field_type(table, 0);
356
bool result_as_int64_t() { return true; }
357
my_decimal *val_decimal(my_decimal *decimal_value)
360
return val_decimal_from_date(decimal_value);
362
int save_in_field(Field *field,
363
bool no_conversions __attribute__((unused)))
365
return save_date_in_field(field);
370
class Item_date_func :public Item_str_func
373
Item_date_func() :Item_str_func() {}
374
Item_date_func(Item *a) :Item_str_func(a) {}
375
Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {}
376
Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {}
377
enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
378
Field *tmp_table_field(Table *table)
380
return tmp_table_field_from_field_type(table, 0);
382
bool result_as_int64_t() { return true; }
383
double val_real() { return (double) val_int(); }
384
my_decimal *val_decimal(my_decimal *decimal_value)
387
return val_decimal_from_date(decimal_value);
389
int save_in_field(Field *field,
390
bool no_conversions __attribute__((unused)))
392
return save_date_in_field(field);
397
class Item_str_timefunc :public Item_str_func
400
Item_str_timefunc() :Item_str_func() {}
401
Item_str_timefunc(Item *a) :Item_str_func(a) {}
402
Item_str_timefunc(Item *a,Item *b) :Item_str_func(a,b) {}
403
Item_str_timefunc(Item *a, Item *b, Item *c) :Item_str_func(a, b ,c) {}
404
enum_field_types field_type() const { return DRIZZLE_TYPE_TIME; }
405
void fix_length_and_dec()
407
decimals= DATETIME_DEC;
408
max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
410
Field *tmp_table_field(Table *table)
412
return tmp_table_field_from_field_type(table, 0);
414
double val_real() { return val_real_from_decimal(); }
415
my_decimal *val_decimal(my_decimal *decimal_value)
418
return val_decimal_from_time(decimal_value);
420
int save_in_field(Field *field,
421
bool no_conversions __attribute__((unused)))
423
return save_time_in_field(field);
428
/* Abstract CURTIME function. Children should define what time zone is used */
430
class Item_func_curtime :public Item_str_timefunc
434
uint32_t buff_length;
436
Item_func_curtime() :Item_str_timefunc() {}
437
Item_func_curtime(Item *a) :Item_str_timefunc(a) {}
438
double val_real() { assert(fixed == 1); return (double) value; }
439
int64_t val_int() { assert(fixed == 1); return value; }
440
String *val_str(String *str);
441
void fix_length_and_dec();
443
Abstract method that defines which time zone is used for conversion.
444
Converts time current time in my_time_t representation to broken-down
445
DRIZZLE_TIME representation using UTC-SYSTEM or per-thread time zone.
447
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
448
bool result_as_int64_t() { return true; }
452
class Item_func_curtime_local :public Item_func_curtime
455
Item_func_curtime_local() :Item_func_curtime() {}
456
Item_func_curtime_local(Item *a) :Item_func_curtime(a) {}
457
const char *func_name() const { return "curtime"; }
458
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
462
class Item_func_curtime_utc :public Item_func_curtime
465
Item_func_curtime_utc() :Item_func_curtime() {}
466
Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {}
467
const char *func_name() const { return "utc_time"; }
468
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
472
/* Abstract CURDATE function. See also Item_func_curtime. */
474
class Item_func_curdate :public Item_date
479
Item_func_curdate() :Item_date() {}
480
int64_t val_int() { assert(fixed == 1); return (value) ; }
481
String *val_str(String *str);
482
void fix_length_and_dec();
483
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
484
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
488
class Item_func_curdate_local :public Item_func_curdate
491
Item_func_curdate_local() :Item_func_curdate() {}
492
const char *func_name() const { return "curdate"; }
493
void store_now_in_TIME(DRIZZLE_TIME *now_time);
497
class Item_func_curdate_utc :public Item_func_curdate
500
Item_func_curdate_utc() :Item_func_curdate() {}
501
const char *func_name() const { return "utc_date"; }
502
void store_now_in_TIME(DRIZZLE_TIME *now_time);
506
/* Abstract CURRENT_TIMESTAMP function. See also Item_func_curtime */
508
class Item_func_now :public Item_date_func
512
char buff[20*2+32]; // +32 to make my_snprintf_{8bit|ucs2} happy
513
uint32_t buff_length;
516
Item_func_now() :Item_date_func() {}
517
Item_func_now(Item *a) :Item_date_func(a) {}
518
enum Item_result result_type () const { return STRING_RESULT; }
519
int64_t val_int() { assert(fixed == 1); return value; }
520
int save_in_field(Field *to, bool no_conversions);
521
String *val_str(String *str);
522
void fix_length_and_dec();
523
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
524
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time)=0;
528
class Item_func_now_local :public Item_func_now
531
Item_func_now_local() :Item_func_now() {}
532
Item_func_now_local(Item *a) :Item_func_now(a) {}
533
const char *func_name() const { return "now"; }
534
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
535
virtual enum Functype functype() const { return NOW_FUNC; }
539
class Item_func_now_utc :public Item_func_now
542
Item_func_now_utc() :Item_func_now() {}
543
Item_func_now_utc(Item *a) :Item_func_now(a) {}
544
const char *func_name() const { return "utc_timestamp"; }
545
virtual void store_now_in_TIME(DRIZZLE_TIME *now_time);
550
This is like NOW(), but always uses the real current time, not the
551
query_start(). This matches the Oracle behavior.
553
class Item_func_sysdate_local :public Item_func_now
556
Item_func_sysdate_local() :Item_func_now() {}
557
Item_func_sysdate_local(Item *a) :Item_func_now(a) {}
558
bool const_item() const { return 0; }
559
const char *func_name() const { return "sysdate"; }
560
void store_now_in_TIME(DRIZZLE_TIME *now_time);
563
int save_in_field(Field *to, bool no_conversions);
564
String *val_str(String *str);
565
void fix_length_and_dec();
566
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
567
void update_used_tables()
569
Item_func_now::update_used_tables();
570
used_tables_cache|= RAND_TABLE_BIT;
575
class Item_func_from_days :public Item_date
578
Item_func_from_days(Item *a) :Item_date(a) {}
579
const char *func_name() const { return "from_days"; }
580
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
584
class Item_func_date_format :public Item_str_func
587
const bool is_time_format;
590
Item_func_date_format(Item *a,Item *b,bool is_time_format_arg)
591
:Item_str_func(a,b),is_time_format(is_time_format_arg) {}
592
String *val_str(String *str);
593
const char *func_name() const
594
{ return is_time_format ? "time_format" : "date_format"; }
595
void fix_length_and_dec();
596
uint32_t format_length(const String *format);
597
bool eq(const Item *item, bool binary_cmp) const;
601
class Item_func_from_unixtime :public Item_date_func
605
Item_func_from_unixtime(Item *a) :Item_date_func(a) {}
607
String *val_str(String *str);
608
const char *func_name() const { return "from_unixtime"; }
609
void fix_length_and_dec();
610
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
615
We need Time_zone class declaration for storing pointers in
616
Item_func_convert_tz.
621
This class represents CONVERT_TZ() function.
622
The important fact about this function that it is handled in special way.
623
When such function is met in expression time_zone system tables are added
624
to global list of tables to open, so later those already opened and locked
625
tables can be used during this function calculation for loading time zone
628
class Item_func_convert_tz :public Item_date_func
631
If time zone parameters are constants we are caching objects that
632
represent them (we use separate from_tz_cached/to_tz_cached members
633
to indicate this fact, since NULL is legal value for from_tz/to_tz
636
bool from_tz_cached, to_tz_cached;
637
Time_zone *from_tz, *to_tz;
639
Item_func_convert_tz(Item *a, Item *b, Item *c):
640
Item_date_func(a, b, c), from_tz_cached(0), to_tz_cached(0) {}
642
String *val_str(String *str);
643
const char *func_name() const { return "convert_tz"; }
644
void fix_length_and_dec();
645
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
650
class Item_func_sec_to_time :public Item_str_timefunc
653
Item_func_sec_to_time(Item *item) :Item_str_timefunc(item) {}
657
return (double) Item_func_sec_to_time::val_int();
660
String *val_str(String *);
661
void fix_length_and_dec()
663
Item_str_timefunc::fix_length_and_dec();
664
collation.set(&my_charset_bin);
667
const char *func_name() const { return "sec_to_time"; }
668
bool result_as_int64_t() { return true; }
672
class Item_date_add_interval :public Item_date_func
675
enum_field_types cached_field_type;
678
const interval_type int_type; // keep it public
679
const bool date_sub_interval; // keep it public
680
Item_date_add_interval(Item *a,Item *b,interval_type type_arg,bool neg_arg)
681
:Item_date_func(a,b),int_type(type_arg), date_sub_interval(neg_arg) {}
682
String *val_str(String *);
683
const char *func_name() const { return "date_add_interval"; }
684
void fix_length_and_dec();
685
enum_field_types field_type() const { return cached_field_type; }
687
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);
688
bool eq(const Item *item, bool binary_cmp) const;
689
virtual void print(String *str, enum_query_type query_type);
693
class Item_extract :public Item_int_func
698
const interval_type int_type; // keep it public
699
Item_extract(interval_type type_arg, Item *a)
700
:Item_int_func(a), int_type(type_arg) {}
702
enum Functype functype() const { return EXTRACT_FUNC; }
703
const char *func_name() const { return "extract"; }
704
void fix_length_and_dec();
705
bool eq(const Item *item, bool binary_cmp) const;
706
virtual void print(String *str, enum_query_type query_type);
710
class Item_typecast :public Item_str_func
713
Item_typecast(Item *a) :Item_str_func(a) {}
714
String *val_str(String *a)
717
String *tmp=args[0]->val_str(a);
718
null_value=args[0]->null_value;
720
tmp->set_charset(collation.collation);
723
void fix_length_and_dec()
725
collation.set(&my_charset_bin);
726
max_length=args[0]->max_length;
728
virtual const char* cast_type() const= 0;
729
virtual void print(String *str, enum_query_type query_type);
733
class Item_typecast_maybe_null :public Item_typecast
736
Item_typecast_maybe_null(Item *a) :Item_typecast(a) {}
737
void fix_length_and_dec()
739
collation.set(&my_charset_bin);
740
max_length=args[0]->max_length;
746
class Item_char_typecast :public Item_typecast
749
const CHARSET_INFO *cast_cs, *from_cs;
750
bool charset_conversion;
753
Item_char_typecast(Item *a, int length_arg, const CHARSET_INFO * const cs_arg)
754
:Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {}
755
enum Functype functype() const { return CHAR_TYPECAST_FUNC; }
756
bool eq(const Item *item, bool binary_cmp) const;
757
const char *func_name() const { return "cast_as_char"; }
758
const char* cast_type() const { return "char"; };
759
String *val_str(String *a);
760
void fix_length_and_dec();
761
virtual void print(String *str, enum_query_type query_type);
765
class Item_date_typecast :public Item_typecast_maybe_null
768
Item_date_typecast(Item *a) :Item_typecast_maybe_null(a) {}
769
const char *func_name() const { return "cast_as_date"; }
770
String *val_str(String *str);
771
bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
772
bool get_time(DRIZZLE_TIME *ltime);
773
const char *cast_type() const { return "date"; }
774
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
775
Field *tmp_table_field(Table *table)
777
return tmp_table_field_from_field_type(table, 0);
779
void fix_length_and_dec()
781
collation.set(&my_charset_bin);
785
bool result_as_int64_t() { return true; }
787
double val_real() { return (double) val_int(); }
788
my_decimal *val_decimal(my_decimal *decimal_value)
791
return val_decimal_from_date(decimal_value);
793
int save_in_field(Field *field,
794
bool no_conversions __attribute__((unused)))
796
return save_date_in_field(field);
801
class Item_time_typecast :public Item_typecast_maybe_null
804
Item_time_typecast(Item *a) :Item_typecast_maybe_null(a) {}
805
const char *func_name() const { return "cast_as_time"; }
806
String *val_str(String *str);
807
bool get_time(DRIZZLE_TIME *ltime);
808
const char *cast_type() const { return "time"; }
809
enum_field_types field_type() const { return DRIZZLE_TYPE_TIME; }
810
Field *tmp_table_field(Table *table)
812
return tmp_table_field_from_field_type(table, 0);
814
bool result_as_int64_t() { return true; }
816
double val_real() { return val_real_from_decimal(); }
817
my_decimal *val_decimal(my_decimal *decimal_value)
820
return val_decimal_from_time(decimal_value);
822
int save_in_field(Field *field,
823
bool no_conversions __attribute__((unused)))
825
return save_time_in_field(field);
830
class Item_datetime_typecast :public Item_typecast_maybe_null
833
Item_datetime_typecast(Item *a) :Item_typecast_maybe_null(a) {}
834
const char *func_name() const { return "cast_as_datetime"; }
835
String *val_str(String *str);
836
const char *cast_type() const { return "datetime"; }
837
enum_field_types field_type() const { return DRIZZLE_TYPE_DATETIME; }
838
Field *tmp_table_field(Table *table)
840
return tmp_table_field_from_field_type(table, 0);
842
void fix_length_and_dec()
844
collation.set(&my_charset_bin);
846
max_length= MAX_DATETIME_FULL_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
847
decimals= DATETIME_DEC;
849
bool result_as_int64_t() { return true; }
851
double val_real() { return val_real_from_decimal(); }
852
double val() { return (double) val_int(); }
853
my_decimal *val_decimal(my_decimal *decimal_value)
856
return val_decimal_from_date(decimal_value);
858
int save_in_field(Field *field,
859
bool no_conversions __attribute__((unused)))
861
return save_date_in_field(field);
865
class Item_func_makedate :public Item_date_func
868
Item_func_makedate(Item *a,Item *b) :Item_date_func(a,b) {}
869
String *val_str(String *str);
870
const char *func_name() const { return "makedate"; }
871
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDATE; }
872
void fix_length_and_dec()
875
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
881
class Item_func_add_time :public Item_str_func
885
enum_field_types cached_field_type;
888
Item_func_add_time(Item *a, Item *b, bool type_arg, bool neg_arg)
889
:Item_str_func(a, b), is_date(type_arg) { sign= neg_arg ? -1 : 1; }
890
String *val_str(String *str);
891
enum_field_types field_type() const { return cached_field_type; }
892
void fix_length_and_dec();
894
Field *tmp_table_field(Table *table)
896
return tmp_table_field_from_field_type(table, 0);
898
virtual void print(String *str, enum_query_type query_type);
899
const char *func_name() const { return "add_time"; }
900
double val_real() { return val_real_from_decimal(); }
901
my_decimal *val_decimal(my_decimal *decimal_value)
904
if (cached_field_type == DRIZZLE_TYPE_TIME)
905
return val_decimal_from_time(decimal_value);
906
if (cached_field_type == DRIZZLE_TYPE_DATETIME)
907
return val_decimal_from_date(decimal_value);
908
return Item_str_func::val_decimal(decimal_value);
910
int save_in_field(Field *field, bool no_conversions)
912
if (cached_field_type == DRIZZLE_TYPE_TIME)
913
return save_time_in_field(field);
914
if (cached_field_type == DRIZZLE_TYPE_DATETIME)
915
return save_date_in_field(field);
916
return Item_str_func::save_in_field(field, no_conversions);
920
class Item_func_timediff :public Item_str_timefunc
923
Item_func_timediff(Item *a, Item *b)
924
:Item_str_timefunc(a, b) {}
925
String *val_str(String *str);
926
const char *func_name() const { return "timediff"; }
927
void fix_length_and_dec()
929
Item_str_timefunc::fix_length_and_dec();
934
class Item_func_maketime :public Item_str_timefunc
937
Item_func_maketime(Item *a, Item *b, Item *c)
938
:Item_str_timefunc(a, b, c)
942
String *val_str(String *str);
943
const char *func_name() const { return "maketime"; }
946
class Item_func_microsecond :public Item_int_func
949
Item_func_microsecond(Item *a) :Item_int_func(a) {}
951
const char *func_name() const { return "microsecond"; }
952
void fix_length_and_dec()
960
class Item_func_timestamp_diff :public Item_int_func
962
const interval_type int_type;
964
Item_func_timestamp_diff(Item *a,Item *b,interval_type type_arg)
965
:Item_int_func(a,b), int_type(type_arg) {}
966
const char *func_name() const { return "timestampdiff"; }
968
void fix_length_and_dec()
973
virtual void print(String *str, enum_query_type query_type);
977
enum date_time_format
979
USA_FORMAT, JIS_FORMAT, ISO_FORMAT, EUR_FORMAT, INTERNAL_FORMAT
982
class Item_func_get_format :public Item_str_func
985
const enum enum_drizzle_timestamp_type type; // keep it public
986
Item_func_get_format(enum enum_drizzle_timestamp_type type_arg, Item *a)
987
:Item_str_func(a), type(type_arg)
989
String *val_str(String *str);
990
const char *func_name() const { return "get_format"; }
991
void fix_length_and_dec()
995
max_length=17*MY_CHARSET_BIN_MB_MAXLEN;
997
virtual void print(String *str, enum_query_type query_type);
1001
class Item_func_str_to_date :public Item_str_func
1003
enum_field_types cached_field_type;
1004
date_time_format_types cached_format_type;
1005
enum enum_drizzle_timestamp_type cached_timestamp_type;
1008
Item_func_str_to_date(Item *a, Item *b)
1009
:Item_str_func(a, b), const_item(false)
1011
String *val_str(String *str);
1012
bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzy_date);
1013
const char *func_name() const { return "str_to_date"; }
1014
enum_field_types field_type() const { return cached_field_type; }
1015
void fix_length_and_dec();
1016
Field *tmp_table_field(Table *table)
1018
return tmp_table_field_from_field_type(table, 1);
1023
class Item_func_last_day :public Item_date
1026
Item_func_last_day(Item *a) :Item_date(a) {}
1027
const char *func_name() const { return "last_day"; }
1028
bool get_date(DRIZZLE_TIME *res, uint32_t fuzzy_date);