Commit 65d26d1f authored by Alexander Barkov's avatar Alexander Barkov

MDEV-10191 non convertible chars convert() resulted in Null instead "?" on Windows

The problem was introduced by the patch for MDEV-7661,
which (in addition to the fix itself) included an attempt to make
CONVERT/CAST work in the same way with fields
(i.e. return NULL in strict mode if a non-convertable character found).
It appeared to be a bad idea and some users were affected by this
behavior change. Changing CONVERT/CAST not depend on sql_mode
(restoring pre-10.1.4 behavior).
parent fa2701c6
......@@ -1945,7 +1945,7 @@ Warnings:
Warning 1300 Invalid utf8 character string: 'FD'
select convert(char(0xff,0x8f) using utf8);
convert(char(0xff,0x8f) using utf8)
NULL
??
Warnings:
Warning 1300 Invalid utf8 character string: '\xFF\x8F'
select hex(convert(char(2557 using latin1) using utf8));
......@@ -2114,7 +2114,7 @@ Warnings:
Warning 1300 Invalid utf8 character string: 'FF'
select hex(convert(0xFF using utf8));
hex(convert(0xFF using utf8))
NULL
3F
Warnings:
Warning 1300 Invalid utf8 character string: '\xFF'
select hex(_utf8 0x616263FF);
......@@ -10473,5 +10473,30 @@ END
DROP PROCEDURE p1;
SET @@SQL_MODE=default;
#
# MDEV-10191 non convertible chars convert() resulted in Null instead "?" on Windows
#
SET sql_mode='STRICT_TRANS_TABLES';
SELECT CONVERT(_utf8 0xC499 USING latin1);
CONVERT(_utf8 0xC499 USING latin1)
?
Warnings:
Warning 1977 Cannot convert 'utf8' character 0xC499 to 'latin1'
SELECT CAST(_utf8 0xC499 AS CHAR CHARACTER SET latin1);
CAST(_utf8 0xC499 AS CHAR CHARACTER SET latin1)
?
Warnings:
Warning 1977 Cannot convert 'utf8' character 0xC499 to 'latin1'
SET sql_mode=default;
SELECT CONVERT(_utf8 0xC499 USING latin1);
CONVERT(_utf8 0xC499 USING latin1)
?
Warnings:
Warning 1977 Cannot convert 'utf8' character 0xC499 to 'latin1'
SELECT CAST(_utf8 0xC499 AS CHAR CHARACTER SET latin1);
CAST(_utf8 0xC499 AS CHAR CHARACTER SET latin1)
?
Warnings:
Warning 1977 Cannot convert 'utf8' character 0xC499 to 'latin1'
#
# End of 10.1 tests
#
......@@ -1970,7 +1970,7 @@ Warnings:
Warning 1300 Invalid utf8mb4 character string: 'FD'
select convert(char(0xff,0x8f) using utf8mb4);
convert(char(0xff,0x8f) using utf8mb4)
NULL
??
Warnings:
Warning 1300 Invalid utf8mb4 character string: '\xFF\x8F'
select hex(convert(char(2557 using latin1) using utf8mb4));
......@@ -2139,7 +2139,7 @@ Warnings:
Warning 1300 Invalid utf8mb4 character string: 'FF'
select hex(convert(0xFF using utf8mb4));
hex(convert(0xFF using utf8mb4))
NULL
3F
Warnings:
Warning 1300 Invalid utf8mb4 character string: '\xFF'
select hex(_utf8mb4 0x616263FF);
......
......@@ -1802,7 +1802,7 @@ Warnings:
Warning 1300 Invalid utf8mb4 character string: 'FD'
select convert(char(0xff,0x8f) using utf8mb4);
convert(char(0xff,0x8f) using utf8mb4)
NULL
??
Warnings:
Warning 1300 Invalid utf8mb4 character string: '\xFF\x8F'
select hex(convert(char(2557 using latin1) using utf8mb4));
......@@ -1971,7 +1971,7 @@ Warnings:
Warning 1300 Invalid utf8mb4 character string: 'FF'
select hex(convert(0xFF using utf8mb4));
hex(convert(0xFF using utf8mb4))
NULL
3F
Warnings:
Warning 1300 Invalid utf8mb4 character string: '\xFF'
select hex(_utf8mb4 0x616263FF);
......
......@@ -1930,7 +1930,7 @@ Warnings:
Warning 1300 Invalid utf8mb4 character string: 'FD'
select convert(char(0xff,0x8f) using utf8mb4);
convert(char(0xff,0x8f) using utf8mb4)
NULL
??
Warnings:
Warning 1300 Invalid utf8mb4 character string: '\xFF\x8F'
select hex(convert(char(2557 using latin1) using utf8mb4));
......@@ -2099,7 +2099,7 @@ Warnings:
Warning 1300 Invalid utf8mb4 character string: 'FF'
select hex(convert(0xFF using utf8mb4));
hex(convert(0xFF using utf8mb4))
NULL
3F
Warnings:
Warning 1300 Invalid utf8mb4 character string: '\xFF'
select hex(_utf8mb4 0x616263FF);
......
......@@ -1930,7 +1930,7 @@ Warnings:
Warning 1300 Invalid utf8mb4 character string: 'FD'
select convert(char(0xff,0x8f) using utf8mb4);
convert(char(0xff,0x8f) using utf8mb4)
NULL
??
Warnings:
Warning 1300 Invalid utf8mb4 character string: '\xFF\x8F'
select hex(convert(char(2557 using latin1) using utf8mb4));
......@@ -2099,7 +2099,7 @@ Warnings:
Warning 1300 Invalid utf8mb4 character string: 'FF'
select hex(convert(0xFF using utf8mb4));
hex(convert(0xFF using utf8mb4))
NULL
3F
Warnings:
Warning 1300 Invalid utf8mb4 character string: '\xFF'
select hex(_utf8mb4 0x616263FF);
......
......@@ -1983,6 +1983,18 @@ SET @@SQL_MODE=default;
#DROP FUNCTION f1;
#SET NAMES utf8;
--echo #
--echo # MDEV-10191 non convertible chars convert() resulted in Null instead "?" on Windows
--echo #
SET sql_mode='STRICT_TRANS_TABLES';
SELECT CONVERT(_utf8 0xC499 USING latin1);
SELECT CAST(_utf8 0xC499 AS CHAR CHARACTER SET latin1);
SET sql_mode=default;
SELECT CONVERT(_utf8 0xC499 USING latin1);
SELECT CAST(_utf8 0xC499 AS CHAR CHARACTER SET latin1);
--echo #
--echo # End of 10.1 tests
......
......@@ -5628,7 +5628,7 @@ String_copier_for_item::copy_with_warn(CHARSET_INFO *dstcs, String *dst,
srccs == &my_charset_bin ?
dstcs->csname : srccs->csname,
err.ptr());
return m_thd->is_strict_mode();
return false;
}
if (const char *pos= cannot_convert_error_pos())
{
......@@ -5641,7 +5641,7 @@ String_copier_for_item::copy_with_warn(CHARSET_INFO *dstcs, String *dst,
ER_CANNOT_CONVERT_CHARACTER,
ER_THD(m_thd, ER_CANNOT_CONVERT_CHARACTER),
srccs->csname, buf, dstcs->csname);
return m_thd->is_strict_mode();
return false;
}
return false;
}
......
......@@ -548,8 +548,7 @@ class Item_func_not;
class Item_splocal;
/**
String_copier that honors the current sql_mode (strict vs non strict)
and can send warnings.
String_copier that sends Item specific warnings.
*/
class String_copier_for_item: public String_copier
{
......
......@@ -2396,7 +2396,7 @@ String *Item_char_typecast::copy(String *str, CHARSET_INFO *strcs)
if (copier.copy_with_warn(cast_cs, &tmp_value, strcs,
str->ptr(), str->length(), cast_length))
{
null_value= 1; // In strict mode: malformed data or could not convert
null_value= 1; // EOM
return 0;
}
check_truncation_with_warn(str, copier.source_end_pos() - str->ptr());
......
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