tags 289762 patch thanks whoops. here's the patch :)
sean
# This is a BitKeeper generated diff -Nru style patch. # # ChangeSet # 2004/12/30 21:18:10+03:00 [EMAIL PROTECTED] # Fix for bug #7515 "from_unixtime(0) now returns NULL instead of # the Epoch". (With after review fixes). # # mysql-test/r/func_time.result # 2004/12/30 21:18:06+03:00 [EMAIL PROTECTED] +5 -2 # Added test for bug #7515 "from_unixtime(0) now returns NULL instead of # the Epoch". # # mysql-test/t/func_time.test # 2004/12/30 21:18:07+03:00 [EMAIL PROTECTED] +6 -2 # Added test for bug #7515 "from_unixtime(0) now returns NULL instead of # the Epoch". # # sql/item_timefunc.cc # 2004/12/30 21:18:07+03:00 [EMAIL PROTECTED] +6 -4 # Item_func_from_unixtime: # from_unixtime(0) should return Epoch instead of NULL. # # sql/item_timefunc.h # 2004/12/30 21:18:07+03:00 [EMAIL PROTECTED] +1 -2 # 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. # diff -Nru a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result --- a/mysql-test/r/func_time.result 2005-01-13 14:05:48 -08:00 +++ b/mysql-test/r/func_time.result 2005-01-13 14:05:48 -08:00 @@ -470,9 +470,12 @@ 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 diff -Nru a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test --- a/mysql-test/t/func_time.test 2005-01-13 14:05:48 -08:00 +++ b/mysql-test/t/func_time.test 2005-01-13 14:05:48 -08:00 @@ -228,7 +228,11 @@ # # 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); diff -Nru a/sql/item_timefunc.cc b/sql/item_timefunc.cc --- a/sql/item_timefunc.cc 2005-01-13 14:05:48 -08:00 +++ b/sql/item_timefunc.cc 2005-01-13 14:05:48 -08:00 @@ -946,10 +946,12 @@ { 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); diff -Nru a/sql/item_timefunc.h b/sql/item_timefunc.h --- a/sql/item_timefunc.h 2005-01-13 14:05:48 -08:00 +++ b/sql/item_timefunc.h 2005-01-13 14:05:48 -08:00 @@ -359,8 +359,7 @@ 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); };
signature.asc
Description: Digital signature