summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <dlenev@mysql.com>2004-12-30 21:37:32 +0300
committerunknown <dlenev@mysql.com>2004-12-30 21:37:32 +0300
commite107535fa2c41862fa0e1faa68d0e693a45f1b64 (patch)
tree8e50594a30d4d0d2a0239ab976ce23fe93ec089c
parent12b08e569431a9d98baf0e2f03d1c024259b3d07 (diff)
parent15017480a7d7aba65df4fcab00a922aa8fc0cf01 (diff)
downloadmariadb-git-e107535fa2c41862fa0e1faa68d0e693a45f1b64.tar.gz
Manual merge of fix for bugs of #7297 and #7515 into 4.1 tree.
mysql-test/r/func_time.result: Manual merge. mysql-test/r/type_datetime.result: Manual merge. mysql-test/t/func_time.test: Manual merge. mysql-test/t/type_datetime.test: Manual merge. sql/item_timefunc.cc: Manual merge. sql/item_timefunc.h: Manual merge. sql/time.cc: Manual merge.
-rw-r--r--mysql-test/r/func_time.result7
-rw-r--r--mysql-test/r/type_datetime.result10
-rw-r--r--mysql-test/t/func_time.test8
-rw-r--r--mysql-test/t/type_datetime.test12
-rw-r--r--sql/item_timefunc.cc11
5 files changed, 39 insertions, 9 deletions
diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result
index c78b16aed8a..4dd00ab74a1 100644
--- a/mysql-test/r/func_time.result
+++ b/mysql-test/r/func_time.result
@@ -474,12 +474,15 @@ 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
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;
diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result
index 127a54e087b..7b101d31fc5 100644
--- a/mysql-test/r/type_datetime.result
+++ b/mysql-test/r/type_datetime.result
@@ -143,3 +143,13 @@ t
0000-00-00 00:00:00
2003-01-01 00:00:00
drop table t1;
+create table t1 (dt datetime);
+insert into t1 values ("12-00-00"), ("00-00-00 01:00:00");
+insert into t1 values ("00-00-00"), ("00-00-00 00:00:00");
+select * from t1;
+dt
+2012-00-00 00:00:00
+2000-00-00 01:00:00
+0000-00-00 00:00:00
+0000-00-00 00:00:00
+drop table t1;
diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test
index b9e592fc5d9..0f495ef891d 100644
--- a/mysql-test/t/func_time.test
+++ b/mysql-test/t/func_time.test
@@ -231,10 +231,14 @@ 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);
#
# Test types from + INTERVAL
diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test
index 04e4a73554a..a7eb78cb292 100644
--- a/mysql-test/t/type_datetime.test
+++ b/mysql-test/t/type_datetime.test
@@ -89,3 +89,15 @@ delete from t1;
insert into t1 values ("0000-00-00 00:00:00 some trailer"),("2003-01-01 00:00:00 some trailer");
select * from t1;
drop table t1;
+
+#
+# Test for bug #7297 "Two digit year should be interpreted correctly even
+# with zero month and day"
+#
+create table t1 (dt datetime);
+# These dates should be treated as dates in 21st century
+insert into t1 values ("12-00-00"), ("00-00-00 01:00:00");
+# Zero dates are still special :/
+insert into t1 values ("00-00-00"), ("00-00-00 00:00:00");
+select * from t1;
+drop table t1;
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 054a9966e73..6198043b576 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -1636,11 +1636,12 @@ longlong Item_func_from_unixtime::val_int()
bool Item_func_from_unixtime::get_date(TIME *ltime,
uint fuzzy_date __attribute__((unused)))
{
- longlong tmp= args[0]->val_int();
-
- if ((null_value= (args[0]->null_value ||
- tmp < TIMESTAMP_MIN_VALUE ||
- tmp > TIMESTAMP_MAX_VALUE)))
+ ulonglong tmp= (ulonglong)(args[0]->val_int());
+ /*
+ "tmp > TIMESTAMP_MAX_VALUE" check also covers case of negative
+ from_unixtime() argument since tmp is unsigned.
+ */
+ if ((null_value= (args[0]->null_value || tmp > TIMESTAMP_MAX_VALUE)))
return 1;
thd->variables.time_zone->gmt_sec_to_TIME(ltime, (my_time_t)tmp);