diff options
author | unknown <jimw@mysql.com> | 2005-08-24 15:50:58 -0700 |
---|---|---|
committer | unknown <jimw@mysql.com> | 2005-08-24 15:50:58 -0700 |
commit | da13a76a289a7f75089c738cb08745e7dd82f619 (patch) | |
tree | d1cebeb5bc16f53aaf69f81ac3286a2365c098fc /sql/item_timefunc.cc | |
parent | a7ce02bcf7540b044019e98b7c0a349f48ff6269 (diff) | |
download | mariadb-git-da13a76a289a7f75089c738cb08745e7dd82f619.tar.gz |
Make SYSDATE() behave as in Oracle: always the current datetime, not the
datetime of when the current statement began. This also makes SYSDATE()
not safe in replication. (Bug #12562)
mysql-test/r/func_time.result:
Add new results
mysql-test/t/func_time.test:
Add tests for new SYSDATE() behavior
sql/item_timefunc.cc:
Add Item_func_sysdate_local implementation
sql/item_timefunc.h:
Add Item_func_sysdate_local, so SYSDATE() can behave differently
than NOW().
sql/lex.h:
SYSDATE() is no longer an alias for NOW().
sql/sql_yacc.yy:
Handle SYSDATE()
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r-- | sql/item_timefunc.cc | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index dfbfca3b078..0d9e23ff0a1 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1476,9 +1476,9 @@ void Item_func_now_utc::store_now_in_TIME(TIME *now_time) bool Item_func_now::get_date(TIME *res, - uint fuzzy_date __attribute__((unused))) + uint fuzzy_date __attribute__((unused))) { - *res=ltime; + *res= ltime; return 0; } @@ -1491,6 +1491,70 @@ int Item_func_now::save_in_field(Field *to, bool no_conversions) } +/* + Converts current time in my_time_t to TIME represenatation for local + time zone. Defines time zone (local) used for whole SYSDATE function. +*/ +void Item_func_sysdate_local::store_now_in_TIME(TIME *now_time) +{ + THD *thd= current_thd; + thd->variables.time_zone->gmt_sec_to_TIME(now_time, time(NULL)); + thd->time_zone_used= 1; +} + + +String *Item_func_sysdate_local::val_str(String *str) +{ + DBUG_ASSERT(fixed == 1); + store_now_in_TIME(<ime); + buff_length= (uint) my_datetime_to_str(<ime, buff); + str_value.set(buff, buff_length, &my_charset_bin); + return &str_value; +} + + +longlong Item_func_sysdate_local::val_int() +{ + DBUG_ASSERT(fixed == 1); + store_now_in_TIME(<ime); + return (longlong) TIME_to_ulonglong_datetime(<ime); +} + + +double Item_func_sysdate_local::val_real() +{ + DBUG_ASSERT(fixed == 1); + store_now_in_TIME(<ime); + return (longlong) TIME_to_ulonglong_datetime(<ime); +} + + +void Item_func_sysdate_local::fix_length_and_dec() +{ + decimals= 0; + collation.set(&my_charset_bin); + max_length= MAX_DATETIME_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; +} + + +bool Item_func_sysdate_local::get_date(TIME *res, + uint fuzzy_date __attribute__((unused))) +{ + store_now_in_TIME(<ime); + *res= ltime; + return 0; +} + + +int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions) +{ + store_now_in_TIME(<ime); + to->set_notnull(); + to->store_time(<ime, MYSQL_TIMESTAMP_DATETIME); + return 0; +} + + String *Item_func_sec_to_time::val_str(String *str) { DBUG_ASSERT(fixed == 1); |