summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <tnurnberg@mysql.com/white.intern.koehntopp.de>2007-11-16 17:43:15 +0100
committerunknown <tnurnberg@mysql.com/white.intern.koehntopp.de>2007-11-16 17:43:15 +0100
commit5e9933d7ff7d7fdd0e8b117b0344b127d5f23ffa (patch)
tree22102c7bedd68e6dd1fe0b7f8748cc68dc3c1778
parentf6686659551be614c835ff5f3730e87f41e06d84 (diff)
downloadmariadb-git-5e9933d7ff7d7fdd0e8b117b0344b127d5f23ffa.tar.gz
Bug #32180: DATE_ADD treats datetime numeric argument as DATE instead of DATETIME
This is a regression from 2007-05-18 when code to zero out the returned struct was added to number_to_datetime(); zero for time_type corresponds to MYSQL_TIMESTAMP_DATE. We now explicitly set the type we return (MYSQL_TIMESTAMP_DATETIME). mysql-test/r/func_time.result: show that DATE_ADD() behaves the same for YYYYMMDDhhmmss given as string and as integer. mysql-test/t/func_time.test: show that DATE_ADD() behaves the same for YYYYMMDDhhmmss given as string and as integer. sql-common/my_time.c: explictly set return type in number_to_datetime()
-rw-r--r--mysql-test/r/func_time.result12
-rw-r--r--mysql-test/t/func_time.test10
-rw-r--r--sql-common/my_time.c9
3 files changed, 30 insertions, 1 deletions
diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result
index 74859be4d04..71234385c0d 100644
--- a/mysql-test/r/func_time.result
+++ b/mysql-test/r/func_time.result
@@ -1270,4 +1270,16 @@ select concat(a,ifnull(min(date_format(now(), '%Y-%m-%d')),' ull')) from t1;
ERROR HY000: Illegal mix of collations (ascii_general_ci,IMPLICIT) and (latin1_swedish_ci,COERCIBLE) for operation 'concat'
set lc_time_names=en_US;
drop table t1;
+select DATE_ADD('20071108181000', INTERVAL 1 DAY);
+DATE_ADD('20071108181000', INTERVAL 1 DAY)
+2007-11-09 18:10:00
+select DATE_ADD(20071108181000, INTERVAL 1 DAY);
+DATE_ADD(20071108181000, INTERVAL 1 DAY)
+2007-11-09 18:10:00
+select DATE_ADD('20071108', INTERVAL 1 DAY);
+DATE_ADD('20071108', INTERVAL 1 DAY)
+2007-11-09
+select DATE_ADD(20071108, INTERVAL 1 DAY);
+DATE_ADD(20071108, INTERVAL 1 DAY)
+2007-11-09
End of 5.0 tests
diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test
index c0a449ac3f4..f8249b7cf7c 100644
--- a/mysql-test/t/func_time.test
+++ b/mysql-test/t/func_time.test
@@ -787,4 +787,14 @@ select concat(a,ifnull(min(date_format(now(), '%Y-%m-%d')),' ull')) from t1;
set lc_time_names=en_US;
drop table t1;
+#
+# Bug#32180: DATE_ADD treats datetime numeric argument as DATE
+# instead of DATETIME
+#
+
+select DATE_ADD('20071108181000', INTERVAL 1 DAY);
+select DATE_ADD(20071108181000, INTERVAL 1 DAY);
+select DATE_ADD('20071108', INTERVAL 1 DAY);
+select DATE_ADD(20071108, INTERVAL 1 DAY);
+
--echo End of 5.0 tests
diff --git a/sql-common/my_time.c b/sql-common/my_time.c
index f5d5828e024..a39cc754c88 100644
--- a/sql-common/my_time.c
+++ b/sql-common/my_time.c
@@ -1113,9 +1113,14 @@ longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res,
long part1,part2;
*was_cut= 0;
+ bzero((char*) time_res, sizeof(*time_res));
+ time_res->time_type=MYSQL_TIMESTAMP_DATE;
if (nr == LL(0) || nr >= LL(10000101000000))
+ {
+ time_res->time_type=MYSQL_TIMESTAMP_DATETIME;
goto ok;
+ }
if (nr < 101)
goto err;
if (nr <= (YY_PART_YEAR-1)*10000L+1231L)
@@ -1139,6 +1144,9 @@ longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res,
}
if (nr < 101000000L)
goto err;
+
+ time_res->time_type=MYSQL_TIMESTAMP_DATETIME;
+
if (nr <= (YY_PART_YEAR-1)*LL(10000000000)+LL(1231235959))
{
nr= nr+LL(20000000000000); /* YYMMDDHHMMSS, 2000-2069 */
@@ -1152,7 +1160,6 @@ longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res,
ok:
part1=(long) (nr/LL(1000000));
part2=(long) (nr - (longlong) part1*LL(1000000));
- bzero((char*) time_res, sizeof(*time_res));
time_res->year= (int) (part1/10000L); part1%=10000L;
time_res->month= (int) part1 / 100;
time_res->day= (int) part1 % 100;