3728 Alexander Barkov 2011-03-04 [merge]
Merging from mysql-5.5
modified:
mysql-test/r/ctype_latin1.result
mysql-test/r/ctype_utf8.result
mysql-test/t/ctype_latin1.test
mysql-test/t/ctype_utf8.test
sql/item.cc
sql/mysqld.h
sql/sql_parse.cc
sql/sql_view.cc
3727 Nirbhay Choubey 2011-03-04 [merge]
Merge of fix for bug#11766219 from mysql-5.5 -> mysql-trunk.
modified:
mysys/default.c
=== modified file 'mysql-test/r/ctype_latin1.result'
--- a/mysql-test/r/ctype_latin1.result 2011-02-10 08:47:05 +0000
+++ b/mysql-test/r/ctype_latin1.result 2011-03-04 15:55:18 +0000
@@ -3269,6 +3269,21 @@ maketime(`a`,`a`,`a`)
DROP TABLE t1;
SET sql_mode=default;
#
+# Bug#11764503 (Bug#57341) Query in EXPLAIN EXTENDED shows wrong characters
+#
+SET NAMES utf8;
+EXPLAIN EXTENDED SELECT 'abcdó', _latin1'abcdó', _utf8'abcdó';
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select 'abcdó' AS `abcdó`,_latin1'abcd\xC3\xB3' AS `abcdó`,_utf8'abcd\xC3\xB3' AS `abcdó`
+SET NAMES latin1;
+EXPLAIN EXTENDED SELECT 'abcdó', _latin1'abcdó', _utf8'abcdó';
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select 'abcdó' AS `abcdó`,_latin1'abcd\xC3\xB3' AS `abcdó`,_utf8'abcd\xC3\xB3' AS `abcd�`
+#
# End of 5.5 tests
#
#
=== modified file 'mysql-test/r/ctype_utf8.result'
--- a/mysql-test/r/ctype_utf8.result 2011-02-10 08:47:05 +0000
+++ b/mysql-test/r/ctype_utf8.result 2011-03-04 15:55:18 +0000
@@ -5083,6 +5083,21 @@ GROUP BY INSERT('', t2.a, t1.a, (@@globa
ERROR 23000: Duplicate entry '107374182410737418241' for key 'group_key'
DROP TABLE t1;
#
+# Bug#11764503 (Bug#57341) Query in EXPLAIN EXTENDED shows wrong characters
+#
+SET NAMES latin1;
+EXPLAIN EXTENDED SELECT 'abcdÁÂÃÄÅ', _latin1'abcdÁÂÃÄÅ', _utf8'abcdÁÂÃÄÅ' AS u;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select 'abcdÁÂÃÄÅ' AS `abcdÁÂÃÄÅ`,_latin1'abcd\xC3\x81\xC3\x82\xC3\x83\xC3\x84\xC3\x85' AS `abcdÁÂÃÄÅ`,_utf8'abcd\xC3\x81\xC3\x82\xC3\x83\xC3\x84\xC3\x85' AS `u`
+SET NAMES utf8;
+EXPLAIN EXTENDED SELECT 'abcdÁÂÃÄÅ', _latin1'abcdÁÂÃÄÅ', _utf8'abcdÁÂÃÄÅ';
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select 'abcdÁÂÃÄÅ' AS `abcdÁÂÃÄÅ`,_latin1'abcd\xC3\x81\xC3\x82\xC3\x83\xC3\x84\xC3\x85' AS `abcdÃÂÃÄÅ`,_utf8'abcd\xC3\x81\xC3\x82\xC3\x83\xC3\x84\xC3\x85' AS `abcdÁÂÃÄÅ`
+#
# End of 5.5 tests
#
#
=== modified file 'mysql-test/t/ctype_latin1.test'
--- a/mysql-test/t/ctype_latin1.test 2010-11-18 09:26:45 +0000
+++ b/mysql-test/t/ctype_latin1.test 2011-03-04 15:55:18 +0000
@@ -143,6 +143,21 @@ SELECT '' LIKE '' ESCAPE EXPORT_SET(1, 1
--source include/ctype_numconv.inc
--echo #
+--echo # Bug#11764503 (Bug#57341) Query in EXPLAIN EXTENDED shows wrong characters
+--echo #
+# Test latin1 client erroneously started with --default-character-set=utf8
+# EXPLAIN output should still be pretty readable.
+# We're using 'ó' (\xC3\xB3) as a magic sequence:
+# - it's "LATIN CAPITAL LETTER A WITH TILDE ABOVE + SUPERSCRIPT 3" in latin1
+# - it's "LATIN SMALL LETTER O WITH ACUTE ABOVE" in utf8.
+SET NAMES utf8;
+EXPLAIN EXTENDED SELECT 'abcdó', _latin1'abcdó', _utf8'abcdó';
+# Test normal latin1
+SET NAMES latin1;
+EXPLAIN EXTENDED SELECT 'abcdó', _latin1'abcdó', _utf8'abcdó';
+
+
+--echo #
--echo # End of 5.5 tests
--echo #
=== modified file 'mysql-test/t/ctype_utf8.test'
--- a/mysql-test/t/ctype_utf8.test 2010-12-17 11:28:59 +0000
+++ b/mysql-test/t/ctype_utf8.test 2011-03-04 15:55:18 +0000
@@ -1570,6 +1570,16 @@ SELECT COUNT(*) FROM t1, t1 t2
GROUP BY INSERT('', t2.a, t1.a, (@@global.max_binlog_size));
DROP TABLE t1;
+--echo #
+--echo # Bug#11764503 (Bug#57341) Query in EXPLAIN EXTENDED shows wrong characters
+--echo #
+# Emulate utf8 client erroneously started with --default-character-set=latin1,
+# as in the bug report. EXPLAIN output should still be pretty readable
+SET NAMES latin1;
+EXPLAIN EXTENDED SELECT 'abcdÁÂÃÄÅ', _latin1'abcdÁÂÃÄÅ', _utf8'abcdÁÂÃÄÅ' AS u;
+# Test normal utf8
+SET NAMES utf8;
+EXPLAIN EXTENDED SELECT 'abcdÁÂÃÄÅ', _latin1'abcdÁÂÃÄÅ', _utf8'abcdÁÂÃÄÅ';
--echo #
--echo # End of 5.5 tests
=== modified file 'sql/item.cc'
--- a/sql/item.cc 2011-03-01 14:47:01 +0000
+++ b/sql/item.cc 2011-03-04 15:55:18 +0000
@@ -2606,7 +2606,9 @@ my_decimal *Item_float::val_decimal(my_d
void Item_string::print(String *str, enum_query_type query_type)
{
- if (query_type == QT_ORDINARY && is_cs_specified())
+ const bool print_introducer=
+ !(query_type & QT_WITHOUT_INTRODUCERS) && is_cs_specified();
+ if (print_introducer)
{
str->append('_');
str->append(collation.collation->csname);
@@ -2614,27 +2616,52 @@ void Item_string::print(String *str, enu
str->append('\'');
- if (query_type == QT_ORDINARY ||
- my_charset_same(str_value.charset(), system_charset_info))
+ if (query_type & QT_TO_SYSTEM_CHARSET)
{
- str_value.print(str);
+ if (print_introducer)
+ {
+ /*
+ Because we wrote an introducer, we must print str_value in its
+ charset, and the resulting bytes must not be changed until they
+ reach the end client.
+ But the caller is asking for system_charset_info, and may later
+ convert into character_set_results. That means two conversions: we
+ must ensure that they don't change our printed bytes.
+ So we print str_value in the least common denominator of the three
+ charsets involved: ASCII. Non-ASCII characters are printed as \xFF
+ sequences (which is ASCII too). This way, our bytes will not be
+ changed.
+ */
+ ErrConvString tmp(str_value.ptr(), str_value.length(), &my_charset_bin);
+ str->append(tmp.ptr());
+ }
+ else
+ {
+ if (my_charset_same(str_value.charset(), system_charset_info))
+ str_value.print(str); // already in system_charset_info
+ else // need to convert
+ {
+ THD *thd= current_thd;
+ LEX_STRING utf8_lex_str;
+
+ thd->convert_string(&utf8_lex_str,
+ system_charset_info,
+ str_value.c_ptr_safe(),
+ str_value.length(),
+ str_value.charset());
+
+ String utf8_str(utf8_lex_str.str,
+ utf8_lex_str.length,
+ system_charset_info);
+
+ utf8_str.print(str);
+ }
+ }
}
else
{
- THD *thd= current_thd;
- LEX_STRING utf8_lex_str;
-
- thd->convert_string(&utf8_lex_str,
- system_charset_info,
- str_value.c_ptr_safe(),
- str_value.length(),
- str_value.charset());
-
- String utf8_str(utf8_lex_str.str,
- utf8_lex_str.length,
- system_charset_info);
-
- utf8_str.print(str);
+ // Caller wants a result in the charset of str_value.
+ str_value.print(str);
}
str->append('\'');
=== modified file 'sql/mysqld.h'
--- a/sql/mysqld.h 2011-02-18 11:39:05 +0000
+++ b/sql/mysqld.h 2011-03-04 15:55:18 +0000
@@ -414,16 +414,16 @@ enum options_mysqld
/**
- Query type constants.
-
- QT_ORDINARY -- ordinary SQL query.
- QT_IS -- SQL query to be shown in INFORMATION_SCHEMA (in utf8 and without
- character set introducers).
+ Query type constants (usable as bitmap flags).
*/
enum enum_query_type
{
- QT_ORDINARY,
- QT_IS
+ /// Nothing specific, ordinary SQL query.
+ QT_ORDINARY= 0,
+ /// In utf8.
+ QT_TO_SYSTEM_CHARSET= (1 << 0),
+ /// Without character set introducers.
+ QT_WITHOUT_INTRODUCERS= (1 << 1)
};
/* query_id */
=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc 2011-03-03 08:32:36 +0000
+++ b/sql/sql_parse.cc 2011-03-04 15:55:18 +0000
@@ -4495,7 +4495,11 @@ static bool execute_sqlcom_select(THD *t
char buff[1024];
String str(buff,(uint32) sizeof(buff), system_charset_info);
str.length(0);
- thd->lex->unit.print(&str, QT_ORDINARY);
+ /*
+ The warnings system requires input in utf8, @see
+ mysqld_show_warnings().
+ */
+ thd->lex->unit.print(&str, QT_TO_SYSTEM_CHARSET);
str.append('\0');
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_YES, str.ptr());
=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc 2011-03-01 14:47:01 +0000
+++ b/sql/sql_view.cc 2011-03-04 15:55:18 +0000
@@ -840,7 +840,8 @@ static int mysql_register_view(THD *thd,
thd->variables.sql_mode&= ~MODE_ANSI_QUOTES;
lex->unit.print(&view_query, QT_ORDINARY);
- lex->unit.print(&is_query, QT_IS);
+ lex->unit.print(&is_query,
+ enum_query_type(QT_TO_SYSTEM_CHARSET | QT_WITHOUT_INTRODUCERS));
thd->variables.sql_mode|= sql_mode;
}
No bundle (reason: useless for push emails).| Thread |
|---|
| • bzr push into mysql-trunk branch (alexander.barkov:3727 to 3728) | Alexander Barkov | 4 Mar |