From f467f4bb934a9a73e9a5643f5b674d02d4d0aa6b Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 28 Apr 2014 17:01:58 +0400 Subject: [PATCH] MDEV-5459 Illegal mix of collations for datetime --- mysql-test/r/ctype_cp1251.result | 10 ++++++++++ mysql-test/t/ctype_cp1251.test | 8 ++++++++ sql/item_cmpfunc.cc | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/ctype_cp1251.result b/mysql-test/r/ctype_cp1251.result index 9c7164911af..313f60ef276 100644 --- a/mysql-test/r/ctype_cp1251.result +++ b/mysql-test/r/ctype_cp1251.result @@ -3282,5 +3282,15 @@ SELECT COALESCE(IF(test1=1, NULL, 1), test2) FROM t1; COALESCE(IF(test1=1, NULL, 1), test2) DROP TABLE t1; # +# MDEV-5459 Illegal mix of collations for datetime +# +SET NAMES cp1251; +CREATE TABLE t1 (dt DATETIME); +INSERT INTO t1 VALUES ('2014-01-02 10:20:30'); +SELECT date(dt) FROM t1 WHERE (CASE WHEN 1 THEN date(dt) ELSE null END >= '2013-12-01 00:00:00'); +date(dt) +2014-01-02 +DROP TABLE t1; +# # End of 5.5 tests # diff --git a/mysql-test/t/ctype_cp1251.test b/mysql-test/t/ctype_cp1251.test index ab260f0c7e8..0455f579922 100644 --- a/mysql-test/t/ctype_cp1251.test +++ b/mysql-test/t/ctype_cp1251.test @@ -95,6 +95,14 @@ SELECT COALESCE(IF(test1=1, 1, NULL), test2) FROM t1; SELECT COALESCE(IF(test1=1, NULL, 1), test2) FROM t1; DROP TABLE t1; +--echo # +--echo # MDEV-5459 Illegal mix of collations for datetime +--echo # +SET NAMES cp1251; +CREATE TABLE t1 (dt DATETIME); +INSERT INTO t1 VALUES ('2014-01-02 10:20:30'); +SELECT date(dt) FROM t1 WHERE (CASE WHEN 1 THEN date(dt) ELSE null END >= '2013-12-01 00:00:00'); +DROP TABLE t1; --echo # --echo # End of 5.5 tests diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index fa14f7bdcf1..998cb1cbd64 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -549,8 +549,8 @@ void Item_bool_func2::fix_length_and_dec() */ DTCollation coll; - if (args[0]->result_type() == STRING_RESULT && - args[1]->result_type() == STRING_RESULT && + if (args[0]->cmp_type() == STRING_RESULT && + args[1]->cmp_type() == STRING_RESULT && agg_arg_charsets_for_comparison(coll, args, 2)) return;