预准备语句是否忽略字符串引入器?
我做了以下测试,似乎就是这种情况。我错过了什么吗?
/*Setting the variables*/
SET @str1 = _utf8mb4'some text' COLLATE utf8mb4_bin;
SET @str2 = _utf16'some text' COLLATE utf16_unicode_ci;
SET @@CHARACTER_SET_CLIENT = 'cp1250';
SET @@CHARACTER_SET_CONNECTION = 'ucs2';
SET @@COLLATION_CONNECTION = 'ucs2_unicode_ci';
SET @@CHARACTER_SET_RESULTS = 'ascii';
/*Preparing the prepared statement*/
PREPARE showStringInfo FROM 'SELECT
? `Input`,
CHARSET(?) `Input Character Set`,
COLLATION(?) `Input Collation`,
@@CHARACTER_SET_CLIENT,
@@CHARACTER_SET_CONNECTION,
@@COLLATION_CONNECTION,
@@CHARACTER_SET_RESULTS;';
执行
EXECUTE showStringInfo
USING @str1, @str1, @str1;
结果
| some text | ucs2 | ucs2_unicode_ci | cp1250 | ucs2 | ucs2_unicode_ci | ascii
执行
EXECUTE showStringInfo
USING @str2, @str2, @str2;
结果
s???? | ucs2 | ucs2_unicode_ci | cp1250 | ucs2 | ucs2_unicode_ci | ascii
查询时
SELECT
@str1 `Input`,
CHARSET(@str1) `Input Character Set`,
COLLATION(@str1) `Input Collation`,
@@CHARACTER_SET_CLIENT,
@@CHARACTER_SET_CONNECTION,
@@COLLATION_CONNECTION,
@@CHARACTER_SET_RESULTS;
结果
some text | utf8mb4 | utf8mb4_bin | cp1250 | ucs2 | ucs2_unicode_ci | ascii
查询
SELECT
@str2 `Input`,
CHARSET(@str2) `Input Character Set`,
COLLATION(@str2) `Input Collation`,
@@CHARACTER_SET_CLIENT,
@@CHARACTER_SET_CONNECTION,
@@COLLATION_CONNECTION,
@@CHARACTER_SET_RESULTS;
结果
s???? | utf16 | utf16_unicode_ci | cp1250 | ucs2 | ucs2_unicode_ci | ascii
测试似乎表明存储过程假定字符串为@@ CHARACTER_SET_CONNECTION和@@ COLLATION_CONNECTION,无论介绍人如何
(使用DataGrip的JDBC和mysql.exe测试)