diff options
author | unknown <dlenev@dlenev.mshome> | 2003-08-11 23:43:01 +0400 |
---|---|---|
committer | unknown <dlenev@dlenev.mshome> | 2003-08-11 23:43:01 +0400 |
commit | 2ad06dc68e3ca572d2abbe89b470f2a510466ad3 (patch) | |
tree | bec2ab17e0424dac363d21f954738ff68f4fede9 /sql/item_timefunc.cc | |
parent | e8da290b099fe2cfcdcb16d5e7805c616a8b526e (diff) | |
download | mariadb-git-2ad06dc68e3ca572d2abbe89b470f2a510466ad3.tar.gz |
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.
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r-- | sql/item_timefunc.cc | 148 |
1 files changed, 105 insertions, 43 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 62d8afd7ec0..2948438d76f 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -571,21 +571,21 @@ longlong Item_func_from_days::val_int() void Item_func_curdate::fix_length_and_dec() { - struct tm tm_tmp,*start; - time_t query_start=current_thd->query_start(); + struct tm start; collation.set(default_charset()); decimals=0; max_length=10*default_charset()->mbmaxlen; - localtime_r(&query_start,&tm_tmp); - start=&tm_tmp; - value=(longlong) ((ulong) ((uint) start->tm_year+1900)*10000L+ - ((uint) start->tm_mon+1)*100+ - (uint) start->tm_mday); + + store_now_in_tm(current_thd->query_start(),&start); + + value=(longlong) ((ulong) ((uint) start.tm_year+1900)*10000L+ + ((uint) start.tm_mon+1)*100+ + (uint) start.tm_mday); /* For getdate */ - ltime.year= start->tm_year+1900; - ltime.month= start->tm_mon+1; - ltime.day= start->tm_mday; + ltime.year= start.tm_year+1900; + ltime.month= start.tm_mon+1; + ltime.day= start.tm_mday; ltime.hour= 0; ltime.minute= 0; ltime.second= 0; @@ -594,6 +594,7 @@ void Item_func_curdate::fix_length_and_dec() ltime.time_type=TIMESTAMP_DATE; } + bool Item_func_curdate::get_date(TIME *res, bool fuzzy_date __attribute__((unused))) { @@ -601,6 +602,27 @@ bool Item_func_curdate::get_date(TIME *res, return 0; } + +/* + Converts time in time_t to struct tm represenatation for local timezone. + Defines timezone (local) used for whole CURDATE function +*/ +void Item_func_curdate_local::store_now_in_tm(time_t now, struct tm *now_tm) +{ + localtime_r(&now,now_tm); +} + + +/* + Converts time in time_t to struct tm represenatation for UTC + Defines timezone (UTC) used for whole UTC_DATE function +*/ +void Item_func_curdate_utc::store_now_in_tm(time_t now, struct tm *now_tm) +{ + gmtime_r(&now,now_tm); +} + + String *Item_func_curtime::val_str(String *str) { str_value.set(buff,buff_length,default_charset()); @@ -609,23 +631,43 @@ String *Item_func_curtime::val_str(String *str) void Item_func_curtime::fix_length_and_dec() { - struct tm tm_tmp,*start; - time_t query_start=current_thd->query_start(); - CHARSET_INFO *cs=default_charset(); + struct tm start; + CHARSET_INFO *cs= default_charset(); decimals=0; max_length=8*cs->mbmaxlen; - localtime_r(&query_start,&tm_tmp); - start=&tm_tmp; collation.set(cs); - value=(longlong) ((ulong) ((uint) start->tm_hour)*10000L+ - (ulong) (((uint) start->tm_min)*100L+ - (uint) start->tm_sec)); + + store_now_in_tm(current_thd->query_start(),&start); + + value=(longlong) ((ulong) ((uint) start.tm_hour)*10000L+ + (ulong) (((uint) start.tm_min)*100L+ + (uint) start.tm_sec)); buff_length=cs->cset->snprintf(cs,buff,sizeof(buff),"%02d:%02d:%02d", - (int) start->tm_hour, - (int) start->tm_min, - (int) start->tm_sec); + (int) start.tm_hour, + (int) start.tm_min, + (int) start.tm_sec); +} + + +/* + Converts time in time_t to struct tm represenatation for local timezone. + Defines timezone (local) used for whole CURTIME function +*/ +void Item_func_curtime_local::store_now_in_tm(time_t now, struct tm *now_tm) +{ + localtime_r(&now,now_tm); +} + + +/* + Converts time in time_t to struct tm represenatation for UTC. + Defines timezone (UTC) used for whole UTC_TIME function +*/ +void Item_func_curtime_utc::store_now_in_tm(time_t now, struct tm *now_tm) +{ + gmtime_r(&now,now_tm); } @@ -638,37 +680,37 @@ String *Item_func_now::val_str(String *str) void Item_func_now::fix_length_and_dec() { - struct tm tm_tmp,*start; - time_t query_start=current_thd->query_start(); + struct tm start; CHARSET_INFO *cs= &my_charset_bin; decimals=0; max_length=19*cs->mbmaxlen; collation.set(cs); - localtime_r(&query_start,&tm_tmp); - start=&tm_tmp; - value=((longlong) ((ulong) ((uint) start->tm_year+1900)*10000L+ - (((uint) start->tm_mon+1)*100+ - (uint) start->tm_mday))*(longlong) 1000000L+ - (longlong) ((ulong) ((uint) start->tm_hour)*10000L+ - (ulong) (((uint) start->tm_min)*100L+ - (uint) start->tm_sec))); + + store_now_in_tm(current_thd->query_start(),&start); + + value=((longlong) ((ulong) ((uint) start.tm_year+1900)*10000L+ + (((uint) start.tm_mon+1)*100+ + (uint) start.tm_mday))*(longlong) 1000000L+ + (longlong) ((ulong) ((uint) start.tm_hour)*10000L+ + (ulong) (((uint) start.tm_min)*100L+ + (uint) start.tm_sec))); buff_length= (uint) cs->cset->snprintf(cs,buff, sizeof(buff), "%04d-%02d-%02d %02d:%02d:%02d", - ((int) (start->tm_year+1900)) % 10000, - (int) start->tm_mon+1, - (int) start->tm_mday, - (int) start->tm_hour, - (int) start->tm_min, - (int) start->tm_sec); + ((int) (start.tm_year+1900)) % 10000, + (int) start.tm_mon+1, + (int) start.tm_mday, + (int) start.tm_hour, + (int) start.tm_min, + (int) start.tm_sec); /* For getdate */ - ltime.year= start->tm_year+1900; - ltime.month= start->tm_mon+1; - ltime.day= start->tm_mday; - ltime.hour= start->tm_hour; - ltime.minute= start->tm_min; - ltime.second= start->tm_sec; + ltime.year= start.tm_year+1900; + ltime.month= start.tm_mon+1; + ltime.day= start.tm_mday; + ltime.hour= start.tm_hour; + ltime.minute= start.tm_min; + ltime.second= start.tm_sec; ltime.second_part=0; ltime.neg=0; ltime.time_type=TIMESTAMP_FULL; @@ -690,6 +732,26 @@ int Item_func_now::save_in_field(Field *to, bool no_conversions) } +/* + Converts time in time_t to struct tm represenatation for local timezone. + Defines timezone (local) used for whole CURRENT_TIMESTAMP function +*/ +void Item_func_now_local::store_now_in_tm(time_t now, struct tm *now_tm) +{ + localtime_r(&now,now_tm); +} + + +/* + Converts time in time_t to struct tm represenatation for UTC. + Defines timezone (UTC) used for whole UTC_TIMESTAMP function +*/ +void Item_func_now_utc::store_now_in_tm(time_t now, struct tm *now_tm) +{ + gmtime_r(&now,now_tm); +} + + String *Item_func_sec_to_time::val_str(String *str) { char buff[23*2]; |