1
/* Copyright (C) 2000-2006 MySQL AB
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.
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.
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 */
17
/* Function items used by mysql */
19
#ifdef USE_PRAGMA_INTERFACE
20
#pragma interface /* gcc class implementation */
23
enum date_time_format_types
25
TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND
28
bool get_interval_value(Item *args,interval_type int_type,
29
String *str_value, INTERVAL *interval);
31
class Item_func_period_add :public Item_int_func
34
Item_func_period_add(Item *a,Item *b) :Item_int_func(a,b) {}
36
const char *func_name() const { return "period_add"; }
37
void fix_length_and_dec()
39
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
44
class Item_func_period_diff :public Item_int_func
47
Item_func_period_diff(Item *a,Item *b) :Item_int_func(a,b) {}
49
const char *func_name() const { return "period_diff"; }
50
void fix_length_and_dec()
53
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
58
class Item_func_to_days :public Item_int_func
61
Item_func_to_days(Item *a) :Item_int_func(a) {}
63
const char *func_name() const { return "to_days"; }
64
void fix_length_and_dec()
67
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
70
enum_monotonicity_info get_monotonicity_info() const;
71
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
75
class Item_func_dayofmonth :public Item_int_func
78
Item_func_dayofmonth(Item *a) :Item_int_func(a) {}
80
const char *func_name() const { return "dayofmonth"; }
81
void fix_length_and_dec()
84
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
90
class Item_func_month :public Item_func
93
Item_func_month(Item *a) :Item_func(a) {}
96
{ DBUG_ASSERT(fixed == 1); return (double) Item_func_month::val_int(); }
97
String *val_str(String *str)
99
str->set(val_int(), &my_charset_bin);
100
return null_value ? 0 : str;
102
const char *func_name() const { return "month"; }
103
enum Item_result result_type () const { return INT_RESULT; }
104
void fix_length_and_dec()
106
collation.set(&my_charset_bin);
108
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
114
class Item_func_monthname :public Item_func_month
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()
123
collation.set(&my_charset_bin);
125
max_length=10*my_charset_bin.mbmaxlen;
131
class Item_func_dayofyear :public Item_int_func
134
Item_func_dayofyear(Item *a) :Item_int_func(a) {}
136
const char *func_name() const { return "dayofyear"; }
137
void fix_length_and_dec()
140
max_length=3*MY_CHARSET_BIN_MB_MAXLEN;
146
class Item_func_hour :public Item_int_func
149
Item_func_hour(Item *a) :Item_int_func(a) {}
151
const char *func_name() const { return "hour"; }
152
void fix_length_and_dec()
155
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
161
class Item_func_minute :public Item_int_func
164
Item_func_minute(Item *a) :Item_int_func(a) {}
166
const char *func_name() const { return "minute"; }
167
void fix_length_and_dec()
170
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
176
class Item_func_quarter :public Item_int_func
179
Item_func_quarter(Item *a) :Item_int_func(a) {}
181
const char *func_name() const { return "quarter"; }
182
void fix_length_and_dec()
185
max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
191
class Item_func_second :public Item_int_func
194
Item_func_second(Item *a) :Item_int_func(a) {}
196
const char *func_name() const { return "second"; }
197
void fix_length_and_dec()
200
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
206
class Item_func_week :public Item_int_func
209
Item_func_week(Item *a,Item *b) :Item_int_func(a,b) {}
211
const char *func_name() const { return "week"; }
212
void fix_length_and_dec()
215
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
220
class Item_func_yearweek :public Item_int_func
223
Item_func_yearweek(Item *a,Item *b) :Item_int_func(a,b) {}
225
const char *func_name() const { return "yearweek"; }
226
void fix_length_and_dec()
229
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
235
class Item_func_year :public Item_int_func
238
Item_func_year(Item *a) :Item_int_func(a) {}
240
const char *func_name() const { return "year"; }
241
enum_monotonicity_info get_monotonicity_info() const;
242
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
243
void fix_length_and_dec()
246
max_length=4*MY_CHARSET_BIN_MB_MAXLEN;
252
class Item_func_weekday :public Item_func
256
Item_func_weekday(Item *a,bool type_arg)
257
:Item_func(a), odbc_type(type_arg) {}
259
double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
260
String *val_str(String *str)
262
DBUG_ASSERT(fixed == 1);
263
str->set(val_int(), &my_charset_bin);
264
return null_value ? 0 : str;
266
const char *func_name() const
268
return (odbc_type ? "dayofweek" : "weekday");
270
enum Item_result result_type () const { return INT_RESULT; }
271
void fix_length_and_dec()
273
collation.set(&my_charset_bin);
275
max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
280
class Item_func_dayname :public Item_func_weekday
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()
289
collation.set(&my_charset_bin);
291
max_length=9*MY_CHARSET_BIN_MB_MAXLEN;
297
class Item_func_unix_timestamp :public Item_int_func
301
Item_func_unix_timestamp() :Item_int_func() {}
302
Item_func_unix_timestamp(Item *a) :Item_int_func(a) {}
304
const char *func_name() const { return "unix_timestamp"; }
305
void fix_length_and_dec()
308
max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
313
class Item_func_time_to_sec :public Item_int_func
316
Item_func_time_to_sec(Item *item) :Item_int_func(item) {}
318
const char *func_name() const { return "time_to_sec"; }
319
void fix_length_and_dec()
322
max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
328
This can't be a Item_str_func, because the val_real() functions are special
331
class Item_date :public Item_func
334
Item_date() :Item_func() {}
335
Item_date(Item *a) :Item_func(a) {}
336
enum Item_result result_type () const { return STRING_RESULT; }
337
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
338
String *val_str(String *str);
340
double val_real() { return val_real_from_decimal(); }
341
const char *func_name() const { return "date"; }
342
void fix_length_and_dec()
344
collation.set(&my_charset_bin);
346
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
348
Field *tmp_table_field(TABLE *table)
350
return tmp_table_field_from_field_type(table, 0);
352
bool result_as_longlong() { return TRUE; }
353
my_decimal *val_decimal(my_decimal *decimal_value)
355
DBUG_ASSERT(fixed == 1);
356
return val_decimal_from_date(decimal_value);
358
int save_in_field(Field *field, bool no_conversions)
360
return save_date_in_field(field);
365
class Item_date_func :public Item_str_func
368
Item_date_func() :Item_str_func() {}
369
Item_date_func(Item *a) :Item_str_func(a) {}
370
Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {}
371
Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {}
372
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
373
Field *tmp_table_field(TABLE *table)
375
return tmp_table_field_from_field_type(table, 0);
377
bool result_as_longlong() { return TRUE; }
378
double val_real() { return (double) val_int(); }
379
my_decimal *val_decimal(my_decimal *decimal_value)
381
DBUG_ASSERT(fixed == 1);
382
return val_decimal_from_date(decimal_value);
384
int save_in_field(Field *field, bool no_conversions)
386
return save_date_in_field(field);
391
class Item_str_timefunc :public Item_str_func
394
Item_str_timefunc() :Item_str_func() {}
395
Item_str_timefunc(Item *a) :Item_str_func(a) {}
396
Item_str_timefunc(Item *a,Item *b) :Item_str_func(a,b) {}
397
Item_str_timefunc(Item *a, Item *b, Item *c) :Item_str_func(a, b ,c) {}
398
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
399
void fix_length_and_dec()
401
decimals= DATETIME_DEC;
402
max_length=MAX_TIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
404
Field *tmp_table_field(TABLE *table)
406
return tmp_table_field_from_field_type(table, 0);
408
double val_real() { return val_real_from_decimal(); }
409
my_decimal *val_decimal(my_decimal *decimal_value)
411
DBUG_ASSERT(fixed == 1);
412
return val_decimal_from_time(decimal_value);
414
int save_in_field(Field *field, bool no_conversions)
416
return save_time_in_field(field);
421
/* Abstract CURTIME function. Children should define what time zone is used */
423
class Item_func_curtime :public Item_str_timefunc
429
Item_func_curtime() :Item_str_timefunc() {}
430
Item_func_curtime(Item *a) :Item_str_timefunc(a) {}
431
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
432
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
433
String *val_str(String *str);
434
void fix_length_and_dec();
436
Abstract method that defines which time zone is used for conversion.
437
Converts time current time in my_time_t representation to broken-down
438
MYSQL_TIME representation using UTC-SYSTEM or per-thread time zone.
440
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
441
bool result_as_longlong() { return TRUE; }
445
class Item_func_curtime_local :public Item_func_curtime
448
Item_func_curtime_local() :Item_func_curtime() {}
449
Item_func_curtime_local(Item *a) :Item_func_curtime(a) {}
450
const char *func_name() const { return "curtime"; }
451
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
455
class Item_func_curtime_utc :public Item_func_curtime
458
Item_func_curtime_utc() :Item_func_curtime() {}
459
Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {}
460
const char *func_name() const { return "utc_time"; }
461
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
465
/* Abstract CURDATE function. See also Item_func_curtime. */
467
class Item_func_curdate :public Item_date
472
Item_func_curdate() :Item_date() {}
473
longlong val_int() { DBUG_ASSERT(fixed == 1); return (value) ; }
474
String *val_str(String *str);
475
void fix_length_and_dec();
476
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
477
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
481
class Item_func_curdate_local :public Item_func_curdate
484
Item_func_curdate_local() :Item_func_curdate() {}
485
const char *func_name() const { return "curdate"; }
486
void store_now_in_TIME(MYSQL_TIME *now_time);
490
class Item_func_curdate_utc :public Item_func_curdate
493
Item_func_curdate_utc() :Item_func_curdate() {}
494
const char *func_name() const { return "utc_date"; }
495
void store_now_in_TIME(MYSQL_TIME *now_time);
499
/* Abstract CURRENT_TIMESTAMP function. See also Item_func_curtime */
501
class Item_func_now :public Item_date_func
505
char buff[20*2+32]; // +32 to make my_snprintf_{8bit|ucs2} happy
509
Item_func_now() :Item_date_func() {}
510
Item_func_now(Item *a) :Item_date_func(a) {}
511
enum Item_result result_type () const { return STRING_RESULT; }
512
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
513
int save_in_field(Field *to, bool no_conversions);
514
String *val_str(String *str);
515
void fix_length_and_dec();
516
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
517
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
521
class Item_func_now_local :public Item_func_now
524
Item_func_now_local() :Item_func_now() {}
525
Item_func_now_local(Item *a) :Item_func_now(a) {}
526
const char *func_name() const { return "now"; }
527
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
528
virtual enum Functype functype() const { return NOW_FUNC; }
532
class Item_func_now_utc :public Item_func_now
535
Item_func_now_utc() :Item_func_now() {}
536
Item_func_now_utc(Item *a) :Item_func_now(a) {}
537
const char *func_name() const { return "utc_timestamp"; }
538
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
543
This is like NOW(), but always uses the real current time, not the
544
query_start(). This matches the Oracle behavior.
546
class Item_func_sysdate_local :public Item_func_now
549
Item_func_sysdate_local() :Item_func_now() {}
550
Item_func_sysdate_local(Item *a) :Item_func_now(a) {}
551
bool const_item() const { return 0; }
552
const char *func_name() const { return "sysdate"; }
553
void store_now_in_TIME(MYSQL_TIME *now_time);
556
int save_in_field(Field *to, bool no_conversions);
557
String *val_str(String *str);
558
void fix_length_and_dec();
559
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
560
void update_used_tables()
562
Item_func_now::update_used_tables();
563
used_tables_cache|= RAND_TABLE_BIT;
568
class Item_func_from_days :public Item_date
571
Item_func_from_days(Item *a) :Item_date(a) {}
572
const char *func_name() const { return "from_days"; }
573
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
577
class Item_func_date_format :public Item_str_func
580
const bool is_time_format;
583
Item_func_date_format(Item *a,Item *b,bool is_time_format_arg)
584
:Item_str_func(a,b),is_time_format(is_time_format_arg) {}
585
String *val_str(String *str);
586
const char *func_name() const
587
{ return is_time_format ? "time_format" : "date_format"; }
588
void fix_length_and_dec();
589
uint format_length(const String *format);
590
bool eq(const Item *item, bool binary_cmp) const;
594
class Item_func_from_unixtime :public Item_date_func
598
Item_func_from_unixtime(Item *a) :Item_date_func(a) {}
600
String *val_str(String *str);
601
const char *func_name() const { return "from_unixtime"; }
602
void fix_length_and_dec();
603
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
608
We need Time_zone class declaration for storing pointers in
609
Item_func_convert_tz.
614
This class represents CONVERT_TZ() function.
615
The important fact about this function that it is handled in special way.
616
When such function is met in expression time_zone system tables are added
617
to global list of tables to open, so later those already opened and locked
618
tables can be used during this function calculation for loading time zone
621
class Item_func_convert_tz :public Item_date_func
624
If time zone parameters are constants we are caching objects that
625
represent them (we use separate from_tz_cached/to_tz_cached members
626
to indicate this fact, since NULL is legal value for from_tz/to_tz
629
bool from_tz_cached, to_tz_cached;
630
Time_zone *from_tz, *to_tz;
632
Item_func_convert_tz(Item *a, Item *b, Item *c):
633
Item_date_func(a, b, c), from_tz_cached(0), to_tz_cached(0) {}
635
String *val_str(String *str);
636
const char *func_name() const { return "convert_tz"; }
637
void fix_length_and_dec();
638
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
643
class Item_func_sec_to_time :public Item_str_timefunc
646
Item_func_sec_to_time(Item *item) :Item_str_timefunc(item) {}
649
DBUG_ASSERT(fixed == 1);
650
return (double) Item_func_sec_to_time::val_int();
653
String *val_str(String *);
654
void fix_length_and_dec()
656
Item_str_timefunc::fix_length_and_dec();
657
collation.set(&my_charset_bin);
660
const char *func_name() const { return "sec_to_time"; }
661
bool result_as_longlong() { return TRUE; }
665
class Item_date_add_interval :public Item_date_func
668
enum_field_types cached_field_type;
671
const interval_type int_type; // keep it public
672
const bool date_sub_interval; // keep it public
673
Item_date_add_interval(Item *a,Item *b,interval_type type_arg,bool neg_arg)
674
:Item_date_func(a,b),int_type(type_arg), date_sub_interval(neg_arg) {}
675
String *val_str(String *);
676
const char *func_name() const { return "date_add_interval"; }
677
void fix_length_and_dec();
678
enum_field_types field_type() const { return cached_field_type; }
680
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
681
bool eq(const Item *item, bool binary_cmp) const;
682
virtual void print(String *str, enum_query_type query_type);
686
class Item_extract :public Item_int_func
691
const interval_type int_type; // keep it public
692
Item_extract(interval_type type_arg, Item *a)
693
:Item_int_func(a), int_type(type_arg) {}
695
enum Functype functype() const { return EXTRACT_FUNC; }
696
const char *func_name() const { return "extract"; }
697
void fix_length_and_dec();
698
bool eq(const Item *item, bool binary_cmp) const;
699
virtual void print(String *str, enum_query_type query_type);
703
class Item_typecast :public Item_str_func
706
Item_typecast(Item *a) :Item_str_func(a) {}
707
String *val_str(String *a)
709
DBUG_ASSERT(fixed == 1);
710
String *tmp=args[0]->val_str(a);
711
null_value=args[0]->null_value;
713
tmp->set_charset(collation.collation);
716
void fix_length_and_dec()
718
collation.set(&my_charset_bin);
719
max_length=args[0]->max_length;
721
virtual const char* cast_type() const= 0;
722
virtual void print(String *str, enum_query_type query_type);
726
class Item_typecast_maybe_null :public Item_typecast
729
Item_typecast_maybe_null(Item *a) :Item_typecast(a) {}
730
void fix_length_and_dec()
732
collation.set(&my_charset_bin);
733
max_length=args[0]->max_length;
739
class Item_char_typecast :public Item_typecast
742
CHARSET_INFO *cast_cs, *from_cs;
743
bool charset_conversion;
746
Item_char_typecast(Item *a, int length_arg, CHARSET_INFO *cs_arg)
747
:Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {}
748
enum Functype functype() const { return CHAR_TYPECAST_FUNC; }
749
bool eq(const Item *item, bool binary_cmp) const;
750
const char *func_name() const { return "cast_as_char"; }
751
const char* cast_type() const { return "char"; };
752
String *val_str(String *a);
753
void fix_length_and_dec();
754
virtual void print(String *str, enum_query_type query_type);
758
class Item_date_typecast :public Item_typecast_maybe_null
761
Item_date_typecast(Item *a) :Item_typecast_maybe_null(a) {}
762
const char *func_name() const { return "cast_as_date"; }
763
String *val_str(String *str);
764
bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
765
bool get_time(MYSQL_TIME *ltime);
766
const char *cast_type() const { return "date"; }
767
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
768
Field *tmp_table_field(TABLE *table)
770
return tmp_table_field_from_field_type(table, 0);
772
void fix_length_and_dec()
774
collation.set(&my_charset_bin);
778
bool result_as_longlong() { return TRUE; }
780
double val_real() { return (double) val_int(); }
781
my_decimal *val_decimal(my_decimal *decimal_value)
783
DBUG_ASSERT(fixed == 1);
784
return val_decimal_from_date(decimal_value);
786
int save_in_field(Field *field, bool no_conversions)
788
return save_date_in_field(field);
793
class Item_time_typecast :public Item_typecast_maybe_null
796
Item_time_typecast(Item *a) :Item_typecast_maybe_null(a) {}
797
const char *func_name() const { return "cast_as_time"; }
798
String *val_str(String *str);
799
bool get_time(MYSQL_TIME *ltime);
800
const char *cast_type() const { return "time"; }
801
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
802
Field *tmp_table_field(TABLE *table)
804
return tmp_table_field_from_field_type(table, 0);
806
bool result_as_longlong() { return TRUE; }
808
double val_real() { return val_real_from_decimal(); }
809
my_decimal *val_decimal(my_decimal *decimal_value)
811
DBUG_ASSERT(fixed == 1);
812
return val_decimal_from_time(decimal_value);
814
int save_in_field(Field *field, bool no_conversions)
816
return save_time_in_field(field);
821
class Item_datetime_typecast :public Item_typecast_maybe_null
824
Item_datetime_typecast(Item *a) :Item_typecast_maybe_null(a) {}
825
const char *func_name() const { return "cast_as_datetime"; }
826
String *val_str(String *str);
827
const char *cast_type() const { return "datetime"; }
828
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
829
Field *tmp_table_field(TABLE *table)
831
return tmp_table_field_from_field_type(table, 0);
833
void fix_length_and_dec()
835
collation.set(&my_charset_bin);
837
max_length= MAX_DATETIME_FULL_WIDTH * MY_CHARSET_BIN_MB_MAXLEN;
838
decimals= DATETIME_DEC;
840
bool result_as_longlong() { return TRUE; }
842
double val_real() { return val_real_from_decimal(); }
843
double val() { return (double) val_int(); }
844
my_decimal *val_decimal(my_decimal *decimal_value)
846
DBUG_ASSERT(fixed == 1);
847
return val_decimal_from_date(decimal_value);
849
int save_in_field(Field *field, bool no_conversions)
851
return save_date_in_field(field);
855
class Item_func_makedate :public Item_date_func
858
Item_func_makedate(Item *a,Item *b) :Item_date_func(a,b) {}
859
String *val_str(String *str);
860
const char *func_name() const { return "makedate"; }
861
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
862
void fix_length_and_dec()
865
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
871
class Item_func_add_time :public Item_str_func
875
enum_field_types cached_field_type;
878
Item_func_add_time(Item *a, Item *b, bool type_arg, bool neg_arg)
879
:Item_str_func(a, b), is_date(type_arg) { sign= neg_arg ? -1 : 1; }
880
String *val_str(String *str);
881
enum_field_types field_type() const { return cached_field_type; }
882
void fix_length_and_dec();
884
Field *tmp_table_field(TABLE *table)
886
return tmp_table_field_from_field_type(table, 0);
888
virtual void print(String *str, enum_query_type query_type);
889
const char *func_name() const { return "add_time"; }
890
double val_real() { return val_real_from_decimal(); }
891
my_decimal *val_decimal(my_decimal *decimal_value)
893
DBUG_ASSERT(fixed == 1);
894
if (cached_field_type == MYSQL_TYPE_TIME)
895
return val_decimal_from_time(decimal_value);
896
if (cached_field_type == MYSQL_TYPE_DATETIME)
897
return val_decimal_from_date(decimal_value);
898
return Item_str_func::val_decimal(decimal_value);
900
int save_in_field(Field *field, bool no_conversions)
902
if (cached_field_type == MYSQL_TYPE_TIME)
903
return save_time_in_field(field);
904
if (cached_field_type == MYSQL_TYPE_DATETIME)
905
return save_date_in_field(field);
906
return Item_str_func::save_in_field(field, no_conversions);
910
class Item_func_timediff :public Item_str_timefunc
913
Item_func_timediff(Item *a, Item *b)
914
:Item_str_timefunc(a, b) {}
915
String *val_str(String *str);
916
const char *func_name() const { return "timediff"; }
917
void fix_length_and_dec()
919
Item_str_timefunc::fix_length_and_dec();
924
class Item_func_maketime :public Item_str_timefunc
927
Item_func_maketime(Item *a, Item *b, Item *c)
928
:Item_str_timefunc(a, b, c)
932
String *val_str(String *str);
933
const char *func_name() const { return "maketime"; }
936
class Item_func_microsecond :public Item_int_func
939
Item_func_microsecond(Item *a) :Item_int_func(a) {}
941
const char *func_name() const { return "microsecond"; }
942
void fix_length_and_dec()
950
class Item_func_timestamp_diff :public Item_int_func
952
const interval_type int_type;
954
Item_func_timestamp_diff(Item *a,Item *b,interval_type type_arg)
955
:Item_int_func(a,b), int_type(type_arg) {}
956
const char *func_name() const { return "timestampdiff"; }
958
void fix_length_and_dec()
963
virtual void print(String *str, enum_query_type query_type);
967
enum date_time_format
969
USA_FORMAT, JIS_FORMAT, ISO_FORMAT, EUR_FORMAT, INTERNAL_FORMAT
972
class Item_func_get_format :public Item_str_func
975
const timestamp_type type; // keep it public
976
Item_func_get_format(timestamp_type type_arg, Item *a)
977
:Item_str_func(a), type(type_arg)
979
String *val_str(String *str);
980
const char *func_name() const { return "get_format"; }
981
void fix_length_and_dec()
985
max_length=17*MY_CHARSET_BIN_MB_MAXLEN;
987
virtual void print(String *str, enum_query_type query_type);
991
class Item_func_str_to_date :public Item_str_func
993
enum_field_types cached_field_type;
994
date_time_format_types cached_format_type;
995
timestamp_type cached_timestamp_type;
998
Item_func_str_to_date(Item *a, Item *b)
999
:Item_str_func(a, b), const_item(false)
1001
String *val_str(String *str);
1002
bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
1003
const char *func_name() const { return "str_to_date"; }
1004
enum_field_types field_type() const { return cached_field_type; }
1005
void fix_length_and_dec();
1006
Field *tmp_table_field(TABLE *table)
1008
return tmp_table_field_from_field_type(table, 1);
1013
class Item_func_last_day :public Item_date
1016
Item_func_last_day(Item *a) :Item_date(a) {}
1017
const char *func_name() const { return "last_day"; }
1018
bool get_date(MYSQL_TIME *res, uint fuzzy_date);