#At file:///export/home/tmp/je159969/mysql-dev/bzr-repos/mysql-pe/ based on revid:aelkin@stripped
3987 John H. Embretsen 2010-03-22 [merge]
Merge 5.1-bugteam --> mysql-pe, following fix for bug 52060.
modified:
mysql-test/r/type_year.result
mysql-test/r/udf.result
mysql-test/t/type_year.test
mysql-test/t/udf.test
sql/item_cmpfunc.cc
=== modified file 'mysql-test/r/type_year.result'
--- a/mysql-test/r/type_year.result 2010-02-04 10:55:39 +0000
+++ b/mysql-test/r/type_year.result 2010-03-22 09:11:30 +0000
@@ -309,4 +309,36 @@ yyyy c4
2069 2069
DROP TABLE t2, t4;
#
+# Bug #49910: Behavioural change in SELECT/WHERE on YEAR(4) data type
+#
+CREATE TABLE t1 (y YEAR NOT NULL, s VARCHAR(4));
+INSERT INTO t1 (s) VALUES ('bad');
+Warnings:
+Warning 1364 Field 'y' doesn't have a default value
+INSERT INTO t1 (y, s) VALUES (0, 0), (2000, 2000), (2001, 2001);
+SELECT * FROM t1 ta, t1 tb WHERE ta.y = tb.y;
+y s y s
+0000 bad 0000 bad
+0000 0 0000 bad
+0000 bad 0000 0
+0000 0 0000 0
+2000 2000 2000 2000
+2001 2001 2001 2001
+SELECT * FROM t1 WHERE t1.y = 0;
+y s
+0000 bad
+0000 0
+SELECT * FROM t1 WHERE t1.y = 2000;
+y s
+2000 2000
+SELECT ta.y AS ta_y, ta.s, tb.y AS tb_y, tb.s FROM t1 ta, t1 tb HAVING ta_y = tb_y;
+ta_y s tb_y s
+0000 bad 0000 bad
+0000 0 0000 bad
+0000 bad 0000 0
+0000 0 0000 0
+2000 2000 2000 2000
+2001 2001 2001 2001
+DROP TABLE t1;
+#
End of 5.1 tests
=== modified file 'mysql-test/r/udf.result'
--- a/mysql-test/r/udf.result 2010-02-23 18:47:51 +0000
+++ b/mysql-test/r/udf.result 2010-03-22 09:11:30 +0000
@@ -38,8 +38,6 @@ ERROR HY000: Can't initialize function '
select reverse_lookup("127.0.0.1");
select reverse_lookup(127,0,0,1);
select reverse_lookup("localhost");
-reverse_lookup("localhost")
-NULL
select avgcost();
ERROR HY000: Can't initialize function 'avgcost'; wrong number of arguments: AVGCOST() requires two arguments
select avgcost(100,23.76);
=== modified file 'mysql-test/t/type_year.test'
--- a/mysql-test/t/type_year.test 2010-02-04 10:55:39 +0000
+++ b/mysql-test/t/type_year.test 2010-03-22 09:11:30 +0000
@@ -134,5 +134,21 @@ SELECT * FROM t4 WHERE yyyy > 123;
DROP TABLE t2, t4;
--echo #
+--echo # Bug #49910: Behavioural change in SELECT/WHERE on YEAR(4) data type
+--echo #
+
+CREATE TABLE t1 (y YEAR NOT NULL, s VARCHAR(4));
+INSERT INTO t1 (s) VALUES ('bad');
+INSERT INTO t1 (y, s) VALUES (0, 0), (2000, 2000), (2001, 2001);
+
+SELECT * FROM t1 ta, t1 tb WHERE ta.y = tb.y;
+SELECT * FROM t1 WHERE t1.y = 0;
+SELECT * FROM t1 WHERE t1.y = 2000;
+
+SELECT ta.y AS ta_y, ta.s, tb.y AS tb_y, tb.s FROM t1 ta, t1 tb HAVING ta_y = tb_y;
+
+DROP TABLE t1;
+
+--echo #
--echo End of 5.1 tests
=== modified file 'mysql-test/t/udf.test'
--- a/mysql-test/t/udf.test 2010-02-23 18:47:51 +0000
+++ b/mysql-test/t/udf.test 2010-03-22 09:11:30 +0000
@@ -51,14 +51,17 @@ select lookup("localhost");
--error ER_CANT_INITIALIZE_UDF
select reverse_lookup();
-# These two functions should return "localhost", but it's
+# These two function calls should return "localhost", but it's
# depending on configuration, so just call them and don't log the result
--disable_result_log
select reverse_lookup("127.0.0.1");
select reverse_lookup(127,0,0,1);
---enable_result_log
+# This function call may return different results depending on platform,
+# so ignore results (see Bug#52060).
select reverse_lookup("localhost");
+--enable_result_log
+
--error ER_CANT_INITIALIZE_UDF
select avgcost();
--error ER_CANT_INITIALIZE_UDF
=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc 2010-03-14 16:19:24 +0000
+++ b/sql/item_cmpfunc.cc 2010-03-22 09:11:30 +0000
@@ -1191,12 +1191,21 @@ get_year_value(THD *thd, Item ***item_ar
/*
Coerce value to the 19XX form in order to correctly compare
YEAR(2) & YEAR(4) types.
+ Here we are converting all item values but YEAR(4) fields since
+ 1) YEAR(4) already has a regular YYYY form and
+ 2) we don't want to convert zero/bad YEAR(4) values to the
+ value of 2000.
*/
- if (value < 70)
- value+= 100;
- if (value <= 1900)
- value+= 1900;
-
+ Item *real_item= item->real_item();
+ if (!(real_item->type() == Item::FIELD_ITEM &&
+ ((Item_field *)real_item)->field->type() == MYSQL_TYPE_YEAR &&
+ ((Item_field *)real_item)->field->field_length == 4))
+ {
+ if (value < 70)
+ value+= 100;
+ if (value <= 1900)
+ value+= 1900;
+ }
/* Convert year to DATETIME of form YYYY-00-00 00:00:00 (YYYY0000000000). */
value*= 10000000000LL;
Attachment: [text/bzr-bundle] bzr/john.embretsen@sun.com-20100322091130-7uulsfu857wax1o7.bundle
| Thread |
|---|
| • bzr commit into mysql-pe branch (john.embretsen:3987) | John H. Embretsen | 22 Mar |