Commit 7c0504ad authored by unknown's avatar unknown
Browse files

Manual merge of fix for bug #6439 "from_unixtime() function returns

wrong datetime values for too big argument" from 4.0 tree to 4.1 tree.


mysql-test/r/func_time.result:
  Manual merge
mysql-test/t/func_time.test:
  Manual merge
sql/item_timefunc.cc:
  Manual merge
parents 77c163c3 801a2fa3
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -474,6 +474,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)
NULL
select from_unixtime(2145916800);
from_unixtime(2145916800)
NULL
CREATE TABLE t1 (datetime datetime, timestamp timestamp, date date, time time);
INSERT INTO t1 values ("2001-01-02 03:04:05", "2002-01-02 03:04:05", "2003-01-02", "06:07:08");
SELECT * from t1;
+7 −0
Original line number Diff line number Diff line
@@ -229,6 +229,13 @@ select @a:=FROM_UNIXTIME(1);
select unix_timestamp(@a);
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.
#
select from_unixtime(0);
select from_unixtime(2145916800);

#
# Test types from + INTERVAL
#
+20 −24
Original line number Diff line number Diff line
@@ -1601,50 +1601,46 @@ void Item_func_from_unixtime::fix_length_and_dec()
String *Item_func_from_unixtime::val_str(String *str)
{
  TIME time_tmp;
  my_time_t tmp;

  DBUG_ASSERT(fixed == 1);
  tmp= (time_t) args[0]->val_int();
  if ((null_value=args[0]->null_value))
    goto null_date;

  thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, tmp);
  if (get_date(&time_tmp, 0))
    return 0;

  if (str->alloc(20*MY_CHARSET_BIN_MB_MAXLEN))
    goto null_date;
  make_datetime((DATE_TIME_FORMAT *) 0, &time_tmp, str);
  return str;

null_date:
  {
    null_value= 1;
    return 0;
  }

  make_datetime((DATE_TIME_FORMAT *) 0, &time_tmp, str);
  return str;
}


longlong Item_func_from_unixtime::val_int()
{
  TIME time_tmp;
  my_time_t tmp;

  DBUG_ASSERT(fixed == 1);

  tmp= (time_t) (ulong) args[0]->val_int();
  if ((null_value=args[0]->null_value))
  if (get_date(&time_tmp, 0))
    return 0;

  current_thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp, tmp);
  
  return (longlong) TIME_to_ulonglong_datetime(&time_tmp);
}

bool Item_func_from_unixtime::get_date(TIME *ltime,
				       uint fuzzy_date __attribute__((unused)))
{
  my_time_t tmp=(my_time_t) args[0]->val_int();
  if ((null_value=args[0]->null_value))
  longlong tmp= args[0]->val_int();

  if ((null_value= (args[0]->null_value ||
                    tmp < TIMESTAMP_MIN_VALUE ||
                    tmp > TIMESTAMP_MAX_VALUE)))
    return 1;

  current_thd->variables.time_zone->gmt_sec_to_TIME(ltime, tmp);
  thd->variables.time_zone->gmt_sec_to_TIME(ltime, (my_time_t)tmp);

  return 0;
}