1 #ifndef ITEM_TIMEFUNC_INCLUDED
2 #define ITEM_TIMEFUNC_INCLUDED
34 const char *func_name()
const {
return "period_add"; }
35 void fix_length_and_dec()
47 const char *func_name()
const {
return "period_diff"; }
48 void fix_length_and_dec()
60 const char *func_name()
const {
return "to_days"; }
61 void fix_length_and_dec()
66 enum_monotonicity_info get_monotonicity_info()
const;
67 longlong val_int_endpoint(
bool left_endp,
bool *incl_endp);
68 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
69 bool check_valid_arguments_processor(uchar *int_arg)
71 return !has_date_args();
81 const char *func_name()
const {
return "to_seconds"; }
82 void fix_length_and_dec()
87 enum_monotonicity_info get_monotonicity_info()
const;
88 longlong val_int_endpoint(
bool left_endp,
bool *incl_endp);
89 bool check_partition_func_processor(uchar *bool_arg) {
return FALSE;}
91 bool intro_version(uchar *int_arg)
94 int *input_version= (
int*)int_arg;
96 int output_version= max(*input_version, 50500);
97 *input_version= output_version;
102 bool check_valid_arguments_processor(uchar *int_arg)
104 return !has_date_args();
114 const char *func_name()
const {
return "dayofmonth"; }
115 void fix_length_and_dec()
120 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
121 bool check_valid_arguments_processor(uchar *int_arg)
123 return !has_date_args();
137 { DBUG_ASSERT(fixed == 1);
return (
double) Item_func_month::val_int(); }
140 longlong nr= val_int();
143 str->set(nr, collation.collation);
146 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate)
154 const char *func_name()
const {
return "month"; }
155 enum Item_result result_type ()
const {
return INT_RESULT; }
156 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();
174 const char *func_name()
const {
return "monthname"; }
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();
190 const char *func_name()
const {
return "dayofyear"; }
191 void fix_length_and_dec()
196 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
197 bool check_valid_arguments_processor(uchar *int_arg)
199 return !has_date_args();
209 const char *func_name()
const {
return "hour"; }
210 void fix_length_and_dec()
215 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
216 bool check_valid_arguments_processor(uchar *int_arg)
218 return !has_time_args();
228 const char *func_name()
const {
return "minute"; }
229 void fix_length_and_dec()
234 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
235 bool check_valid_arguments_processor(uchar *int_arg)
237 return !has_time_args();
247 const char *func_name()
const {
return "quarter"; }
248 void fix_length_and_dec()
253 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
254 bool check_valid_arguments_processor(uchar *int_arg)
256 return !has_date_args();
266 const char *func_name()
const {
return "second"; }
267 void fix_length_and_dec()
272 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
273 bool check_valid_arguments_processor(uchar *int_arg)
275 return !has_time_args();
285 const char *func_name()
const {
return "week"; }
286 void fix_length_and_dec()
298 const char *func_name()
const {
return "yearweek"; }
299 void fix_length_and_dec()
304 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
305 bool check_valid_arguments_processor(uchar *int_arg)
307 return !has_date_args();
317 const char *func_name()
const {
return "year"; }
318 enum_monotonicity_info get_monotonicity_info()
const;
319 longlong val_int_endpoint(
bool left_endp,
bool *incl_endp);
320 void fix_length_and_dec()
325 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
326 bool check_valid_arguments_processor(uchar *int_arg)
328 return !has_date_args();
341 :
Item_func(a), odbc_type(type_arg) { collation.set_numeric(); }
343 double val_real() { DBUG_ASSERT(fixed == 1);
return (
double) val_int(); }
346 DBUG_ASSERT(fixed == 1);
347 str->set(val_int(), &my_charset_bin);
348 return null_value ? 0 : str;
350 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate)
358 const char *func_name()
const
360 return (odbc_type ?
"dayofweek" :
"weekday");
362 enum Item_result result_type ()
const {
return INT_RESULT; }
363 void fix_length_and_dec()
368 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
369 bool check_valid_arguments_processor(uchar *int_arg)
371 return !has_date_args();
385 const char *func_name()
const {
return "dayname"; }
387 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate)
395 enum Item_result result_type ()
const {
return STRING_RESULT; }
396 void fix_length_and_dec();
397 bool check_partition_func_processor(uchar *int_arg) {
return TRUE;}
420 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate)
428 enum Item_result result_type()
const
430 return decimals ? DECIMAL_RESULT : INT_RESULT;
440 const char *func_name()
const {
return "unix_timestamp"; }
441 enum_monotonicity_info get_monotonicity_info()
const;
442 longlong val_int_endpoint(
bool left_endp,
bool *incl_endp);
443 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
449 bool check_valid_arguments_processor(uchar *int_arg)
451 return !has_timestamp_args();
453 void fix_length_and_dec()
455 fix_length_and_dec_and_charset_datetime(11, arg_count == 0 ? 0 :
467 const char *func_name()
const {
return "time_to_sec"; }
468 void fix_length_and_dec()
473 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
474 bool check_valid_arguments_processor(uchar *int_arg)
476 return !has_time_args();
488 bool check_precision();
494 enum Item_result result_type ()
const
496 return STRING_RESULT;
500 return &my_charset_bin;
527 enum_field_types cached_field_type;
542 enum Item_result result_type ()
const {
return STRING_RESULT; }
543 enum_field_types field_type()
const {
return cached_field_type; }
552 DBUG_ASSERT(fixed == 1);
553 return cached_field_type == MYSQL_TYPE_STRING ?
554 collation.collation : &my_charset_bin;
560 longlong val_int() {
return val_int_from_decimal(); }
561 double val_real() {
return val_real_from_decimal(); }
573 return val_str_from_val_str_ascii(str, &ascii_buf);
575 bool get_date(
MYSQL_TIME *ltime, uint fuzzydate);
596 enum_field_types field_type()
const {
return MYSQL_TYPE_DATE; }
603 return val_string_from_date(str);
607 return val_int_from_date();
610 double val_real() {
return (
double) val_int(); }
611 const char *func_name()
const {
return "date"; }
612 void fix_length_and_dec()
614 fix_length_and_dec_and_charset_datetime(MAX_DATE_WIDTH, 0);
618 DBUG_ASSERT(fixed == 1);
619 return val_decimal_from_date(decimal_value);
623 return save_date_in_field(field);
628 virtual bool get_date(
MYSQL_TIME *res, uint fuzzy_date)= 0;
646 enum_field_types field_type()
const {
return MYSQL_TYPE_DATETIME; }
647 double val_real() {
return val_real_from_decimal(); }
650 return val_string_from_datetime(str);
654 return val_int_from_datetime();
659 DBUG_ASSERT(fixed == 1);
660 return val_decimal_from_date(decimal_value);
664 return save_date_in_field(field);
673 virtual bool get_date(
MYSQL_TIME *res, uint fuzzy_date)= 0;
687 enum_field_types field_type()
const {
return MYSQL_TYPE_TIME; }
688 double val_real() {
return val_real_from_decimal(); }
691 DBUG_ASSERT(fixed == 1);
692 return val_decimal_from_time(decimal_value);
696 return save_time_in_field(field);
700 return val_int_from_time();
703 bool get_date(
MYSQL_TIME *res, uint fuzzy_date)
709 return val_string_from_time(str);
729 longlong time_packed;
730 char string_buff[MAX_DATE_STRING_REP_LENGTH];
744 string_buff[0]=
'\0';
751 time.time_type= MYSQL_TIMESTAMP_NONE;
761 DBUG_ASSERT(time.time_type != MYSQL_TIMESTAMP_NONE);
810 DBUG_ASSERT(time.time_type != MYSQL_TIMESTAMP_NONE);
819 DBUG_ASSERT(time.time_type != MYSQL_TIMESTAMP_NONE);
840 DBUG_ASSERT(time.time_type != MYSQL_TIMESTAMP_NONE);
868 fix_length_and_dec();
871 const char *func_name()
const {
return "date_literal"; }
872 void print(
String *str, enum_query_type query_type);
878 bool get_date(
MYSQL_TIME *ltime, uint fuzzy_date)
881 return cached_time.
get_date(ltime, fuzzy_date);
886 return cached_time.
val_str(str);
888 void fix_length_and_dec()
890 fix_length_and_dec_and_charset_datetime(MAX_DATE_WIDTH, 0);
892 bool check_partition_func_processor(uchar *int_arg)
896 bool basic_const_item()
const {
return true; }
897 bool const_item()
const {
return true; }
898 table_map used_tables()
const {
return (table_map) 0L; }
903 item_name= orig_name;
905 bool eq(
const Item *item,
bool binary_cmp)
const;
923 decimals= MY_MIN(dec_arg, DATETIME_MAX_DECIMALS);
924 cached_time.
set_time(ltime, decimals);
925 fix_length_and_dec();
928 const char *func_name()
const {
return "time_literal"; }
929 void print(
String *str, enum_query_type query_type);
943 return cached_time.
val_str(str);
945 void fix_length_and_dec()
947 fix_length_and_dec_and_charset_datetime(MAX_TIME_WIDTH, decimals);
949 bool check_partition_func_processor(uchar *int_arg)
953 bool basic_const_item()
const {
return true; }
954 bool const_item()
const {
return true; }
955 table_map used_tables()
const {
return (table_map) 0L; }
960 item_name= orig_name;
962 bool eq(
const Item *item,
bool binary_cmp)
const;
980 decimals= MY_MIN(dec_arg, DATETIME_MAX_DECIMALS);
982 fix_length_and_dec();
985 const char *func_name()
const {
return "datetime_literal"; }
986 void print(
String *str, enum_query_type query_type);
992 bool get_date(
MYSQL_TIME *ltime, uint fuzzy_date)
995 return cached_time.
get_date(ltime, fuzzy_date);
1000 return cached_time.
val_str(str);
1002 void fix_length_and_dec()
1004 fix_length_and_dec_and_charset_datetime(MAX_DATETIME_WIDTH, decimals);
1006 bool check_partition_func_processor(uchar *int_arg)
1010 bool basic_const_item()
const {
return true; }
1011 bool const_item()
const {
return true; }
1012 table_map used_tables()
const {
return (table_map) 0L; }
1017 item_name= orig_name;
1019 bool eq(
const Item *item,
bool binary_cmp)
const;
1037 void fix_length_and_dec();
1040 DBUG_ASSERT(fixed == 1);
1045 DBUG_ASSERT(fixed == 1);
1046 return cached_time.
get_time(ltime);
1050 DBUG_ASSERT(fixed == 1);
1051 return cached_time.
val_str(&str_value);
1062 const char *func_name()
const {
return "curtime"; }
1072 const char *func_name()
const {
return "utc_time"; }
1085 void fix_length_and_dec();
1088 DBUG_ASSERT(fixed == 1);
1091 bool get_date(
MYSQL_TIME *res, uint fuzzy_date)
1093 DBUG_ASSERT(fixed == 1);
1098 DBUG_ASSERT(fixed == 1);
1099 return cached_time.
val_str(&str_value);
1110 const char *func_name()
const {
return "curdate"; }
1120 const char *func_name()
const {
return "utc_date"; }
1137 void fix_length_and_dec();
1141 DBUG_ASSERT(fixed == 1);
1144 bool get_date(
MYSQL_TIME *res, uint fuzzy_date)
1146 DBUG_ASSERT(fixed == 1);
1151 DBUG_ASSERT(fixed == 1);
1152 return cached_time.
val_str(&str_value);
1171 const char *func_name()
const {
return "now"; }
1172 virtual enum Functype functype()
const {
return NOW_FUNC; }
1182 const char *func_name()
const {
return "utc_timestamp"; }
1195 bool const_item()
const {
return 0; }
1196 const char *func_name()
const {
return "sysdate"; }
1197 void fix_length_and_dec();
1212 const char *func_name()
const {
return "from_days"; }
1213 bool get_date(
MYSQL_TIME *res, uint fuzzy_date);
1214 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
1215 bool check_valid_arguments_processor(uchar *int_arg)
1217 return has_date_args() || has_time_args();
1225 const bool is_time_format;
1231 const char *func_name()
const
1232 {
return is_time_format ?
"time_format" :
"date_format"; }
1233 void fix_length_and_dec();
1234 uint format_length(
const String *format);
1235 bool eq(
const Item *item,
bool binary_cmp)
const;
1244 const char *func_name()
const {
return "from_unixtime"; }
1245 void fix_length_and_dec();
1246 bool get_date(
MYSQL_TIME *res, uint fuzzy_date);
1272 bool from_tz_cached, to_tz_cached;
1277 const char *func_name()
const {
return "convert_tz"; }
1278 void fix_length_and_dec();
1279 bool get_date(
MYSQL_TIME *res, uint fuzzy_date);
1288 void fix_length_and_dec()
1291 fix_length_and_dec_and_charset_datetime(MAX_TIME_WIDTH,
1292 MY_MIN(args[0]->decimals,
1293 DATETIME_MAX_DECIMALS));
1295 const char *func_name()
const {
return "sec_to_time"; }
1303 bool get_date_internal(
MYSQL_TIME *res, uint fuzzy_date);
1309 const interval_type int_type;
1310 const bool date_sub_interval;
1313 int_type(type_arg), date_sub_interval(neg_arg) {}
1314 const char *func_name()
const {
return "date_add_interval"; }
1315 void fix_length_and_dec();
1316 bool eq(
const Item *item,
bool binary_cmp)
const;
1317 void print(
String *str, enum_query_type query_type);
1325 const interval_type int_type;
1329 enum Functype functype()
const {
return EXTRACT_FUNC; }
1330 const char *func_name()
const {
return "extract"; }
1331 void fix_length_and_dec();
1332 bool eq(
const Item *item,
bool binary_cmp)
const;
1333 virtual void print(
String *str, enum_query_type query_type);
1334 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
1335 bool check_valid_arguments_processor(uchar *int_arg)
1339 case INTERVAL_YEAR_MONTH:
1340 case INTERVAL_QUARTER:
1341 case INTERVAL_MONTH:
1344 return !has_date_args();
1345 case INTERVAL_DAY_HOUR:
1346 case INTERVAL_DAY_MINUTE:
1347 case INTERVAL_DAY_SECOND:
1348 case INTERVAL_DAY_MICROSECOND:
1349 return !has_datetime_args();
1351 case INTERVAL_HOUR_MINUTE:
1352 case INTERVAL_HOUR_SECOND:
1353 case INTERVAL_MINUTE:
1354 case INTERVAL_MINUTE_SECOND:
1355 case INTERVAL_SECOND:
1356 case INTERVAL_MICROSECOND:
1357 case INTERVAL_HOUR_MICROSECOND:
1358 case INTERVAL_MINUTE_MICROSECOND:
1359 case INTERVAL_SECOND_MICROSECOND:
1360 return !has_time_args();
1378 void print(
String *str, enum_query_type query_type);
1379 const char *func_name()
const {
return "cast_as_date"; }
1380 bool get_date(
MYSQL_TIME *ltime, uint fuzzy_date);
1381 const char *cast_type()
const {
return "date"; }
1387 bool detect_precision_from_arg;
1391 detect_precision_from_arg=
true;
1395 detect_precision_from_arg=
false;
1398 void print(
String *str, enum_query_type query_type);
1399 const char *func_name()
const {
return "cast_as_time"; }
1401 const char *cast_type()
const {
return "time"; }
1402 void fix_length_and_dec()
1405 fix_length_and_dec_and_charset_datetime(MAX_TIME_WIDTH,
1406 detect_precision_from_arg ?
1415 bool detect_precision_from_arg;
1419 detect_precision_from_arg=
true;
1423 detect_precision_from_arg=
false;
1426 void print(
String *str, enum_query_type query_type);
1427 const char *func_name()
const {
return "cast_as_datetime"; }
1428 const char *cast_type()
const {
return "datetime"; }
1429 void fix_length_and_dec()
1432 fix_length_and_dec_and_charset_datetime(MAX_DATETIME_WIDTH,
1433 detect_precision_from_arg ?
1437 bool get_date(
MYSQL_TIME *res, uint fuzzy_date);
1445 const char *func_name()
const {
return "makedate"; }
1454 bool val_datetime(
MYSQL_TIME *time, uint fuzzy_date);
1459 sign= neg_arg ? -1 : 1;
1461 void fix_length_and_dec();
1462 void print(
String *str, enum_query_type query_type);
1463 const char *func_name()
const {
return "add_time"; }
1471 const char *func_name()
const {
return "timediff"; }
1472 void fix_length_and_dec()
1475 fix_length_and_dec_and_charset_datetime(MAX_TIME_WIDTH, dec);
1488 void fix_length_and_dec()
1490 fix_length_and_dec_and_charset_datetime(MAX_TIME_WIDTH,
1491 MY_MIN(args[2]->decimals,
1492 DATETIME_MAX_DECIMALS));
1494 const char *func_name()
const {
return "maketime"; }
1503 const char *func_name()
const {
return "microsecond"; }
1504 void fix_length_and_dec()
1508 bool check_partition_func_processor(uchar *int_arg) {
return FALSE;}
1509 bool check_valid_arguments_processor(uchar *int_arg)
1511 return !has_time_args();
1518 const interval_type int_type;
1522 const char *func_name()
const {
return "timestampdiff"; }
1524 void fix_length_and_dec()
1528 virtual void print(
String *str, enum_query_type query_type);
1532 enum date_time_format
1534 USA_FORMAT, JIS_FORMAT, ISO_FORMAT, EUR_FORMAT, INTERNAL_FORMAT
1540 const timestamp_type type;
1545 const char *func_name()
const {
return "get_format"; }
1546 void fix_length_and_dec()
1550 fix_length_and_charset(17, default_charset());
1552 virtual void print(
String *str, enum_query_type query_type);
1558 timestamp_type cached_timestamp_type;
1560 void fix_from_format(
const char *format, uint length);
1567 const char *func_name()
const {
return "str_to_date"; }
1568 void fix_length_and_dec();
1576 const char *func_name()
const {
return "last_day"; }
1577 bool get_date(
MYSQL_TIME *res, uint fuzzy_date);