mirror of
https://github.com/MariaDB/server.git
synced 2026-05-02 13:15:32 +02:00
Implemented UTC_TIME, UTC_DATE and UTC_TIMESTAMP functions (WL#345)
configure.in: ./configure now tests if gmtime_r is present include/config-os2.h: Supposing that OS/2 have gmtime_r include/my_pthread.h: Use our imeplementation of gmtime_r if system lacks one mysql-test/r/func_time.result: Added UTC_* functions to test mysql-test/t/func_time.test: Added UTC_* functions to test mysys/my_pthread.c: Our implementation of gmtime_r mysys/my_thr_init.c: Now we also need LOCK_locktime_r if gmtime_r is absent sql/item_timefunc.cc: Generalized classes for CURDATE, CURTIME and NOW, abstracted them from timezone. Added new children classes for implementing these and UTC_* functions. sql/item_timefunc.h: Generalized classes for CURDATE, CURTIME and NOW, abstracted them from timezone. Added new children classes for implementing these and UTC_* functions. sql/lex.h: Added tokens for UTC_TIME, UTC_DATE and UTC_TIMESTAMP sql/sql_yacc.yy: Added UTC_* functions to grammar. Current functions are using classes now.
This commit is contained in:
parent
e8da290b09
commit
2ad06dc68e
11 changed files with 260 additions and 58 deletions
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue