Commit 7f0236de authored by Alexander Barkov's avatar Alexander Barkov

Bug#58321 No warning when characters outside BMP0 is converted to UCS2

Problem: when inserting supplementary characters to an UCS2 column,
character was silently shrinked to 16-bit value.

Fix: produce a warning on attempt to insert a supplementary character,
and convert to question mark.

  @ mysql-test/r/ctype_many.result
  @ mysql-test/t/ctype_many.test
  Adding tests

  @ strings/ctype-ucs2.c
  Check if wc is greater than the highest value supported (0xFFFF),
  return MY_CS_ILUNI if true.
parent bdd4ab87
...@@ -216,6 +216,10 @@ DROP TABLE t1; ...@@ -216,6 +216,10 @@ DROP TABLE t1;
# End of 4.1 tests # End of 4.1 tests
--echo #
--echo # Start of 5.5 tests
--echo #
--echo # --echo #
--echo # WL#1213 Implement 4-byte UTF8, UTF16 and UTF32 --echo # WL#1213 Implement 4-byte UTF8, UTF16 and UTF32
--echo # Testing that only utf8mb4 is superset for utf8 --echo # Testing that only utf8mb4 is superset for utf8
...@@ -284,3 +288,19 @@ SELECT CHARSET(CONCAT(utf32, utf8mb4)) FROM t1; ...@@ -284,3 +288,19 @@ SELECT CHARSET(CONCAT(utf32, utf8mb4)) FROM t1;
SELECT CHARSET(CONCAT(utf32, utf16)) FROM t1; SELECT CHARSET(CONCAT(utf32, utf16)) FROM t1;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # Bug#58321 No warning when characters outside BMP0 is converted to UCS2
--echo #
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf32);
CREATE TABLE t2 (a VARCHAR(10) CHARACTER SET ucs2);
INSERT INTO t1 VALUES (0x10082), (0x12345);
INSERT INTO t2 SELECT * FROM t1;
SELECT HEX(a) FROM t2;
DROP TABLE t1;
DROP TABLE t2;
--echo #
--echo # End of 5.5 tests
--echo #
...@@ -2694,6 +2694,9 @@ static int my_uni_ucs2(CHARSET_INFO *cs __attribute__((unused)) , ...@@ -2694,6 +2694,9 @@ static int my_uni_ucs2(CHARSET_INFO *cs __attribute__((unused)) ,
if ( r+2 > e ) if ( r+2 > e )
return MY_CS_TOOSMALL2; return MY_CS_TOOSMALL2;
if (wc > 0xFFFF) /* UCS2 does not support characters outside BMP */
return MY_CS_ILUNI;
r[0]= (uchar) (wc >> 8); r[0]= (uchar) (wc >> 8);
r[1]= (uchar) (wc & 0xFF); r[1]= (uchar) (wc & 0xFF);
return 2; return 2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment