Commit 1ffd688a authored by unknown's avatar unknown

Fix for bug #7515 "from_unixtime(0) now returns NULL instead of

the Epoch". (With after review fixes).


mysql-test/r/func_time.result:
  Added test for bug #7515 "from_unixtime(0) now returns NULL instead of
  the Epoch".
mysql-test/t/func_time.test:
  Added test for bug #7515 "from_unixtime(0) now returns NULL instead of
  the Epoch".
sql/item_timefunc.cc:
  Item_func_from_unixtime:
   from_unixtime(0) should return Epoch instead of NULL.
sql/item_timefunc.h:
  Item_func_from_unixtime:
   - Removed unused method definition.
   - fix_length_and_dec() should set maybe_null to true since now
     from_unixtime() can return NULL even in case when none of its
     arguments is NULL.
parent 2fb340b5
......@@ -470,9 +470,12 @@ unix_timestamp(@a)
select unix_timestamp('1969-12-01 19:00:01');
unix_timestamp('1969-12-01 19:00:01')
0
select from_unixtime(0);
from_unixtime(0)
select from_unixtime(-1);
from_unixtime(-1)
NULL
select from_unixtime(2145916800);
from_unixtime(2145916800)
NULL
select from_unixtime(0);
from_unixtime(0)
1970-01-01 03:00:00
......@@ -228,7 +228,11 @@ select unix_timestamp('1969-12-01 19:00:01');
#
# Test for bug #6439 "unix_timestamp() function returns wrong datetime
# values for too big argument". It should return error instead.
# values for too big argument" and bug #7515 "from_unixtime(0) now
# returns NULL instead of the epoch". unix_timestamp() should return error
# for too big or negative argument. It should return Epoch value for zero
# argument since it seems that many user's rely on this fact.
#
select from_unixtime(0);
select from_unixtime(-1);
select from_unixtime(2145916800);
select from_unixtime(0);
......@@ -946,10 +946,12 @@ bool Item_func_from_unixtime::get_date(TIME *ltime,
{
struct tm tm_tmp;
time_t tmp;
longlong arg= args[0]->val_int();
if ((null_value= (args[0]->null_value ||
arg < TIMESTAMP_MIN_VALUE ||
arg > TIMESTAMP_MAX_VALUE)))
ulonglong arg= (ulonglong)(args[0]->val_int());
/*
"arg > TIMESTAMP_MAX_VALUE" check also covers case of negative
from_unixtime() argument since arg is unsigned.
*/
if ((null_value= (args[0]->null_value || arg > TIMESTAMP_MAX_VALUE)))
return 1;
tmp= arg;
localtime_r(&tmp,&tm_tmp);
......
......@@ -359,8 +359,7 @@ class Item_func_from_unixtime :public Item_date_func
longlong val_int();
String *val_str(String *str);
const char *func_name() const { return "from_unixtime"; }
void fix_length_and_dec() { decimals=0; max_length=19; }
// enum Item_result result_type () const { return STRING_RESULT; }
void fix_length_and_dec() { decimals=0; max_length=19; maybe_null= 1; }
bool get_date(TIME *res,bool fuzzy_date);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment