diff options
author | dlenev@dlenev.mshome <> | 2003-08-11 23:43:01 +0400 |
---|---|---|
committer | dlenev@dlenev.mshome <> | 2003-08-11 23:43:01 +0400 |
commit | 921ac8af8b388a90b6c06db2de78dba1cd5a3950 (patch) | |
tree | bec2ab17e0424dac363d21f954738ff68f4fede9 /sql/item_timefunc.h | |
parent | a60acfcfe09945c9dd7d326ab99d1df5715cba46 (diff) | |
download | mariadb-git-921ac8af8b388a90b6c06db2de78dba1cd5a3950.tar.gz |
Implemented UTC_TIME, UTC_DATE and UTC_TIMESTAMP functions (WL#345)
Diffstat (limited to 'sql/item_timefunc.h')
-rw-r--r-- | sql/item_timefunc.h | 80 |
1 files changed, 75 insertions, 5 deletions
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index a6fb9b11de4..2196f83884a 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -350,6 +350,8 @@ public: }; +/* Abstract CURTIME function. Children should define what timezone is used */ + class Item_func_curtime :public Item_func { longlong value; @@ -363,29 +365,77 @@ public: double val() { return (double) value; } longlong val_int() { return value; } String *val_str(String *str); - const char *func_name() const { return "curtime"; } void fix_length_and_dec(); Field *tmp_table_field() { return result_field; } Field *tmp_table_field(TABLE *t_arg) { return (new Field_time(maybe_null, name, t_arg, default_charset())); - } + } + /* + Abstract method that defines which time zone is used for conversion. + Converts time from time_t representation to broken down representation + in struct tm using gmtime_r or localtime_r functions. + */ + virtual void store_now_in_tm(time_t now, struct tm *now_tm)=0; }; +class Item_func_curtime_local :public Item_func_curtime +{ +public: + Item_func_curtime_local() :Item_func_curtime() {} + Item_func_curtime_local(Item *a) :Item_func_curtime(a) {} + const char *func_name() const { return "curtime"; } + void store_now_in_tm(time_t now, struct tm *now_tm); +}; + + +class Item_func_curtime_utc :public Item_func_curtime +{ +public: + Item_func_curtime_utc() :Item_func_curtime() {} + Item_func_curtime_utc(Item *a) :Item_func_curtime(a) {} + const char *func_name() const { return "utc_time"; } + void store_now_in_tm(time_t now, struct tm *now_tm); +}; + + +/* Abstract CURDATE function. See also Item_func_curtime. */ + class Item_func_curdate :public Item_date { longlong value; TIME ltime; public: Item_func_curdate() :Item_date() {} + void set_result_from_tm(struct tm *now); longlong val_int() { return (value) ; } - const char *func_name() const { return "curdate"; } - void fix_length_and_dec(); /* Retrieves curtime */ + void fix_length_and_dec(); bool get_date(TIME *res,bool fuzzy_date); + virtual void store_now_in_tm(time_t now, struct tm *now_tm)=0; +}; + + +class Item_func_curdate_local :public Item_func_curdate +{ +public: + Item_func_curdate_local() :Item_func_curdate() {} + const char *func_name() const { return "curdate"; } + void store_now_in_tm(time_t now, struct tm *now_tm); }; +class Item_func_curdate_utc :public Item_func_curdate +{ +public: + Item_func_curdate_utc() :Item_func_curdate() {} + const char *func_name() const { return "utc_date"; } + void store_now_in_tm(time_t now, struct tm *now_tm); +}; + + +/* Abstract CURRENT_TIMESTAMP function. See also Item_func_curtime */ + class Item_func_now :public Item_date_func { longlong value; @@ -400,9 +450,29 @@ public: longlong val_int() { return value; } int save_in_field(Field *to, bool no_conversions); String *val_str(String *str); - const char *func_name() const { return "now"; } void fix_length_and_dec(); bool get_date(TIME *res,bool fuzzy_date); + virtual void store_now_in_tm(time_t now, struct tm *now_tm)=0; +}; + + +class Item_func_now_local :public Item_func_now +{ +public: + Item_func_now_local() :Item_func_now() {} + Item_func_now_local(Item *a) :Item_func_now(a) {} + const char *func_name() const { return "now"; } + void store_now_in_tm(time_t now, struct tm *now_tm); +}; + + +class Item_func_now_utc :public Item_func_now +{ +public: + Item_func_now_utc() :Item_func_now() {} + Item_func_now_utc(Item *a) :Item_func_now(a) {} + const char *func_name() const { return "utc_timestamp"; } + void store_now_in_tm(time_t now, struct tm *now_tm); }; |