Skip to content

Commit

Permalink
MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throw…
Browse files Browse the repository at this point in the history
…s an error
  • Loading branch information
abarkov committed Nov 8, 2021
1 parent 5cae401 commit bb20059
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
19 changes: 19 additions & 0 deletions mysql-test/main/ctype_ucs.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
13 changes: 13 additions & 0 deletions mysql-test/main/ctype_ucs.test
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,19 @@ SELECT CAST(_ucs2 0x0061DFFF0062 AS INT);
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 #
18 changes: 18 additions & 0 deletions mysql-test/main/ctype_utf8mb4.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
19 changes: 19 additions & 0 deletions mysql-test/main/ctype_utf8mb4.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
6 changes: 4 additions & 2 deletions sql/item_strfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bb20059

Please sign in to comment.