From ce069b1f6b3847309b06e548adf23fa0c7238336 Mon Sep 17 00:00:00 2001
From: Alexander Barkov <bar@mnogosearch.org>
Date: Tue, 15 Oct 2013 13:39:44 +0400
Subject: [PATCH] A follow-up for WL#5624: Collation customization improvements

The reasons for failures to initialize a user collation defined
in Index.xml are now correctly reported
(in SHOW WARNINGS and in the server error log) if the COLLATE clause
is used with an expression, e.g.:

  SELECT <exrp> COLLATE <collation name> FROM t1;

Previously, the failure reasons were reported only by COLLATE clauses
in SET NAMES and in DDL statements, e.g.:

  SET NAMES utf8 COLLATE utf8_xxx_ci;
  CREATE TABLE t1 (a VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_xxx_ci);
---
 mysql-test/r/ctype_ldml.result | 8 +++++++-
 mysql-test/t/ctype_ldml.test   | 6 +++++-
 sql/item_strfunc.cc            | 5 +----
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/mysql-test/r/ctype_ldml.result b/mysql-test/r/ctype_ldml.result
index d80e0726e7..5eef6c3864 100644
--- a/mysql-test/r/ctype_ldml.result
+++ b/mysql-test/r/ctype_ldml.result
@@ -769,6 +769,12 @@ SHOW WARNINGS;
 Level	Code	Message
 Error	1273	Unknown collation: 'utf8_5624_2'
 Warning	1273	Syntax error at '[strength tertiary]'
+SELECT _utf8'test' COLLATE utf8_5624_2;
+ERROR HY000: Unknown collation: 'utf8_5624_2'
+SHOW WARNINGS;
+Level	Code	Message
+Error	1273	Unknown collation: 'utf8_5624_2'
+Warning	1273	Syntax error at '[strength tertiary]'
 #
 # WL#5624, reset before primary ignorable
 #
@@ -1086,4 +1092,4 @@ DROP TABLE t1;
 # Bug#14197426 PARSE ERRORS IN LOADABLE UCA / LDML COLLATIONS ARE SILENTLY IGNORED
 #
 # Search for occurrences of [ERROR] Syntax error at '[strength tertiary]'
-Occurances : 1
+Occurances : 2
diff --git a/mysql-test/t/ctype_ldml.test b/mysql-test/t/ctype_ldml.test
index e67ee73051..bcb16334df 100644
--- a/mysql-test/t/ctype_ldml.test
+++ b/mysql-test/t/ctype_ldml.test
@@ -249,6 +249,10 @@ DROP TABLE t1;
 SET NAMES utf8 COLLATE utf8_5624_2;
 SHOW WARNINGS;
 
+--error ER_UNKNOWN_COLLATION
+SELECT _utf8'test' COLLATE utf8_5624_2;
+SHOW WARNINGS;
+
 --echo #
 --echo # WL#5624, reset before primary ignorable
 --echo #
@@ -353,7 +357,7 @@ DROP TABLE t1;
 --let $out_file= $MYSQLTEST_VARDIR/tmp/ctype_ldml_log.err
 --let OUTF= $out_file
 # Error messages are not seen in error log in embedded version
---let EMBEDDED=`SELECT version() LIKE '%embedded%'`
+--let EMBEDDED=`SELECT IF(version() LIKE '%embedded%',2,0)`
 --echo # Search for occurrences of [ERROR] Syntax error at '[strength tertiary]'
 
 perl;
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 8dd2a33b1a..68237ef495 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -3463,11 +3463,8 @@ void Item_func_set_collation::fix_length_and_dec()
 					 MY_CS_BINSORT,MYF(0));
   else
   {
-    if (!(set_collation= get_charset_by_name(colname,MYF(0))))
-    {
-      my_error(ER_UNKNOWN_COLLATION, MYF(0), colname);
+    if (!(set_collation= mysqld_collation_get_by_name(colname)))  
       return;
-    }
   }
 
   if (!set_collation || 
-- 
2.30.9