1
#ifndef ITEM_TIMEFUNC_INCLUDED
2
#define ITEM_TIMEFUNC_INCLUDED
4
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
20
/* Function items used by mysql */
22
#ifdef USE_PRAGMA_INTERFACE
23
#pragma interface /* gcc class implementation */
28
enum date_time_format_types
30
TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND
33
bool get_interval_value(Item *args,interval_type int_type,
34
String *str_value, INTERVAL *interval);
36
class Item_func_period_add :public Item_int_func
39
Item_func_period_add(Item *a,Item *b) :Item_int_func(a,b) {}
41
const char *func_name() const { return "period_add"; }
42
void fix_length_and_dec()
44
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
49
class Item_func_period_diff :public Item_int_func
52
Item_func_period_diff(Item *a,Item *b) :Item_int_func(a,b) {}
54
const char *func_name() const { return "period_diff"; }
55
void fix_length_and_dec()
58
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
63
class Item_func_to_days :public Item_int_func
66
Item_func_to_days(Item *a) :Item_int_func(a) {}
68
const char *func_name() const { return "to_days"; }
69
void fix_length_and_dec()
72
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
75
enum_monotonicity_info get_monotonicity_info() const;
76
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
77
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
78
bool check_valid_arguments_processor(uchar *int_arg)
80
return !has_date_args();
85
class Item_func_to_seconds :public Item_int_func
88
Item_func_to_seconds(Item *a) :Item_int_func(a) {}
90
const char *func_name() const { return "to_seconds"; }
91
void fix_length_and_dec()
94
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
97
enum_monotonicity_info get_monotonicity_info() const;
98
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
99
bool check_partition_func_processor(uchar *bool_arg) { return FALSE;}
101
bool intro_version(uchar *int_arg)
103
int *input_version= (int*)int_arg;
104
/* This function was introduced in 5.5 */
105
int output_version= max(*input_version, 50500);
106
*input_version= output_version;
110
/* Only meaningful with date part and optional time part */
111
bool check_valid_arguments_processor(uchar *int_arg)
113
return !has_date_args();
118
class Item_func_dayofmonth :public Item_int_func
121
Item_func_dayofmonth(Item *a) :Item_int_func(a) {}
123
const char *func_name() const { return "dayofmonth"; }
124
void fix_length_and_dec()
127
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
130
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
131
bool check_valid_arguments_processor(uchar *int_arg)
133
return !has_date_args();
138
class Item_func_month :public Item_func
141
Item_func_month(Item *a) :Item_func(a) { collation.set_numeric(); }
144
{ DBUG_ASSERT(fixed == 1); return (double) Item_func_month::val_int(); }
145
String *val_str(String *str)
147
longlong nr= val_int();
150
str->set(nr, collation.collation);
153
const char *func_name() const { return "month"; }
154
enum Item_result result_type () const { return INT_RESULT; }
155
void fix_length_and_dec()
161
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
162
bool check_valid_arguments_processor(uchar *int_arg)
164
return !has_date_args();
169
class Item_func_monthname :public Item_str_func
173
Item_func_monthname(Item *a) :Item_str_func(a) {}
174
const char *func_name() const { return "monthname"; }
175
String *val_str(String *str);
176
void fix_length_and_dec();
177
bool check_partition_func_processor(uchar *int_arg) {return TRUE;}
178
bool check_valid_arguments_processor(uchar *int_arg)
180
return !has_date_args();
185
class Item_func_dayofyear :public Item_int_func
188
Item_func_dayofyear(Item *a) :Item_int_func(a) {}
190
const char *func_name() const { return "dayofyear"; }
191
void fix_length_and_dec()
197
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
198
bool check_valid_arguments_processor(uchar *int_arg)
200
return !has_date_args();
205
class Item_func_hour :public Item_int_func
208
Item_func_hour(Item *a) :Item_int_func(a) {}
210
const char *func_name() const { return "hour"; }
211
void fix_length_and_dec()
214
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
217
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
218
bool check_valid_arguments_processor(uchar *int_arg)
220
return !has_time_args();
225
class Item_func_minute :public Item_int_func
228
Item_func_minute(Item *a) :Item_int_func(a) {}
230
const char *func_name() const { return "minute"; }
231
void fix_length_and_dec()
234
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
237
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
238
bool check_valid_arguments_processor(uchar *int_arg)
240
return !has_time_args();
245
class Item_func_quarter :public Item_int_func
248
Item_func_quarter(Item *a) :Item_int_func(a) {}
250
const char *func_name() const { return "quarter"; }
251
void fix_length_and_dec()
254
max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
257
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
258
bool check_valid_arguments_processor(uchar *int_arg)
260
return !has_date_args();
265
class Item_func_second :public Item_int_func
268
Item_func_second(Item *a) :Item_int_func(a) {}
270
const char *func_name() const { return "second"; }
271
void fix_length_and_dec()
274
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
277
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
278
bool check_valid_arguments_processor(uchar *int_arg)
280
return !has_time_args();
285
class Item_func_week :public Item_int_func
288
Item_func_week(Item *a,Item *b) :Item_int_func(a,b) {}
290
const char *func_name() const { return "week"; }
291
void fix_length_and_dec()
294
max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
299
class Item_func_yearweek :public Item_int_func
302
Item_func_yearweek(Item *a,Item *b) :Item_int_func(a,b) {}
304
const char *func_name() const { return "yearweek"; }
305
void fix_length_and_dec()
308
max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
311
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
312
bool check_valid_arguments_processor(uchar *int_arg)
314
return !has_date_args();
319
class Item_func_year :public Item_int_func
322
Item_func_year(Item *a) :Item_int_func(a) {}
324
const char *func_name() const { return "year"; }
325
enum_monotonicity_info get_monotonicity_info() const;
326
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
327
void fix_length_and_dec()
330
max_length=4*MY_CHARSET_BIN_MB_MAXLEN;
333
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
334
bool check_valid_arguments_processor(uchar *int_arg)
336
return !has_date_args();
341
class Item_func_weekday :public Item_func
345
Item_func_weekday(Item *a,bool type_arg)
346
:Item_func(a), odbc_type(type_arg) { collation.set_numeric(); }
348
double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
349
String *val_str(String *str)
351
DBUG_ASSERT(fixed == 1);
352
str->set(val_int(), &my_charset_bin);
353
return null_value ? 0 : str;
355
const char *func_name() const
357
return (odbc_type ? "dayofweek" : "weekday");
359
enum Item_result result_type () const { return INT_RESULT; }
360
void fix_length_and_dec()
366
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
367
bool check_valid_arguments_processor(uchar *int_arg)
369
return !has_date_args();
373
class Item_func_dayname :public Item_func_weekday
377
Item_func_dayname(Item *a) :Item_func_weekday(a,0) {}
378
const char *func_name() const { return "dayname"; }
379
String *val_str(String *str);
380
enum Item_result result_type () const { return STRING_RESULT; }
381
void fix_length_and_dec();
382
bool check_partition_func_processor(uchar *int_arg) {return TRUE;}
386
class Item_func_unix_timestamp :public Item_int_func
390
Item_func_unix_timestamp() :Item_int_func() {}
391
Item_func_unix_timestamp(Item *a) :Item_int_func(a) {}
393
const char *func_name() const { return "unix_timestamp"; }
394
enum_monotonicity_info get_monotonicity_info() const;
395
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
396
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
398
UNIX_TIMESTAMP() depends on the current timezone
399
(and thus may not be used as a partitioning function)
400
when its argument is NOT of the TIMESTAMP type.
402
bool check_valid_arguments_processor(uchar *int_arg)
404
return !has_timestamp_args();
406
void fix_length_and_dec()
409
max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
414
class Item_func_time_to_sec :public Item_int_func
417
Item_func_time_to_sec(Item *item) :Item_int_func(item) {}
419
const char *func_name() const { return "time_to_sec"; }
420
void fix_length_and_dec()
424
max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
426
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
427
bool check_valid_arguments_processor(uchar *int_arg)
429
return !has_time_args();
435
This can't be a Item_str_func, because the val_real() functions are special
438
class Item_date :public Item_func
441
Item_date() :Item_func() {}
442
Item_date(Item *a) :Item_func(a) {}
443
enum Item_result result_type () const { return STRING_RESULT; }
444
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
445
CHARSET_INFO *charset_for_protocol(void) const { return &my_charset_bin; }
446
String *val_str(String *str);
448
double val_real() { return val_real_from_decimal(); }
449
const char *func_name() const { return "date"; }
450
void fix_length_and_dec()
453
fix_length_and_charset_datetime(MAX_DATE_WIDTH);
455
Field *tmp_table_field(TABLE *table)
457
return tmp_table_field_from_field_type(table, 0);
459
bool result_as_longlong() { return TRUE; }
460
my_decimal *val_decimal(my_decimal *decimal_value)
462
DBUG_ASSERT(fixed == 1);
463
return val_decimal_from_date(decimal_value);
465
int save_in_field(Field *field, bool no_conversions)
467
return save_date_in_field(field);
472
class Item_date_func :public Item_str_func
475
Item_date_func() :Item_str_func() {}
476
Item_date_func(Item *a) :Item_str_func(a) {}
477
Item_date_func(Item *a,Item *b) :Item_str_func(a,b) {}
478
Item_date_func(Item *a,Item *b, Item *c) :Item_str_func(a,b,c) {}
479
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
480
CHARSET_INFO *charset_for_protocol(void) const { return &my_charset_bin; }
481
Field *tmp_table_field(TABLE *table)
483
return tmp_table_field_from_field_type(table, 0);
485
bool result_as_longlong() { return TRUE; }
486
double val_real() { return (double) val_int(); }
487
my_decimal *val_decimal(my_decimal *decimal_value)
489
DBUG_ASSERT(fixed == 1);
490
return val_decimal_from_date(decimal_value);
492
int save_in_field(Field *field, bool no_conversions)
494
return save_date_in_field(field);
499
class Item_str_timefunc :public Item_str_func
502
Item_str_timefunc() :Item_str_func() {}
503
Item_str_timefunc(Item *a) :Item_str_func(a) {}
504
Item_str_timefunc(Item *a,Item *b) :Item_str_func(a,b) {}
505
Item_str_timefunc(Item *a, Item *b, Item *c) :Item_str_func(a, b ,c) {}
506
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
507
CHARSET_INFO *charset_for_protocol(void) const { return &my_charset_bin; }
508
void fix_length_and_dec()
510
decimals= DATETIME_DEC;
511
fix_length_and_charset_datetime(MAX_TIME_WIDTH);
513
Field *tmp_table_field(TABLE *table)
515
return tmp_table_field_from_field_type(table, 0);
517
double val_real() { return val_real_from_decimal(); }
518
my_decimal *val_decimal(my_decimal *decimal_value)
520
DBUG_ASSERT(fixed == 1);
521
return val_decimal_from_time(decimal_value);
523
int save_in_field(Field *field, bool no_conversions)
525
return save_time_in_field(field);
527
longlong val_int() { return val_int_from_decimal(); }
528
bool result_as_longlong() { return TRUE; }
532
/* Abstract CURTIME function. Children should define what time zone is used */
534
class Item_func_curtime :public Item_str_timefunc
540
Item_func_curtime() :Item_str_timefunc() {}
541
Item_func_curtime(Item *a) :Item_str_timefunc(a) {}
542
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
543
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
544
String *val_str(String *str);
545
void fix_length_and_dec();
547
Abstract method that defines which time zone is used for conversion.
548
Converts time current time in my_time_t representation to broken-down
549
MYSQL_TIME representation using UTC-SYSTEM or per-thread time zone.
551
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
552
bool result_as_longlong() { return TRUE; }
556
class Item_func_curtime_local :public Item_func_curtime
559
Item_func_curtime_local() :Item_func_curtime() {}
560
Item_func_curtime_local(Item *a) :Item_func_curtime(a) {}
561
const char *func_name() const { return "curtime"; }
562
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
566
class Item_func_curtime_utc :public Item_func_curtime
569
Item_func_curtime_utc() :Item_func_curtime() {}
570
Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {}
571
const char *func_name() const { return "utc_time"; }
572
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
576
/* Abstract CURDATE function. See also Item_func_curtime. */
578
class Item_func_curdate :public Item_date
583
Item_func_curdate() :Item_date() {}
584
longlong val_int() { DBUG_ASSERT(fixed == 1); return (value) ; }
585
String *val_str(String *str);
586
void fix_length_and_dec();
587
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
588
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
592
class Item_func_curdate_local :public Item_func_curdate
595
Item_func_curdate_local() :Item_func_curdate() {}
596
const char *func_name() const { return "curdate"; }
597
void store_now_in_TIME(MYSQL_TIME *now_time);
601
class Item_func_curdate_utc :public Item_func_curdate
604
Item_func_curdate_utc() :Item_func_curdate() {}
605
const char *func_name() const { return "utc_date"; }
606
void store_now_in_TIME(MYSQL_TIME *now_time);
610
/* Abstract CURRENT_TIMESTAMP function. See also Item_func_curtime */
612
class Item_func_now :public Item_date_func
616
char buff[20*2+32]; // +32 to make my_snprintf_{8bit|ucs2} happy
620
Item_func_now() :Item_date_func() {}
621
Item_func_now(Item *a) :Item_date_func(a) {}
622
enum Item_result result_type () const { return STRING_RESULT; }
623
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
624
int save_in_field(Field *to, bool no_conversions);
625
String *val_str(String *str);
626
void fix_length_and_dec();
627
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
628
virtual void store_now_in_TIME(MYSQL_TIME *now_time)=0;
632
class Item_func_now_local :public Item_func_now
635
Item_func_now_local() :Item_func_now() {}
636
Item_func_now_local(Item *a) :Item_func_now(a) {}
637
const char *func_name() const { return "now"; }
638
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
639
virtual enum Functype functype() const { return NOW_FUNC; }
643
class Item_func_now_utc :public Item_func_now
646
Item_func_now_utc() :Item_func_now() {}
647
Item_func_now_utc(Item *a) :Item_func_now(a) {}
648
const char *func_name() const { return "utc_timestamp"; }
649
virtual void store_now_in_TIME(MYSQL_TIME *now_time);
654
This is like NOW(), but always uses the real current time, not the
655
query_start(). This matches the Oracle behavior.
657
class Item_func_sysdate_local :public Item_func_now
660
Item_func_sysdate_local() :Item_func_now() {}
661
Item_func_sysdate_local(Item *a) :Item_func_now(a) {}
662
bool const_item() const { return 0; }
663
const char *func_name() const { return "sysdate"; }
664
void store_now_in_TIME(MYSQL_TIME *now_time);
667
int save_in_field(Field *to, bool no_conversions);
668
String *val_str(String *str);
669
void fix_length_and_dec();
670
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
671
void update_used_tables()
673
Item_func_now::update_used_tables();
674
used_tables_cache|= RAND_TABLE_BIT;
679
class Item_func_from_days :public Item_date
682
Item_func_from_days(Item *a) :Item_date(a) {}
683
const char *func_name() const { return "from_days"; }
684
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
685
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
686
bool check_valid_arguments_processor(uchar *int_arg)
688
return has_date_args() || has_time_args();
693
class Item_func_date_format :public Item_str_func
696
const bool is_time_format;
699
Item_func_date_format(Item *a,Item *b,bool is_time_format_arg)
700
:Item_str_func(a,b),is_time_format(is_time_format_arg) {}
701
String *val_str(String *str);
702
const char *func_name() const
703
{ return is_time_format ? "time_format" : "date_format"; }
704
void fix_length_and_dec();
705
uint format_length(const String *format);
706
bool eq(const Item *item, bool binary_cmp) const;
710
class Item_func_from_unixtime :public Item_date_func
714
Item_func_from_unixtime(Item *a) :Item_date_func(a) {}
716
String *val_str(String *str);
717
const char *func_name() const { return "from_unixtime"; }
718
void fix_length_and_dec();
719
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
724
We need Time_zone class declaration for storing pointers in
725
Item_func_convert_tz.
730
This class represents CONVERT_TZ() function.
731
The important fact about this function that it is handled in special way.
732
When such function is met in expression time_zone system tables are added
733
to global list of tables to open, so later those already opened and locked
734
tables can be used during this function calculation for loading time zone
737
class Item_func_convert_tz :public Item_date_func
740
If time zone parameters are constants we are caching objects that
741
represent them (we use separate from_tz_cached/to_tz_cached members
742
to indicate this fact, since NULL is legal value for from_tz/to_tz
745
bool from_tz_cached, to_tz_cached;
746
Time_zone *from_tz, *to_tz;
748
Item_func_convert_tz(Item *a, Item *b, Item *c):
749
Item_date_func(a, b, c), from_tz_cached(0), to_tz_cached(0) {}
751
String *val_str(String *str);
752
const char *func_name() const { return "convert_tz"; }
753
void fix_length_and_dec();
754
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
759
class Item_func_sec_to_time :public Item_str_timefunc
762
Item_func_sec_to_time(Item *item) :Item_str_timefunc(item) {}
765
DBUG_ASSERT(fixed == 1);
766
return (double) Item_func_sec_to_time::val_int();
769
String *val_str(String *);
770
void fix_length_and_dec()
772
Item_str_timefunc::fix_length_and_dec();
775
const char *func_name() const { return "sec_to_time"; }
776
bool result_as_longlong() { return TRUE; }
780
class Item_date_add_interval :public Item_date_func
783
enum_field_types cached_field_type;
786
const interval_type int_type; // keep it public
787
const bool date_sub_interval; // keep it public
788
Item_date_add_interval(Item *a,Item *b,interval_type type_arg,bool neg_arg)
789
:Item_date_func(a,b),int_type(type_arg), date_sub_interval(neg_arg) {}
790
String *val_str_ascii(String *str);
791
String *val_str(String *str)
793
return val_str_from_val_str_ascii(str, &ascii_buf);
795
const char *func_name() const { return "date_add_interval"; }
796
void fix_length_and_dec();
797
enum_field_types field_type() const { return cached_field_type; }
798
CHARSET_INFO *charset_for_protocol(void) const
801
DATE_ADD() can return DATE, DATETIME or VARCHAR depending on arguments.
802
Send using "binary" when DATE or DATETIME,
803
or using collation.collation when VARCHAR
804
(which was fixed from @collation_connection in fix_length_and_dec).
806
DBUG_ASSERT(fixed == 1);
807
return cached_field_type == MYSQL_TYPE_STRING ?
808
collation.collation : &my_charset_bin;
811
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
812
bool eq(const Item *item, bool binary_cmp) const;
813
virtual void print(String *str, enum_query_type query_type);
817
class Item_extract :public Item_int_func
821
const interval_type int_type; // keep it public
822
Item_extract(interval_type type_arg, Item *a)
823
:Item_int_func(a), int_type(type_arg) {}
825
enum Functype functype() const { return EXTRACT_FUNC; }
826
const char *func_name() const { return "extract"; }
827
void fix_length_and_dec();
828
bool eq(const Item *item, bool binary_cmp) const;
829
virtual void print(String *str, enum_query_type query_type);
830
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
831
bool check_valid_arguments_processor(uchar *int_arg)
835
case INTERVAL_YEAR_MONTH:
836
case INTERVAL_QUARTER:
838
/* case INTERVAL_WEEK: Not allowed as partitioning function, bug#57071 */
840
return !has_date_args();
841
case INTERVAL_DAY_HOUR:
842
case INTERVAL_DAY_MINUTE:
843
case INTERVAL_DAY_SECOND:
844
case INTERVAL_DAY_MICROSECOND:
845
return !has_datetime_args();
847
case INTERVAL_HOUR_MINUTE:
848
case INTERVAL_HOUR_SECOND:
849
case INTERVAL_MINUTE:
850
case INTERVAL_MINUTE_SECOND:
851
case INTERVAL_SECOND:
852
case INTERVAL_MICROSECOND:
853
case INTERVAL_HOUR_MICROSECOND:
854
case INTERVAL_MINUTE_MICROSECOND:
855
case INTERVAL_SECOND_MICROSECOND:
856
return !has_time_args();
859
INTERVAL_LAST is only an end marker,
860
INTERVAL_WEEK depends on default_week_format which is a session
861
variable and cannot be used for partitioning. See bug#57071.
870
class Item_typecast :public Item_str_func
873
Item_typecast(Item *a) :Item_str_func(a) {}
874
String *val_str(String *a)
876
DBUG_ASSERT(fixed == 1);
877
String *tmp=args[0]->val_str(a);
878
null_value=args[0]->null_value;
880
tmp->set_charset(collation.collation);
883
void fix_length_and_dec()
885
collation.set(&my_charset_bin);
886
max_length=args[0]->max_length;
888
virtual const char* cast_type() const= 0;
889
virtual void print(String *str, enum_query_type query_type);
893
class Item_typecast_maybe_null :public Item_typecast
896
Item_typecast_maybe_null(Item *a) :Item_typecast(a) { maybe_null= 1; }
900
class Item_char_typecast :public Item_typecast
903
CHARSET_INFO *cast_cs, *from_cs;
904
bool charset_conversion;
907
Item_char_typecast(Item *a, int length_arg, CHARSET_INFO *cs_arg)
908
:Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {}
909
enum Functype functype() const { return CHAR_TYPECAST_FUNC; }
910
bool eq(const Item *item, bool binary_cmp) const;
911
const char *func_name() const { return "cast_as_char"; }
912
const char* cast_type() const { return "char"; };
913
String *val_str(String *a);
914
void fix_length_and_dec();
915
virtual void print(String *str, enum_query_type query_type);
919
class Item_date_typecast :public Item_typecast_maybe_null
922
Item_date_typecast(Item *a) :Item_typecast_maybe_null(a) {}
923
const char *func_name() const { return "cast_as_date"; }
924
String *val_str(String *str);
925
bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
926
bool get_time(MYSQL_TIME *ltime);
927
const char *cast_type() const { return "date"; }
928
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
929
CHARSET_INFO *charset_for_protocol(void) const { return &my_charset_bin; }
930
Field *tmp_table_field(TABLE *table)
932
return tmp_table_field_from_field_type(table, 0);
934
void fix_length_and_dec() { fix_length_and_charset_datetime(10); }
935
bool result_as_longlong() { return TRUE; }
937
double val_real() { return (double) val_int(); }
938
my_decimal *val_decimal(my_decimal *decimal_value)
940
DBUG_ASSERT(fixed == 1);
941
return val_decimal_from_date(decimal_value);
943
int save_in_field(Field *field, bool no_conversions)
945
return save_date_in_field(field);
950
class Item_time_typecast :public Item_typecast_maybe_null
953
Item_time_typecast(Item *a) :Item_typecast_maybe_null(a) {}
954
const char *func_name() const { return "cast_as_time"; }
955
String *val_str(String *str);
956
bool get_time(MYSQL_TIME *ltime);
957
const char *cast_type() const { return "time"; }
958
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
959
CHARSET_INFO *charset_for_protocol(void) const { return &my_charset_bin; }
960
Field *tmp_table_field(TABLE *table)
962
return tmp_table_field_from_field_type(table, 0);
964
bool result_as_longlong() { return TRUE; }
966
double val_real() { return val_real_from_decimal(); }
967
my_decimal *val_decimal(my_decimal *decimal_value)
969
DBUG_ASSERT(fixed == 1);
970
return val_decimal_from_time(decimal_value);
972
int save_in_field(Field *field, bool no_conversions)
974
return save_time_in_field(field);
976
void fix_length_and_dec()
977
{ fix_length_and_charset_datetime(args[0]->max_char_length()); }
981
class Item_datetime_typecast :public Item_typecast_maybe_null
984
Item_datetime_typecast(Item *a) :Item_typecast_maybe_null(a) {}
985
const char *func_name() const { return "cast_as_datetime"; }
986
String *val_str(String *str);
987
const char *cast_type() const { return "datetime"; }
988
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
989
CHARSET_INFO *charset_for_protocol(void) const { return &my_charset_bin; }
990
Field *tmp_table_field(TABLE *table)
992
return tmp_table_field_from_field_type(table, 0);
994
void fix_length_and_dec()
996
fix_length_and_charset_datetime(MAX_DATETIME_FULL_WIDTH);
997
decimals= DATETIME_DEC;
999
bool result_as_longlong() { return TRUE; }
1001
double val_real() { return val_real_from_decimal(); }
1002
double val() { return (double) val_int(); }
1003
my_decimal *val_decimal(my_decimal *decimal_value)
1005
DBUG_ASSERT(fixed == 1);
1006
return val_decimal_from_date(decimal_value);
1008
int save_in_field(Field *field, bool no_conversions)
1010
return save_date_in_field(field);
1014
class Item_func_makedate :public Item_date_func
1017
Item_func_makedate(Item *a,Item *b) :Item_date_func(a,b) {}
1018
String *val_str(String *str);
1019
const char *func_name() const { return "makedate"; }
1020
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
1021
CHARSET_INFO *charset_for_protocol(void) const { return &my_charset_bin; }
1022
void fix_length_and_dec()
1025
fix_length_and_charset_datetime(MAX_DATE_WIDTH);
1032
class Item_func_add_time :public Item_str_func
1036
enum_field_types cached_field_type;
1039
Item_func_add_time(Item *a, Item *b, bool type_arg, bool neg_arg)
1040
:Item_str_func(a, b), is_date(type_arg) { sign= neg_arg ? -1 : 1; }
1041
String *val_str(String *str);
1042
enum_field_types field_type() const { return cached_field_type; }
1043
void fix_length_and_dec();
1044
CHARSET_INFO *charset_for_protocol(void) const { return &my_charset_bin; }
1046
Field *tmp_table_field(TABLE *table)
1048
return tmp_table_field_from_field_type(table, 0);
1050
virtual void print(String *str, enum_query_type query_type);
1051
const char *func_name() const { return "add_time"; }
1052
double val_real() { return val_real_from_decimal(); }
1053
my_decimal *val_decimal(my_decimal *decimal_value)
1055
DBUG_ASSERT(fixed == 1);
1056
if (cached_field_type == MYSQL_TYPE_TIME)
1057
return val_decimal_from_time(decimal_value);
1058
if (cached_field_type == MYSQL_TYPE_DATETIME)
1059
return val_decimal_from_date(decimal_value);
1060
return Item_str_func::val_decimal(decimal_value);
1062
int save_in_field(Field *field, bool no_conversions)
1064
if (cached_field_type == MYSQL_TYPE_TIME)
1065
return save_time_in_field(field);
1066
if (cached_field_type == MYSQL_TYPE_DATETIME)
1067
return save_date_in_field(field);
1068
return Item_str_func::save_in_field(field, no_conversions);
1071
MYSQL_TIME *val_datetime(MYSQL_TIME *time, date_time_format_types *format);
1074
class Item_func_timediff :public Item_str_timefunc
1077
Item_func_timediff(Item *a, Item *b)
1078
:Item_str_timefunc(a, b) {}
1079
String *val_str(String *str);
1080
const char *func_name() const { return "timediff"; }
1081
void fix_length_and_dec()
1083
Item_str_timefunc::fix_length_and_dec();
1088
class Item_func_maketime :public Item_str_timefunc
1091
Item_func_maketime(Item *a, Item *b, Item *c)
1092
:Item_str_timefunc(a, b, c)
1096
String *val_str(String *str);
1097
const char *func_name() const { return "maketime"; }
1100
class Item_func_microsecond :public Item_int_func
1103
Item_func_microsecond(Item *a) :Item_int_func(a) {}
1105
const char *func_name() const { return "microsecond"; }
1106
void fix_length_and_dec()
1111
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
1112
bool check_valid_arguments_processor(uchar *int_arg)
1114
return !has_time_args();
1119
class Item_func_timestamp_diff :public Item_int_func
1121
const interval_type int_type;
1123
Item_func_timestamp_diff(Item *a,Item *b,interval_type type_arg)
1124
:Item_int_func(a,b), int_type(type_arg) {}
1125
const char *func_name() const { return "timestampdiff"; }
1127
void fix_length_and_dec()
1132
virtual void print(String *str, enum_query_type query_type);
1136
enum date_time_format
1138
USA_FORMAT, JIS_FORMAT, ISO_FORMAT, EUR_FORMAT, INTERNAL_FORMAT
1141
class Item_func_get_format :public Item_str_ascii_func
1144
const timestamp_type type; // keep it public
1145
Item_func_get_format(timestamp_type type_arg, Item *a)
1146
:Item_str_ascii_func(a), type(type_arg)
1148
String *val_str_ascii(String *str);
1149
const char *func_name() const { return "get_format"; }
1150
void fix_length_and_dec()
1154
fix_length_and_charset(17, default_charset());
1156
virtual void print(String *str, enum_query_type query_type);
1160
class Item_func_str_to_date :public Item_str_func
1162
enum_field_types cached_field_type;
1163
date_time_format_types cached_format_type;
1164
timestamp_type cached_timestamp_type;
1168
Item_func_str_to_date(Item *a, Item *b)
1169
:Item_str_func(a, b), const_item(false)
1171
String *val_str(String *str);
1172
bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
1173
const char *func_name() const { return "str_to_date"; }
1174
enum_field_types field_type() const { return cached_field_type; }
1175
void fix_length_and_dec();
1176
Field *tmp_table_field(TABLE *table)
1178
return tmp_table_field_from_field_type(table, 1);
1181
bool result_as_longlong() { return TRUE; }
1185
class Item_func_last_day :public Item_date
1188
Item_func_last_day(Item *a) :Item_date(a) {}
1189
const char *func_name() const { return "last_day"; }
1190
bool get_date(MYSQL_TIME *res, uint fuzzy_date);
1191
void fix_length_and_dec()
1193
Item_date::fix_length_and_dec();
1199
/* Function prototypes */
1201
bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
1202
timestamp_type type, String *str);
1204
#endif /* ITEM_TIMEFUNC_INCLUDED */