diff options
author | Sergei Golubchik <sergii@pisem.net> | 2011-05-22 11:58:48 +0200 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2011-05-22 11:58:48 +0200 |
commit | 306ed65302e14f303fdc33cfa9d19016fb319440 (patch) | |
tree | 1419433c9d99e58fffee2527c42a8194c338a65e /sql/item_timefunc.h | |
parent | dda9577d553c9969415bc5f3d45f287e3dd6de39 (diff) | |
download | mariadb-git-306ed65302e14f303fdc33cfa9d19016fb319440.tar.gz |
unix_timestamp() and from_unixtime() supports microseconds.
unix_timestamp() and time_to_sec() are hybrid items,
returning integer or double depending on the argument.
Diffstat (limited to 'sql/item_timefunc.h')
-rw-r--r-- | sql/item_timefunc.h | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 14275680d15..d50b0c20716 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -297,15 +297,37 @@ class Item_func_dayname :public Item_func_weekday }; -class Item_func_unix_timestamp :public Item_int_func +class Item_func_seconds_hybrid: public Item_func_numhybrid { - String value; public: - Item_func_unix_timestamp() :Item_int_func() {} - Item_func_unix_timestamp(Item *a) :Item_int_func(a) {} - longlong val_int(); + Item_func_seconds_hybrid() :Item_func_numhybrid() {} + Item_func_seconds_hybrid(Item *a) :Item_func_numhybrid(a) {} + void fix_num_length_and_dec() + { + if (arg_count) + decimals= args[0]->decimals; + if (decimals != NOT_FIXED_DEC) + set_if_smaller(decimals, TIME_SECOND_PART_DIGITS); + max_length=17 + (decimals ? decimals + 1 : 0); + } + void find_num_type() { hybrid_type= decimals ? REAL_RESULT : INT_RESULT; } + my_decimal *decimal_op(my_decimal* buf) { DBUG_ASSERT(0); return 0; } + String *str_op(String *str) { DBUG_ASSERT(0); return 0; } +}; + +class Item_func_unix_timestamp :public Item_func_seconds_hybrid +{ + bool get_timestamp_value(my_time_t *seconds, ulong *second_part); +public: + Item_func_unix_timestamp() :Item_func_seconds_hybrid() {} + Item_func_unix_timestamp(Item *a) :Item_func_seconds_hybrid(a) {} const char *func_name() const { return "unix_timestamp"; } bool check_partition_func_processor(uchar *int_arg) {return FALSE;} + void fix_num_length_and_dec() + { + maybe_null= false; + Item_func_seconds_hybrid::fix_num_length_and_dec(); + } /* UNIX_TIMESTAMP() depends on the current timezone (and thus may not be used as a partitioning function) @@ -315,29 +337,24 @@ public: { return !has_timestamp_args(); } - void fix_length_and_dec() - { - decimals=0; - max_length=10*MY_CHARSET_BIN_MB_MAXLEN; - } + longlong int_op(); + double real_op(); }; -class Item_func_time_to_sec :public Item_real_func +class Item_func_time_to_sec :public Item_func_seconds_hybrid { public: - Item_func_time_to_sec(Item *item) :Item_real_func(item) {} + Item_func_time_to_sec(Item *item) :Item_func_seconds_hybrid(item) {} const char *func_name() const { return "time_to_sec"; } - double val_real(); - void fix_length_and_dec() + void fix_num_length_and_dec() { - maybe_null= TRUE; - decimals= args[0]->decimals; - if (decimals != NOT_FIXED_DEC) - set_if_smaller(decimals, TIME_SECOND_PART_DIGITS); - max_length=17; + maybe_null= true; + Item_func_seconds_hybrid::fix_num_length_and_dec(); } bool check_partition_func_processor(uchar *int_arg) {return FALSE;} + longlong int_op(); + double real_op(); }; |