1#ifndef ITEM_TIMEFUNC_INCLUDED
2#define ITEM_TIMEFUNC_INCLUDED
3/* Copyright (c) 2000, 2011, Oracle and/or its affiliates.
4 Copyright (c) 2009-2011, Monty Program Ab
5
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.
9
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.
14
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 Street, Fifth Floor, Boston, MA 02110-1301, USA */
18
19
20/* Function items used by mysql */
21
22#ifdef USE_PRAGMA_INTERFACE
23#pragma interface /* gcc class implementation */
24#endif
25
26class MY_LOCALE;
27
28enum date_time_format_types
29{
30 TIME_ONLY= 0, TIME_MICROSECOND, DATE_ONLY, DATE_TIME, DATE_TIME_MICROSECOND
31};
32
33
34bool get_interval_value(Item *args,interval_type int_type, INTERVAL *interval);
35
36
37class Item_long_func_date_field: public Item_long_func
38{
39 bool check_arguments() const
40 { return args[0]->check_type_can_return_date(func_name()); }
41public:
42 Item_long_func_date_field(THD *thd, Item *a)
43 :Item_long_func(thd, a) { }
44};
45
46
47class Item_long_func_time_field: public Item_long_func
48{
49 bool check_arguments() const
50 { return args[0]->check_type_can_return_time(func_name()); }
51public:
52 Item_long_func_time_field(THD *thd, Item *a)
53 :Item_long_func(thd, a) { }
54};
55
56
57class Item_func_period_add :public Item_long_func
58{
59 bool check_arguments() const
60 { return check_argument_types_can_return_int(0, 2); }
61public:
62 Item_func_period_add(THD *thd, Item *a, Item *b): Item_long_func(thd, a, b) {}
63 longlong val_int();
64 const char *func_name() const { return "period_add"; }
65 void fix_length_and_dec()
66 {
67 max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
68 }
69 Item *get_copy(THD *thd)
70 { return get_item_copy<Item_func_period_add>(thd, this); }
71};
72
73
74class Item_func_period_diff :public Item_long_func
75{
76 bool check_arguments() const
77 { return check_argument_types_can_return_int(0, 2); }
78public:
79 Item_func_period_diff(THD *thd, Item *a, Item *b): Item_long_func(thd, a, b) {}
80 longlong val_int();
81 const char *func_name() const { return "period_diff"; }
82 void fix_length_and_dec()
83 {
84 decimals=0;
85 max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
86 }
87 Item *get_copy(THD *thd)
88 { return get_item_copy<Item_func_period_diff>(thd, this); }
89};
90
91
92class Item_func_to_days :public Item_long_func_date_field
93{
94public:
95 Item_func_to_days(THD *thd, Item *a): Item_long_func_date_field(thd, a) {}
96 longlong val_int();
97 const char *func_name() const { return "to_days"; }
98 void fix_length_and_dec()
99 {
100 decimals=0;
101 max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
102 maybe_null=1;
103 }
104 enum_monotonicity_info get_monotonicity_info() const;
105 longlong val_int_endpoint(bool left_endp, bool *incl_endp);
106 bool check_partition_func_processor(void *int_arg) {return FALSE;}
107 bool check_vcol_func_processor(void *arg) { return FALSE;}
108 bool check_valid_arguments_processor(void *int_arg)
109 {
110 return !has_date_args();
111 }
112 Item *get_copy(THD *thd)
113 { return get_item_copy<Item_func_to_days>(thd, this); }
114};
115
116
117class Item_func_to_seconds :public Item_longlong_func
118{
119 bool check_arguments() const
120 { return check_argument_types_can_return_date(0, arg_count); }
121public:
122 Item_func_to_seconds(THD *thd, Item *a): Item_longlong_func(thd, a) {}
123 longlong val_int();
124 const char *func_name() const { return "to_seconds"; }
125 void fix_length_and_dec()
126 {
127 decimals=0;
128 fix_char_length(12);
129 maybe_null= 1;
130 }
131 enum_monotonicity_info get_monotonicity_info() const;
132 longlong val_int_endpoint(bool left_endp, bool *incl_endp);
133 bool check_partition_func_processor(void *bool_arg) { return FALSE;}
134
135 /* Only meaningful with date part and optional time part */
136 bool check_valid_arguments_processor(void *int_arg)
137 {
138 return !has_date_args();
139 }
140 Item *get_copy(THD *thd)
141 { return get_item_copy<Item_func_to_seconds>(thd, this); }
142};
143
144
145class Item_func_dayofmonth :public Item_long_func_date_field
146{
147public:
148 Item_func_dayofmonth(THD *thd, Item *a): Item_long_func_date_field(thd, a) {}
149 longlong val_int();
150 const char *func_name() const { return "dayofmonth"; }
151 void fix_length_and_dec()
152 {
153 decimals=0;
154 max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
155 maybe_null=1;
156 }
157 bool check_partition_func_processor(void *int_arg) {return FALSE;}
158 bool check_vcol_func_processor(void *arg) { return FALSE;}
159 bool check_valid_arguments_processor(void *int_arg)
160 {
161 return !has_date_args();
162 }
163 Item *get_copy(THD *thd)
164 { return get_item_copy<Item_func_dayofmonth>(thd, this); }
165};
166
167
168class Item_func_month :public Item_func
169{
170public:
171 Item_func_month(THD *thd, Item *a): Item_func(thd, a)
172 { collation.set_numeric(); }
173 longlong val_int();
174 double val_real()
175 { DBUG_ASSERT(fixed == 1); return (double) Item_func_month::val_int(); }
176 String *val_str(String *str)
177 {
178 longlong nr= val_int();
179 if (null_value)
180 return 0;
181 str->set(nr, collation.collation);
182 return str;
183 }
184 bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
185 {
186 return get_date_from_int(ltime, fuzzydate);
187 }
188 const char *func_name() const { return "month"; }
189 const Type_handler *type_handler() const { return &type_handler_long; }
190 void fix_length_and_dec()
191 {
192 decimals= 0;
193 fix_char_length(2);
194 maybe_null=1;
195 }
196 bool check_partition_func_processor(void *int_arg) {return FALSE;}
197 bool check_vcol_func_processor(void *arg) { return FALSE;}
198 bool check_valid_arguments_processor(void *int_arg)
199 {
200 return !has_date_args();
201 }
202 Item *get_copy(THD *thd)
203 { return get_item_copy<Item_func_month>(thd, this); }
204};
205
206
207class Item_func_monthname :public Item_str_func
208{
209 MY_LOCALE *locale;
210public:
211 Item_func_monthname(THD *thd, Item *a): Item_str_func(thd, a) {}
212 const char *func_name() const { return "monthname"; }
213 String *val_str(String *str);
214 void fix_length_and_dec();
215 bool check_partition_func_processor(void *int_arg) {return TRUE;}
216 bool check_valid_arguments_processor(void *int_arg)
217 {
218 return !has_date_args();
219 }
220 bool check_vcol_func_processor(void *arg)
221 {
222 return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
223 }
224 Item *get_copy(THD *thd)
225 { return get_item_copy<Item_func_monthname>(thd, this); }
226};
227
228
229class Item_func_dayofyear :public Item_long_func_date_field
230{
231public:
232 Item_func_dayofyear(THD *thd, Item *a): Item_long_func_date_field(thd, a) {}
233 longlong val_int();
234 const char *func_name() const { return "dayofyear"; }
235 void fix_length_and_dec()
236 {
237 decimals= 0;
238 fix_char_length(3);
239 maybe_null=1;
240 }
241 bool check_partition_func_processor(void *int_arg) {return FALSE;}
242 bool check_vcol_func_processor(void *arg) { return FALSE;}
243 bool check_valid_arguments_processor(void *int_arg)
244 {
245 return !has_date_args();
246 }
247 Item *get_copy(THD *thd)
248 { return get_item_copy<Item_func_dayofyear>(thd, this); }
249};
250
251
252class Item_func_hour :public Item_long_func_time_field
253{
254public:
255 Item_func_hour(THD *thd, Item *a): Item_long_func_time_field(thd, a) {}
256 longlong val_int();
257 const char *func_name() const { return "hour"; }
258 void fix_length_and_dec()
259 {
260 decimals=0;
261 max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
262 maybe_null=1;
263 }
264 bool check_partition_func_processor(void *int_arg) {return FALSE;}
265 bool check_vcol_func_processor(void *arg) { return FALSE;}
266 bool check_valid_arguments_processor(void *int_arg)
267 {
268 return !has_time_args();
269 }
270 Item *get_copy(THD *thd)
271 { return get_item_copy<Item_func_hour>(thd, this); }
272};
273
274
275class Item_func_minute :public Item_long_func_time_field
276{
277public:
278 Item_func_minute(THD *thd, Item *a): Item_long_func_time_field(thd, a) {}
279 longlong val_int();
280 const char *func_name() const { return "minute"; }
281 void fix_length_and_dec()
282 {
283 decimals=0;
284 max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
285 maybe_null=1;
286 }
287 bool check_partition_func_processor(void *int_arg) {return FALSE;}
288 bool check_vcol_func_processor(void *arg) { return FALSE;}
289 bool check_valid_arguments_processor(void *int_arg)
290 {
291 return !has_time_args();
292 }
293 Item *get_copy(THD *thd)
294 { return get_item_copy<Item_func_minute>(thd, this); }
295};
296
297
298class Item_func_quarter :public Item_long_func_date_field
299{
300public:
301 Item_func_quarter(THD *thd, Item *a): Item_long_func_date_field(thd, a) {}
302 longlong val_int();
303 const char *func_name() const { return "quarter"; }
304 void fix_length_and_dec()
305 {
306 decimals=0;
307 max_length=1*MY_CHARSET_BIN_MB_MAXLEN;
308 maybe_null=1;
309 }
310 bool check_partition_func_processor(void *int_arg) {return FALSE;}
311 bool check_vcol_func_processor(void *arg) { return FALSE;}
312 bool check_valid_arguments_processor(void *int_arg)
313 {
314 return !has_date_args();
315 }
316 Item *get_copy(THD *thd)
317 { return get_item_copy<Item_func_quarter>(thd, this); }
318};
319
320
321class Item_func_second :public Item_long_func_time_field
322{
323public:
324 Item_func_second(THD *thd, Item *a): Item_long_func_time_field(thd, a) {}
325 longlong val_int();
326 const char *func_name() const { return "second"; }
327 void fix_length_and_dec()
328 {
329 decimals=0;
330 max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
331 maybe_null=1;
332 }
333 bool check_partition_func_processor(void *int_arg) {return FALSE;}
334 bool check_vcol_func_processor(void *arg) { return FALSE;}
335 bool check_valid_arguments_processor(void *int_arg)
336 {
337 return !has_time_args();
338 }
339 Item *get_copy(THD *thd)
340 { return get_item_copy<Item_func_second>(thd, this); }
341};
342
343
344class Item_func_week :public Item_long_func
345{
346 bool check_arguments() const
347 {
348 return args[0]->check_type_can_return_date(func_name()) ||
349 (arg_count > 1 && args[1]->check_type_can_return_int(func_name()));
350 }
351public:
352 Item_func_week(THD *thd, Item *a): Item_long_func(thd, a) {}
353 Item_func_week(THD *thd, Item *a, Item *b): Item_long_func(thd, a, b) {}
354 longlong val_int();
355 const char *func_name() const { return "week"; }
356 void fix_length_and_dec()
357 {
358 decimals=0;
359 max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
360 maybe_null=1;
361 }
362 bool check_vcol_func_processor(void *arg)
363 {
364 if (arg_count == 2)
365 return FALSE;
366 return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
367 }
368 bool check_valid_arguments_processor(void *int_arg)
369 {
370 return arg_count == 2;
371 }
372 Item *get_copy(THD *thd)
373 { return get_item_copy<Item_func_week>(thd, this); }
374};
375
376class Item_func_yearweek :public Item_long_func
377{
378 bool check_arguments() const
379 {
380 return args[0]->check_type_can_return_date(func_name()) ||
381 args[1]->check_type_can_return_int(func_name());
382 }
383public:
384 Item_func_yearweek(THD *thd, Item *a, Item *b)
385 :Item_long_func(thd, a, b) {}
386 longlong val_int();
387 const char *func_name() const { return "yearweek"; }
388 void fix_length_and_dec()
389 {
390 decimals=0;
391 max_length=6*MY_CHARSET_BIN_MB_MAXLEN;
392 maybe_null=1;
393 }
394 bool check_partition_func_processor(void *int_arg) {return FALSE;}
395 bool check_vcol_func_processor(void *arg) { return FALSE;}
396 bool check_valid_arguments_processor(void *int_arg)
397 {
398 return !has_date_args();
399 }
400 Item *get_copy(THD *thd)
401 { return get_item_copy<Item_func_yearweek>(thd, this); }
402};
403
404
405class Item_func_year :public Item_long_func_date_field
406{
407public:
408 Item_func_year(THD *thd, Item *a): Item_long_func_date_field(thd, a) {}
409 longlong val_int();
410 const char *func_name() const { return "year"; }
411 enum_monotonicity_info get_monotonicity_info() const;
412 longlong val_int_endpoint(bool left_endp, bool *incl_endp);
413 void fix_length_and_dec()
414 {
415 decimals=0;
416 max_length=4*MY_CHARSET_BIN_MB_MAXLEN;
417 maybe_null=1;
418 }
419 bool check_partition_func_processor(void *int_arg) {return FALSE;}
420 bool check_vcol_func_processor(void *arg) { return FALSE;}
421 bool check_valid_arguments_processor(void *int_arg)
422 {
423 return !has_date_args();
424 }
425 Item *get_copy(THD *thd)
426 { return get_item_copy<Item_func_year>(thd, this); }
427};
428
429
430class Item_func_weekday :public Item_func
431{
432 bool odbc_type;
433public:
434 Item_func_weekday(THD *thd, Item *a, bool type_arg):
435 Item_func(thd, a), odbc_type(type_arg) { collation.set_numeric(); }
436 longlong val_int();
437 double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
438 String *val_str(String *str)
439 {
440 DBUG_ASSERT(fixed == 1);
441 str->set(val_int(), &my_charset_bin);
442 return null_value ? 0 : str;
443 }
444 const char *func_name() const
445 {
446 return (odbc_type ? "dayofweek" : "weekday");
447 }
448 bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
449 {
450 return type_handler()->Item_get_date(this, ltime, fuzzydate);
451 }
452 const Type_handler *type_handler() const { return &type_handler_long; }
453 void fix_length_and_dec()
454 {
455 decimals= 0;
456 fix_char_length(1);
457 maybe_null=1;
458 }
459 bool check_partition_func_processor(void *int_arg) {return FALSE;}
460 bool check_vcol_func_processor(void *arg) { return FALSE;}
461 bool check_valid_arguments_processor(void *int_arg)
462 {
463 return !has_date_args();
464 }
465 Item *get_copy(THD *thd)
466 { return get_item_copy<Item_func_weekday>(thd, this); }
467};
468
469class Item_func_dayname :public Item_func_weekday
470{
471 MY_LOCALE *locale;
472 public:
473 Item_func_dayname(THD *thd, Item *a): Item_func_weekday(thd, a, 0) {}
474 const char *func_name() const { return "dayname"; }
475 String *val_str(String *str);
476 const Type_handler *type_handler() const { return &type_handler_varchar; }
477 void fix_length_and_dec();
478 bool check_partition_func_processor(void *int_arg) {return TRUE;}
479 bool check_vcol_func_processor(void *arg)
480 {
481 return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
482 }
483};
484
485
486class Item_func_seconds_hybrid: public Item_func_numhybrid
487{
488public:
489 Item_func_seconds_hybrid(THD *thd): Item_func_numhybrid(thd) {}
490 Item_func_seconds_hybrid(THD *thd, Item *a): Item_func_numhybrid(thd, a) {}
491 void fix_length_and_dec_generic(uint dec)
492 {
493 DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS);
494 decimals= dec;
495 max_length=17 + (decimals ? decimals + 1 : 0);
496 maybe_null= true;
497 if (decimals)
498 set_handler(&type_handler_newdecimal);
499 else
500 set_handler(type_handler_long_or_longlong());
501 }
502 double real_op() { DBUG_ASSERT(0); return 0; }
503 String *str_op(String *str) { DBUG_ASSERT(0); return 0; }
504 bool date_op(MYSQL_TIME *ltime, ulonglong fuzzydate)
505 {
506 DBUG_ASSERT(0);
507 return true;
508 }
509};
510
511
512class Item_func_unix_timestamp :public Item_func_seconds_hybrid
513{
514 bool get_timestamp_value(my_time_t *seconds, ulong *second_part);
515public:
516 Item_func_unix_timestamp(THD *thd): Item_func_seconds_hybrid(thd) {}
517 Item_func_unix_timestamp(THD *thd, Item *a):
518 Item_func_seconds_hybrid(thd, a) {}
519 const char *func_name() const { return "unix_timestamp"; }
520 enum_monotonicity_info get_monotonicity_info() const;
521 longlong val_int_endpoint(bool left_endp, bool *incl_endp);
522 bool check_partition_func_processor(void *int_arg) {return FALSE;}
523 /*
524 UNIX_TIMESTAMP() depends on the current timezone
525 (and thus may not be used as a partitioning function)
526 when its argument is NOT of the TIMESTAMP type.
527 */
528 bool check_valid_arguments_processor(void *int_arg)
529 {
530 return !has_timestamp_args();
531 }
532 bool check_vcol_func_processor(void *arg)
533 {
534 if (arg_count)
535 return FALSE;
536 return mark_unsupported_function(func_name(), "()", arg, VCOL_TIME_FUNC);
537 }
538 void fix_length_and_dec()
539 {
540 fix_length_and_dec_generic(arg_count ? args[0]->datetime_precision() : 0);
541 }
542 longlong int_op();
543 my_decimal *decimal_op(my_decimal* buf);
544 Item *get_copy(THD *thd)
545 { return get_item_copy<Item_func_unix_timestamp>(thd, this); }
546};
547
548
549class Item_func_time_to_sec :public Item_func_seconds_hybrid
550{
551public:
552 Item_func_time_to_sec(THD *thd, Item *item):
553 Item_func_seconds_hybrid(thd, item) {}
554 const char *func_name() const { return "time_to_sec"; }
555 bool check_partition_func_processor(void *int_arg) {return FALSE;}
556 bool check_vcol_func_processor(void *arg) { return FALSE;}
557 bool check_valid_arguments_processor(void *int_arg)
558 {
559 return !has_time_args();
560 }
561 void fix_length_and_dec()
562 {
563 fix_length_and_dec_generic(args[0]->time_precision());
564 }
565 longlong int_op();
566 my_decimal *decimal_op(my_decimal* buf);
567 Item *get_copy(THD *thd)
568 { return get_item_copy<Item_func_time_to_sec>(thd, this); }
569};
570
571
572class Item_temporal_func: public Item_func
573{
574public:
575 Item_temporal_func(THD *thd): Item_func(thd) {}
576 Item_temporal_func(THD *thd, Item *a): Item_func(thd, a) {}
577 Item_temporal_func(THD *thd, Item *a, Item *b): Item_func(thd, a, b) {}
578 Item_temporal_func(THD *thd, Item *a, Item *b, Item *c): Item_func(thd, a, b, c) {}
579 String *val_str(String *str);
580 longlong val_int() { return val_int_from_date(); }
581 double val_real() { return val_real_from_date(); }
582 bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date) { DBUG_ASSERT(0); return 1; }
583 my_decimal *val_decimal(my_decimal *decimal_value)
584 { return val_decimal_from_date(decimal_value); }
585};
586
587
588/**
589 Abstract class for functions returning TIME, DATE, DATETIME or string values,
590 whose data type depends on parameters and is set at fix_fields time.
591*/
592class Item_temporal_hybrid_func: public Item_hybrid_func
593{
594protected:
595 String ascii_buf; // Conversion buffer
596public:
597 Item_temporal_hybrid_func(THD *thd, Item *a, Item *b):
598 Item_hybrid_func(thd, a, b) {}
599
600 longlong val_int() { return val_int_from_date(); }
601 double val_real() { return val_real_from_date(); }
602 bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date)= 0;
603 my_decimal *val_decimal(my_decimal *decimal_value)
604 { return val_decimal_from_date(decimal_value); }
605
606 /**
607 Fix the returned timestamp to match field_type(),
608 which is important for val_str().
609 */
610 bool fix_temporal_type(MYSQL_TIME *ltime);
611 /**
612 Return string value in ASCII character set.
613 */
614 String *val_str_ascii(String *str);
615 /**
616 Return string value in @@character_set_connection.
617 */
618 String *val_str(String *str)
619 {
620 return val_str_from_val_str_ascii(str, &ascii_buf);
621 }
622};
623
624
625class Item_datefunc :public Item_temporal_func
626{
627public:
628 Item_datefunc(THD *thd): Item_temporal_func(thd) { }
629 Item_datefunc(THD *thd, Item *a): Item_temporal_func(thd, a) { }
630 Item_datefunc(THD *thd, Item *a, Item *b): Item_temporal_func(thd, a, b) { }
631 const Type_handler *type_handler() const { return &type_handler_newdate; }
632 void fix_length_and_dec()
633 {
634 fix_attributes_date();
635 maybe_null= (arg_count > 0);
636 }
637};
638
639
640class Item_timefunc :public Item_temporal_func
641{
642public:
643 Item_timefunc(THD *thd): Item_temporal_func(thd) {}
644 Item_timefunc(THD *thd, Item *a): Item_temporal_func(thd, a) {}
645 Item_timefunc(THD *thd, Item *a, Item *b): Item_temporal_func(thd, a, b) {}
646 Item_timefunc(THD *thd, Item *a, Item *b, Item *c):
647 Item_temporal_func(thd, a, b ,c) {}
648 const Type_handler *type_handler() const { return &type_handler_time2; }
649};
650
651
652class Item_datetimefunc :public Item_temporal_func
653{
654public:
655 Item_datetimefunc(THD *thd): Item_temporal_func(thd) {}
656 Item_datetimefunc(THD *thd, Item *a): Item_temporal_func(thd, a) {}
657 Item_datetimefunc(THD *thd, Item *a, Item *b, Item *c):
658 Item_temporal_func(thd, a, b ,c) {}
659 const Type_handler *type_handler() const { return &type_handler_datetime2; }
660};
661
662
663/* Abstract CURTIME function. Children should define what time zone is used */
664
665class Item_func_curtime :public Item_timefunc
666{
667 MYSQL_TIME ltime;
668 query_id_t last_query_id;
669public:
670 Item_func_curtime(THD *thd, uint dec): Item_timefunc(thd), last_query_id(0)
671 { decimals= dec; }
672 bool fix_fields(THD *, Item **);
673 void fix_length_and_dec() { fix_attributes_time(decimals); }
674 bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
675 /*
676 Abstract method that defines which time zone is used for conversion.
677 Converts time current time in my_time_t representation to broken-down
678 MYSQL_TIME representation using UTC-SYSTEM or per-thread time zone.
679 */
680 virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)=0;
681 bool check_vcol_func_processor(void *arg)
682 {
683 return mark_unsupported_function(func_name(), "()", arg, VCOL_TIME_FUNC);
684 }
685 void print(String *str, enum_query_type query_type);
686};
687
688
689class Item_func_curtime_local :public Item_func_curtime
690{
691public:
692 Item_func_curtime_local(THD *thd, uint dec): Item_func_curtime(thd, dec) {}
693 const char *func_name() const { return "curtime"; }
694 virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time);
695 Item *get_copy(THD *thd)
696 { return get_item_copy<Item_func_curtime_local>(thd, this); }
697};
698
699
700class Item_func_curtime_utc :public Item_func_curtime
701{
702public:
703 Item_func_curtime_utc(THD *thd, uint dec): Item_func_curtime(thd, dec) {}
704 const char *func_name() const { return "utc_time"; }
705 virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time);
706 Item *get_copy(THD *thd)
707 { return get_item_copy<Item_func_curtime_utc>(thd, this); }
708};
709
710
711/* Abstract CURDATE function. See also Item_func_curtime. */
712
713class Item_func_curdate :public Item_datefunc
714{
715 query_id_t last_query_id;
716 MYSQL_TIME ltime;
717public:
718 Item_func_curdate(THD *thd): Item_datefunc(thd), last_query_id(0) {}
719 bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
720 virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)=0;
721 bool check_vcol_func_processor(void *arg)
722 {
723 return mark_unsupported_function(func_name(), "()", arg, VCOL_TIME_FUNC);
724 }
725};
726
727
728class Item_func_curdate_local :public Item_func_curdate
729{
730public:
731 Item_func_curdate_local(THD *thd): Item_func_curdate(thd) {}
732 const char *func_name() const { return "curdate"; }
733 void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time);
734 Item *get_copy(THD *thd)
735 { return get_item_copy<Item_func_curdate_local>(thd, this); }
736};
737
738
739class Item_func_curdate_utc :public Item_func_curdate
740{
741public:
742 Item_func_curdate_utc(THD *thd): Item_func_curdate(thd) {}
743 const char *func_name() const { return "utc_date"; }
744 void store_now_in_TIME(THD* thd, MYSQL_TIME *now_time);
745 Item *get_copy(THD *thd)
746 { return get_item_copy<Item_func_curdate_utc>(thd, this); }
747};
748
749
750/* Abstract CURRENT_TIMESTAMP function. See also Item_func_curtime */
751
752class Item_func_now :public Item_datetimefunc
753{
754 MYSQL_TIME ltime;
755 query_id_t last_query_id;
756public:
757 Item_func_now(THD *thd, uint dec): Item_datetimefunc(thd), last_query_id(0)
758 { decimals= dec; }
759 bool fix_fields(THD *, Item **);
760 void fix_length_and_dec() { fix_attributes_datetime(decimals); }
761 bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
762 virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time)=0;
763 bool check_vcol_func_processor(void *arg)
764 {
765 /*
766 NOW is safe for replication as slaves will run with same time as
767 master
768 */
769 return mark_unsupported_function(func_name(), "()", arg, VCOL_TIME_FUNC);
770 }
771 void print(String *str, enum_query_type query_type);
772};
773
774
775class Item_func_now_local :public Item_func_now
776{
777public:
778 Item_func_now_local(THD *thd, uint dec): Item_func_now(thd, dec) {}
779 const char *func_name() const { return "current_timestamp"; }
780 int save_in_field(Field *field, bool no_conversions);
781 virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time);
782 virtual enum Functype functype() const { return NOW_FUNC; }
783 Item *get_copy(THD *thd)
784 { return get_item_copy<Item_func_now_local>(thd, this); }
785};
786
787
788class Item_func_now_utc :public Item_func_now
789{
790public:
791 Item_func_now_utc(THD *thd, uint dec): Item_func_now(thd, dec) {}
792 const char *func_name() const { return "utc_timestamp"; }
793 virtual void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time);
794 virtual enum Functype functype() const { return NOW_UTC_FUNC; }
795 virtual bool check_vcol_func_processor(void *arg)
796 {
797 return mark_unsupported_function(func_name(), "()", arg,
798 VCOL_TIME_FUNC | VCOL_NON_DETERMINISTIC);
799 }
800 Item *get_copy(THD *thd)
801 { return get_item_copy<Item_func_now_utc>(thd, this); }
802};
803
804
805/*
806 This is like NOW(), but always uses the real current time, not the
807 query_start(). This matches the Oracle behavior.
808*/
809class Item_func_sysdate_local :public Item_func_now
810{
811public:
812 Item_func_sysdate_local(THD *thd, uint dec): Item_func_now(thd, dec) {}
813 bool const_item() const { return 0; }
814 const char *func_name() const { return "sysdate"; }
815 void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time);
816 bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
817 table_map used_tables() const { return RAND_TABLE_BIT; }
818 bool check_vcol_func_processor(void *arg)
819 {
820 return mark_unsupported_function(func_name(), "()", arg,
821 VCOL_TIME_FUNC | VCOL_NON_DETERMINISTIC);
822 }
823 virtual enum Functype functype() const { return SYSDATE_FUNC; }
824 Item *get_copy(THD *thd)
825 { return get_item_copy<Item_func_sysdate_local>(thd, this); }
826};
827
828
829class Item_func_from_days :public Item_datefunc
830{
831 bool check_arguments() const
832 { return args[0]->check_type_can_return_int(func_name()); }
833public:
834 Item_func_from_days(THD *thd, Item *a): Item_datefunc(thd, a) {}
835 const char *func_name() const { return "from_days"; }
836 bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
837 bool check_partition_func_processor(void *int_arg) {return FALSE;}
838 bool check_vcol_func_processor(void *arg) { return FALSE;}
839 bool check_valid_arguments_processor(void *int_arg)
840 {
841 return has_date_args() || has_time_args();
842 }
843 Item *get_copy(THD *thd)
844 { return get_item_copy<Item_func_from_days>(thd, this); }
845};
846
847
848class Item_func_date_format :public Item_str_func
849{
850 bool check_arguments() const
851 {
852 return args[0]->check_type_can_return_date(func_name()) ||
853 check_argument_types_can_return_text(1, arg_count);
854 }
855 const MY_LOCALE *locale;
856 int fixed_length;
857 String value;
858protected:
859 bool is_time_format;
860public:
861 Item_func_date_format(THD *thd, Item *a, Item *b):
862 Item_str_func(thd, a, b), locale(0), is_time_format(false) {}
863 Item_func_date_format(THD *thd, Item *a, Item *b, Item *c):
864 Item_str_func(thd, a, b, c), locale(0), is_time_format(false) {}
865 String *val_str(String *str);
866 const char *func_name() const { return "date_format"; }
867 void fix_length_and_dec();
868 uint format_length(const String *format);
869 bool eq(const Item *item, bool binary_cmp) const;
870 bool check_vcol_func_processor(void *arg)
871 {
872 if (arg_count > 2)
873 return false;
874 return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
875 }
876 Item *get_copy(THD *thd)
877 { return get_item_copy<Item_func_date_format>(thd, this); }
878};
879
880class Item_func_time_format: public Item_func_date_format
881{
882public:
883 Item_func_time_format(THD *thd, Item *a, Item *b):
884 Item_func_date_format(thd, a, b) { is_time_format= true; }
885 const char *func_name() const { return "time_format"; }
886 bool check_vcol_func_processor(void *arg) { return false; }
887 Item *get_copy(THD *thd)
888 { return get_item_copy<Item_func_time_format>(thd, this); }
889};
890
891
892class Item_func_from_unixtime :public Item_datetimefunc
893{
894 bool check_arguments() const
895 { return args[0]->check_type_can_return_decimal(func_name()); }
896 Time_zone *tz;
897 public:
898 Item_func_from_unixtime(THD *thd, Item *a): Item_datetimefunc(thd, a) {}
899 const char *func_name() const { return "from_unixtime"; }
900 void fix_length_and_dec();
901 bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
902 Item *get_copy(THD *thd)
903 { return get_item_copy<Item_func_from_unixtime>(thd, this); }
904};
905
906
907/*
908 We need Time_zone class declaration for storing pointers in
909 Item_func_convert_tz.
910*/
911class Time_zone;
912
913/*
914 This class represents CONVERT_TZ() function.
915 The important fact about this function that it is handled in special way.
916 When such function is met in expression time_zone system tables are added
917 to global list of tables to open, so later those already opened and locked
918 tables can be used during this function calculation for loading time zone
919 descriptions.
920*/
921class Item_func_convert_tz :public Item_datetimefunc
922{
923 bool check_arguments() const
924 {
925 return args[0]->check_type_can_return_date(func_name()) ||
926 check_argument_types_can_return_text(1, arg_count);
927 }
928 /*
929 If time zone parameters are constants we are caching objects that
930 represent them (we use separate from_tz_cached/to_tz_cached members
931 to indicate this fact, since NULL is legal value for from_tz/to_tz
932 members.
933 */
934 bool from_tz_cached, to_tz_cached;
935 Time_zone *from_tz, *to_tz;
936 public:
937 Item_func_convert_tz(THD *thd, Item *a, Item *b, Item *c):
938 Item_datetimefunc(thd, a, b, c), from_tz_cached(0), to_tz_cached(0) {}
939 const char *func_name() const { return "convert_tz"; }
940 void fix_length_and_dec()
941 {
942 fix_attributes_datetime(args[0]->datetime_precision());
943 maybe_null= true;
944 }
945 bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
946 void cleanup();
947 Item *get_copy(THD *thd)
948 { return get_item_copy<Item_func_convert_tz>(thd, this); }
949};
950
951
952class Item_func_sec_to_time :public Item_timefunc
953{
954 bool check_arguments() const
955 { return args[0]->check_type_can_return_decimal(func_name()); }
956public:
957 Item_func_sec_to_time(THD *thd, Item *item): Item_timefunc(thd, item) {}
958 bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
959 void fix_length_and_dec()
960 {
961 fix_attributes_time(args[0]->decimals);
962 maybe_null= true;
963 }
964 const char *func_name() const { return "sec_to_time"; }
965 Item *get_copy(THD *thd)
966 { return get_item_copy<Item_func_sec_to_time>(thd, this); }
967};
968
969
970class Item_date_add_interval :public Item_temporal_hybrid_func
971{
972public:
973 const interval_type int_type; // keep it public
974 const bool date_sub_interval; // keep it public
975 Item_date_add_interval(THD *thd, Item *a, Item *b, interval_type type_arg,
976 bool neg_arg):
977 Item_temporal_hybrid_func(thd, a, b),int_type(type_arg),
978 date_sub_interval(neg_arg) {}
979 const char *func_name() const { return "date_add_interval"; }
980 void fix_length_and_dec();
981 bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
982 bool eq(const Item *item, bool binary_cmp) const;
983 void print(String *str, enum_query_type query_type);
984 enum precedence precedence() const { return ADDINTERVAL_PRECEDENCE; }
985 bool need_parentheses_in_default() { return true; }
986 Item *get_copy(THD *thd)
987 { return get_item_copy<Item_date_add_interval>(thd, this); }
988};
989
990
991class Item_extract :public Item_int_func
992{
993 bool date_value;
994 void set_date_length(uint32 length)
995 {
996 /*
997 Although DATE components (e.g. YEAR, YEAR_MONTH, QUARTER, MONTH, WEEK)
998 cannot have a sign, we should probably still add +1,
999 because all around the code we assume that max_length is sign inclusive.
1000 Another options is to set unsigned_flag to "true".
1001 */
1002 max_length= length; //QQ: see above
1003 date_value= true;
1004 }
1005 void set_time_length(uint32 length)
1006 {
1007 max_length= length + 1/*sign*/;
1008 date_value= false;
1009 }
1010 public:
1011 const interval_type int_type; // keep it public
1012 Item_extract(THD *thd, interval_type type_arg, Item *a):
1013 Item_int_func(thd, a), int_type(type_arg) {}
1014 const Type_handler *type_handler() const
1015 {
1016 switch (int_type) {
1017 case INTERVAL_YEAR:
1018 case INTERVAL_YEAR_MONTH:
1019 case INTERVAL_QUARTER:
1020 case INTERVAL_MONTH:
1021 case INTERVAL_WEEK:
1022 case INTERVAL_DAY:
1023 case INTERVAL_DAY_HOUR:
1024 case INTERVAL_DAY_MINUTE:
1025 case INTERVAL_DAY_SECOND:
1026 case INTERVAL_HOUR:
1027 case INTERVAL_HOUR_MINUTE:
1028 case INTERVAL_HOUR_SECOND:
1029 case INTERVAL_MINUTE:
1030 case INTERVAL_MINUTE_SECOND:
1031 case INTERVAL_SECOND:
1032 case INTERVAL_MICROSECOND:
1033 case INTERVAL_SECOND_MICROSECOND:
1034 return &type_handler_long;
1035 case INTERVAL_DAY_MICROSECOND:
1036 case INTERVAL_HOUR_MICROSECOND:
1037 case INTERVAL_MINUTE_MICROSECOND:
1038 return &type_handler_longlong;
1039 case INTERVAL_LAST:
1040 break;
1041 }
1042 DBUG_ASSERT(0);
1043 return &type_handler_longlong;
1044 }
1045 longlong val_int();
1046 enum Functype functype() const { return EXTRACT_FUNC; }
1047 const char *func_name() const { return "extract"; }
1048 void fix_length_and_dec();
1049 bool eq(const Item *item, bool binary_cmp) const;
1050 void print(String *str, enum_query_type query_type);
1051 bool check_partition_func_processor(void *int_arg) {return FALSE;}
1052 bool check_vcol_func_processor(void *arg)
1053 {
1054 if (int_type != INTERVAL_WEEK)
1055 return FALSE;
1056 return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
1057 }
1058 bool check_valid_arguments_processor(void *int_arg)
1059 {
1060 switch (int_type) {
1061 case INTERVAL_YEAR:
1062 case INTERVAL_YEAR_MONTH:
1063 case INTERVAL_QUARTER:
1064 case INTERVAL_MONTH:
1065 /* case INTERVAL_WEEK: Not allowed as partitioning function, bug#57071 */
1066 case INTERVAL_DAY:
1067 return !has_date_args();
1068 case INTERVAL_DAY_HOUR:
1069 case INTERVAL_DAY_MINUTE:
1070 case INTERVAL_DAY_SECOND:
1071 case INTERVAL_DAY_MICROSECOND:
1072 return !has_datetime_args();
1073 case INTERVAL_HOUR:
1074 case INTERVAL_HOUR_MINUTE:
1075 case INTERVAL_HOUR_SECOND:
1076 case INTERVAL_MINUTE:
1077 case INTERVAL_MINUTE_SECOND:
1078 case INTERVAL_SECOND:
1079 case INTERVAL_MICROSECOND:
1080 case INTERVAL_HOUR_MICROSECOND:
1081 case INTERVAL_MINUTE_MICROSECOND:
1082 case INTERVAL_SECOND_MICROSECOND:
1083 return !has_time_args();
1084 default:
1085 /*
1086 INTERVAL_LAST is only an end marker,
1087 INTERVAL_WEEK depends on default_week_format which is a session
1088 variable and cannot be used for partitioning. See bug#57071.
1089 */
1090 break;
1091 }
1092 return true;
1093 }
1094 Item *get_copy(THD *thd)
1095 { return get_item_copy<Item_extract>(thd, this); }
1096};
1097
1098
1099class Item_char_typecast :public Item_str_func
1100{
1101 uint cast_length;
1102 CHARSET_INFO *cast_cs, *from_cs;
1103 bool charset_conversion;
1104 String tmp_value;
1105 bool m_suppress_warning_to_error_escalation;
1106 bool has_explicit_length() const { return cast_length != ~0U; }
1107 String *reuse(String *src, size_t length);
1108 String *copy(String *src, CHARSET_INFO *cs);
1109 uint adjusted_length_with_warn(uint length);
1110 void check_truncation_with_warn(String *src, size_t dstlen);
1111 void fix_length_and_dec_internal(CHARSET_INFO *fromcs);
1112public:
1113 Item_char_typecast(THD *thd, Item *a, uint length_arg, CHARSET_INFO *cs_arg):
1114 Item_str_func(thd, a), cast_length(length_arg), cast_cs(cs_arg),
1115 m_suppress_warning_to_error_escalation(false) {}
1116 enum Functype functype() const { return CHAR_TYPECAST_FUNC; }
1117 bool eq(const Item *item, bool binary_cmp) const;
1118 const char *func_name() const { return "cast_as_char"; }
1119 CHARSET_INFO *cast_charset() const { return cast_cs; }
1120 String *val_str(String *a);
1121 void fix_length_and_dec_generic();
1122 void fix_length_and_dec_numeric();
1123 void fix_length_and_dec_str()
1124 {
1125 fix_length_and_dec_generic();
1126 m_suppress_warning_to_error_escalation= true;
1127 }
1128 void fix_length_and_dec()
1129 {
1130 args[0]->type_handler()->Item_char_typecast_fix_length_and_dec(this);
1131 }
1132 void print(String *str, enum_query_type query_type);
1133 bool need_parentheses_in_default() { return true; }
1134 Item *get_copy(THD *thd)
1135 { return get_item_copy<Item_char_typecast>(thd, this); }
1136};
1137
1138
1139class Item_temporal_typecast: public Item_temporal_func
1140{
1141public:
1142 Item_temporal_typecast(THD *thd, Item *a): Item_temporal_func(thd, a) {}
1143 virtual const char *cast_type() const = 0;
1144 void print(String *str, enum_query_type query_type);
1145};
1146
1147class Item_date_typecast :public Item_temporal_typecast
1148{
1149public:
1150 Item_date_typecast(THD *thd, Item *a): Item_temporal_typecast(thd, a) {}
1151 const char *func_name() const { return "cast_as_date"; }
1152 bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date);
1153 const char *cast_type() const { return "date"; }
1154 const Type_handler *type_handler() const { return &type_handler_newdate; }
1155 void fix_length_and_dec()
1156 {
1157 args[0]->type_handler()->Item_date_typecast_fix_length_and_dec(this);
1158 }
1159 Item *get_copy(THD *thd)
1160 { return get_item_copy<Item_date_typecast>(thd, this); }
1161};
1162
1163
1164class Item_time_typecast :public Item_temporal_typecast
1165{
1166public:
1167 Item_time_typecast(THD *thd, Item *a, uint dec_arg):
1168 Item_temporal_typecast(thd, a) { decimals= dec_arg; }
1169 const char *func_name() const { return "cast_as_time"; }
1170 bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date);
1171 const char *cast_type() const { return "time"; }
1172 const Type_handler *type_handler() const { return &type_handler_time2; }
1173 void fix_length_and_dec()
1174 {
1175 args[0]->type_handler()->Item_time_typecast_fix_length_and_dec(this);
1176 }
1177 Item *get_copy(THD *thd)
1178 { return get_item_copy<Item_time_typecast>(thd, this); }
1179};
1180
1181
1182class Item_datetime_typecast :public Item_temporal_typecast
1183{
1184public:
1185 Item_datetime_typecast(THD *thd, Item *a, uint dec_arg):
1186 Item_temporal_typecast(thd, a) { decimals= dec_arg; }
1187 const char *func_name() const { return "cast_as_datetime"; }
1188 const char *cast_type() const { return "datetime"; }
1189 const Type_handler *type_handler() const { return &type_handler_datetime2; }
1190 bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date);
1191 void fix_length_and_dec()
1192 {
1193 args[0]->type_handler()->Item_datetime_typecast_fix_length_and_dec(this);
1194 }
1195 Item *get_copy(THD *thd)
1196 { return get_item_copy<Item_datetime_typecast>(thd, this); }
1197};
1198
1199
1200class Item_func_makedate :public Item_datefunc
1201{
1202 bool check_arguments() const
1203 { return check_argument_types_can_return_int(0, arg_count); }
1204public:
1205 Item_func_makedate(THD *thd, Item *a, Item *b):
1206 Item_datefunc(thd, a, b) {}
1207 const char *func_name() const { return "makedate"; }
1208 bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date);
1209 Item *get_copy(THD *thd)
1210 { return get_item_copy<Item_func_makedate>(thd, this); }
1211};
1212
1213
1214class Item_func_add_time :public Item_temporal_hybrid_func
1215{
1216 const bool is_date;
1217 int sign;
1218
1219public:
1220 Item_func_add_time(THD *thd, Item *a, Item *b, bool type_arg, bool neg_arg):
1221 Item_temporal_hybrid_func(thd, a, b), is_date(type_arg)
1222 { sign= neg_arg ? -1 : 1; }
1223 void fix_length_and_dec();
1224 bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date);
1225 void print(String *str, enum_query_type query_type);
1226 const char *func_name() const { return "add_time"; }
1227 Item *get_copy(THD *thd)
1228 { return get_item_copy<Item_func_add_time>(thd, this); }
1229};
1230
1231class Item_func_timediff :public Item_timefunc
1232{
1233 bool check_arguments() const
1234 { return check_argument_types_can_return_time(0, arg_count); }
1235public:
1236 Item_func_timediff(THD *thd, Item *a, Item *b): Item_timefunc(thd, a, b) {}
1237 const char *func_name() const { return "timediff"; }
1238 void fix_length_and_dec()
1239 {
1240 uint dec= MY_MAX(args[0]->time_precision(), args[1]->time_precision());
1241 fix_attributes_time(dec);
1242 maybe_null= true;
1243 }
1244 bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date);
1245 Item *get_copy(THD *thd)
1246 { return get_item_copy<Item_func_timediff>(thd, this); }
1247};
1248
1249class Item_func_maketime :public Item_timefunc
1250{
1251 bool check_arguments() const
1252 {
1253 return check_argument_types_can_return_int(0, 2) ||
1254 args[2]->check_type_can_return_decimal(func_name());
1255 }
1256public:
1257 Item_func_maketime(THD *thd, Item *a, Item *b, Item *c):
1258 Item_timefunc(thd, a, b, c)
1259 {}
1260 void fix_length_and_dec()
1261 {
1262 fix_attributes_time(args[2]->decimals);
1263 maybe_null= true;
1264 }
1265 const char *func_name() const { return "maketime"; }
1266 bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date);
1267 Item *get_copy(THD *thd)
1268 { return get_item_copy<Item_func_maketime>(thd, this); }
1269};
1270
1271
1272class Item_func_microsecond :public Item_long_func_time_field
1273{
1274public:
1275 Item_func_microsecond(THD *thd, Item *a): Item_long_func_time_field(thd, a) {}
1276 longlong val_int();
1277 const char *func_name() const { return "microsecond"; }
1278 void fix_length_and_dec()
1279 {
1280 decimals=0;
1281 maybe_null=1;
1282 fix_char_length(6);
1283 }
1284 bool check_partition_func_processor(void *int_arg) {return FALSE;}
1285 bool check_vcol_func_processor(void *arg) { return FALSE;}
1286 bool check_valid_arguments_processor(void *int_arg)
1287 {
1288 return !has_time_args();
1289 }
1290 Item *get_copy(THD *thd)
1291 { return get_item_copy<Item_func_microsecond>(thd, this); }
1292};
1293
1294
1295class Item_func_timestamp_diff :public Item_longlong_func
1296{
1297 bool check_arguments() const
1298 { return check_argument_types_can_return_date(0, arg_count); }
1299 const interval_type int_type;
1300public:
1301 Item_func_timestamp_diff(THD *thd, Item *a, Item *b, interval_type type_arg):
1302 Item_longlong_func(thd, a, b), int_type(type_arg) {}
1303 const char *func_name() const { return "timestampdiff"; }
1304 longlong val_int();
1305 void fix_length_and_dec()
1306 {
1307 decimals=0;
1308 maybe_null=1;
1309 }
1310 virtual void print(String *str, enum_query_type query_type);
1311 Item *get_copy(THD *thd)
1312 { return get_item_copy<Item_func_timestamp_diff>(thd, this); }
1313};
1314
1315
1316enum date_time_format
1317{
1318 USA_FORMAT, JIS_FORMAT, ISO_FORMAT, EUR_FORMAT, INTERNAL_FORMAT
1319};
1320
1321class Item_func_get_format :public Item_str_ascii_func
1322{
1323public:
1324 const timestamp_type type; // keep it public
1325 Item_func_get_format(THD *thd, timestamp_type type_arg, Item *a):
1326 Item_str_ascii_func(thd, a), type(type_arg)
1327 {}
1328 String *val_str_ascii(String *str);
1329 const char *func_name() const { return "get_format"; }
1330 void fix_length_and_dec()
1331 {
1332 maybe_null= 1;
1333 decimals=0;
1334 fix_length_and_charset(17, default_charset());
1335 }
1336 virtual void print(String *str, enum_query_type query_type);
1337 Item *get_copy(THD *thd)
1338 { return get_item_copy<Item_func_get_format>(thd, this); }
1339};
1340
1341
1342class Item_func_str_to_date :public Item_temporal_hybrid_func
1343{
1344 timestamp_type cached_timestamp_type;
1345 bool const_item;
1346 String subject_converter;
1347 String format_converter;
1348 CHARSET_INFO *internal_charset;
1349public:
1350 Item_func_str_to_date(THD *thd, Item *a, Item *b):
1351 Item_temporal_hybrid_func(thd, a, b), const_item(false),
1352 internal_charset(NULL)
1353 {}
1354 bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date);
1355 const char *func_name() const { return "str_to_date"; }
1356 void fix_length_and_dec();
1357 Item *get_copy(THD *thd)
1358 { return get_item_copy<Item_func_str_to_date>(thd, this); }
1359};
1360
1361
1362class Item_func_last_day :public Item_datefunc
1363{
1364 bool check_arguments() const
1365 { return args[0]->check_type_can_return_date(func_name()); }
1366public:
1367 Item_func_last_day(THD *thd, Item *a): Item_datefunc(thd, a) {}
1368 const char *func_name() const { return "last_day"; }
1369 bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date);
1370 Item *get_copy(THD *thd)
1371 { return get_item_copy<Item_func_last_day>(thd, this); }
1372};
1373
1374#endif /* ITEM_TIMEFUNC_INCLUDED */
1375