summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2021-11-03 15:29:35 +0400
committerAlexander Barkov <bar@mariadb.com>2021-11-08 08:22:18 +0400
commitbb200599fff17602465668aee0ad4a614ee5528e (patch)
treec24d5639e512a65dcd31133b6236b84e75f80a5c
parent5cae401b00425746f157f448f2a8447d112cabdb (diff)
downloadmariadb-git-bb200599fff17602465668aee0ad4a614ee5528e.tar.gz
MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an errorbb-10.5-bar-MDEV-24584
-rw-r--r--mysql-test/main/ctype_ucs.result19
-rw-r--r--mysql-test/main/ctype_ucs.test13
-rw-r--r--mysql-test/main/ctype_utf8mb4.result18
-rw-r--r--mysql-test/main/ctype_utf8mb4.test19
-rw-r--r--sql/item_strfunc.cc6
5 files changed, 73 insertions, 2 deletions
diff --git a/mysql-test/main/ctype_ucs.result b/mysql-test/main/ctype_ucs.result
index dc3ed0cf7a9..6c14ca3ab66 100644
--- a/mysql-test/main/ctype_ucs.result
+++ b/mysql-test/main/ctype_ucs.result
@@ -6473,5 +6473,24 @@ CAST(_ucs2 0x0061E0030062 AS INT)
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'ab'
#
+# MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
+#
+SET NAMES utf8, collation_connection=ucs2_general_ci;
+SELECT 1 COLLATE ucs2_general_ci;
+1 COLLATE ucs2_general_ci
+1
+SELECT 1 COLLATE ucs2_bin;
+1 COLLATE ucs2_bin
+1
+SELECT HEX(1 COLLATE ucs2_general_ci);
+HEX(1 COLLATE ucs2_general_ci)
+0031
+SELECT HEX(1 COLLATE ucs2_bin);
+HEX(1 COLLATE ucs2_bin)
+0031
+SELECT 1 COLLATE latin1_swedish_ci;
+ERROR 42000: COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'ucs2'
+SET NAMES utf8;
+#
# End of 10.5 tests
#
diff --git a/mysql-test/main/ctype_ucs.test b/mysql-test/main/ctype_ucs.test
index cdc86fa3283..8f566fe831e 100644
--- a/mysql-test/main/ctype_ucs.test
+++ b/mysql-test/main/ctype_ucs.test
@@ -1147,5 +1147,18 @@ SELECT CAST(_ucs2 0x0061D7000062 AS INT);
SELECT CAST(_ucs2 0x0061E0030062 AS INT);
--echo #
+--echo # MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
+--echo #
+
+SET NAMES utf8, collation_connection=ucs2_general_ci;
+SELECT 1 COLLATE ucs2_general_ci;
+SELECT 1 COLLATE ucs2_bin;
+SELECT HEX(1 COLLATE ucs2_general_ci);
+SELECT HEX(1 COLLATE ucs2_bin);
+--error ER_COLLATION_CHARSET_MISMATCH
+SELECT 1 COLLATE latin1_swedish_ci;
+SET NAMES utf8;
+
+--echo #
--echo # End of 10.5 tests
--echo #
diff --git a/mysql-test/main/ctype_utf8mb4.result b/mysql-test/main/ctype_utf8mb4.result
index 5d039195f33..5c04eafdf70 100644
--- a/mysql-test/main/ctype_utf8mb4.result
+++ b/mysql-test/main/ctype_utf8mb4.result
@@ -4149,3 +4149,21 @@ c
#
# End of 10.2 tests
#
+#
+# Start of 10.5 tests
+#
+#
+# MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
+#
+SET NAMES utf8mb4;
+SELECT 1 COLLATE utf8mb4_general_ci;
+1 COLLATE utf8mb4_general_ci
+1
+SELECT 1 COLLATE utf8mb4_bin;
+1 COLLATE utf8mb4_bin
+1
+SELECT 1 COLLATE latin1_swedish_ci;
+ERROR 42000: COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'utf8mb4'
+#
+# End of 10.5 tests
+#
diff --git a/mysql-test/main/ctype_utf8mb4.test b/mysql-test/main/ctype_utf8mb4.test
index 8fbbee872ce..5640bc45ed1 100644
--- a/mysql-test/main/ctype_utf8mb4.test
+++ b/mysql-test/main/ctype_utf8mb4.test
@@ -2043,3 +2043,22 @@ EXECUTE IMMEDIATE 'SELECT ''😎'' AS c';
--echo #
--echo # End of 10.2 tests
--echo #
+
+
+--echo #
+--echo # Start of 10.5 tests
+--echo #
+
+--echo #
+--echo # MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
+--echo #
+
+SET NAMES utf8mb4;
+SELECT 1 COLLATE utf8mb4_general_ci;
+SELECT 1 COLLATE utf8mb4_bin;
+--error ER_COLLATION_CHARSET_MISMATCH
+SELECT 1 COLLATE latin1_swedish_ci;
+
+--echo #
+--echo # End of 10.5 tests
+--echo #
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 2967a0b42aa..e7abb51893c 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -3552,10 +3552,12 @@ String *Item_func_set_collation::val_str(String *str)
bool Item_func_set_collation::fix_length_and_dec()
{
- if (!my_charset_same(args[0]->collation.collation, m_set_collation))
+ if (agg_arg_charsets_for_string_result(collation, args, 1))
+ return true;
+ if (!my_charset_same(collation.collation, m_set_collation))
{
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
- m_set_collation->name, args[0]->collation.collation->csname);
+ m_set_collation->name, collation.collation->csname);
return TRUE;
}
collation.set(m_set_collation, DERIVATION_EXPLICIT,