Skip to content

Commit bb20059

Browse files
committed
MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
1 parent 5cae401 commit bb20059

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

mysql-test/main/ctype_ucs.result

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6473,5 +6473,24 @@ CAST(_ucs2 0x0061E0030062 AS INT)
64736473
Warnings:
64746474
Warning 1292 Truncated incorrect INTEGER value: 'ab'
64756475
#
6476+
# MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
6477+
#
6478+
SET NAMES utf8, collation_connection=ucs2_general_ci;
6479+
SELECT 1 COLLATE ucs2_general_ci;
6480+
1 COLLATE ucs2_general_ci
6481+
1
6482+
SELECT 1 COLLATE ucs2_bin;
6483+
1 COLLATE ucs2_bin
6484+
1
6485+
SELECT HEX(1 COLLATE ucs2_general_ci);
6486+
HEX(1 COLLATE ucs2_general_ci)
6487+
0031
6488+
SELECT HEX(1 COLLATE ucs2_bin);
6489+
HEX(1 COLLATE ucs2_bin)
6490+
0031
6491+
SELECT 1 COLLATE latin1_swedish_ci;
6492+
ERROR 42000: COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'ucs2'
6493+
SET NAMES utf8;
6494+
#
64766495
# End of 10.5 tests
64776496
#

mysql-test/main/ctype_ucs.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,19 @@ SELECT CAST(_ucs2 0x0061DFFF0062 AS INT);
11461146
SELECT CAST(_ucs2 0x0061D7000062 AS INT);
11471147
SELECT CAST(_ucs2 0x0061E0030062 AS INT);
11481148

1149+
--echo #
1150+
--echo # MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
1151+
--echo #
1152+
1153+
SET NAMES utf8, collation_connection=ucs2_general_ci;
1154+
SELECT 1 COLLATE ucs2_general_ci;
1155+
SELECT 1 COLLATE ucs2_bin;
1156+
SELECT HEX(1 COLLATE ucs2_general_ci);
1157+
SELECT HEX(1 COLLATE ucs2_bin);
1158+
--error ER_COLLATION_CHARSET_MISMATCH
1159+
SELECT 1 COLLATE latin1_swedish_ci;
1160+
SET NAMES utf8;
1161+
11491162
--echo #
11501163
--echo # End of 10.5 tests
11511164
--echo #

mysql-test/main/ctype_utf8mb4.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4149,3 +4149,21 @@ c
41494149
#
41504150
# End of 10.2 tests
41514151
#
4152+
#
4153+
# Start of 10.5 tests
4154+
#
4155+
#
4156+
# MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
4157+
#
4158+
SET NAMES utf8mb4;
4159+
SELECT 1 COLLATE utf8mb4_general_ci;
4160+
1 COLLATE utf8mb4_general_ci
4161+
1
4162+
SELECT 1 COLLATE utf8mb4_bin;
4163+
1 COLLATE utf8mb4_bin
4164+
1
4165+
SELECT 1 COLLATE latin1_swedish_ci;
4166+
ERROR 42000: COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'utf8mb4'
4167+
#
4168+
# End of 10.5 tests
4169+
#

mysql-test/main/ctype_utf8mb4.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,3 +2043,22 @@ EXECUTE IMMEDIATE 'SELECT ''😎'' AS c';
20432043
--echo #
20442044
--echo # End of 10.2 tests
20452045
--echo #
2046+
2047+
2048+
--echo #
2049+
--echo # Start of 10.5 tests
2050+
--echo #
2051+
2052+
--echo #
2053+
--echo # MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
2054+
--echo #
2055+
2056+
SET NAMES utf8mb4;
2057+
SELECT 1 COLLATE utf8mb4_general_ci;
2058+
SELECT 1 COLLATE utf8mb4_bin;
2059+
--error ER_COLLATION_CHARSET_MISMATCH
2060+
SELECT 1 COLLATE latin1_swedish_ci;
2061+
2062+
--echo #
2063+
--echo # End of 10.5 tests
2064+
--echo #

sql/item_strfunc.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,10 +3552,12 @@ String *Item_func_set_collation::val_str(String *str)
35523552

35533553
bool Item_func_set_collation::fix_length_and_dec()
35543554
{
3555-
if (!my_charset_same(args[0]->collation.collation, m_set_collation))
3555+
if (agg_arg_charsets_for_string_result(collation, args, 1))
3556+
return true;
3557+
if (!my_charset_same(collation.collation, m_set_collation))
35563558
{
35573559
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
3558-
m_set_collation->name, args[0]->collation.collation->csname);
3560+
m_set_collation->name, collation.collation->csname);
35593561
return TRUE;
35603562
}
35613563
collation.set(m_set_collation, DERIVATION_EXPLICIT,

0 commit comments

Comments
 (0)