From e4eadcfbddddce94da909f5248f6c68242ec6e3b Mon Sep 17 00:00:00 2001 From: "gshchepa/uchum@gleb.loc" <> Date: Thu, 13 Sep 2007 18:41:50 +0500 Subject: [PATCH] Fixed bug #27695. Declaring an all space column name in the SELECT FROM DUAL or in a view leads to misleading warning message: "Leading spaces are removed from name ' '". The Item::set_name method has been modified to raise warnings like "Name ' ' has become ''" in case of the truncation of an all space identifier to an empty string identifier instead of the "Leading spaces are removed from name ' '" warning message. --- mysql-test/r/select.result | 34 ++++++++++++++++++++++++++++++++++ mysql-test/t/select.test | 20 ++++++++++++++++++++ sql/item.cc | 14 ++++++++++---- sql/share/errmsg.txt | 2 ++ 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 2cf1316bb47..ed120a1bbb8 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -4062,4 +4062,38 @@ SHOW WARNINGS; Level Code Message Note 1003 select '0' AS `c1` from `test`.`t1` `join_0` join `test`.`t1` `join_1` join `test`.`t1` `join_2` join `test`.`t1` `join_3` join `test`.`t1` `join_4` join `test`.`t1` `join_5` join `test`.`t1` `join_6` join `test`.`t1` `join_7` where 0 group by '0','0','0','0','0' DROP TABLE t1; +SELECT 1 AS ` `; + +1 +Warnings: +Warning 1474 Name ' ' has become '' +SELECT 1 AS ` `; + +1 +Warnings: +Warning 1474 Name ' ' has become '' +SELECT 1 AS ` x`; +x +1 +Warnings: +Warning 1466 Leading spaces are removed from name ' x' +CREATE VIEW v1 AS SELECT 1 AS ` `; +Warnings: +Warning 1474 Name ' ' has become '' +SELECT `` FROM v1; + +1 +CREATE VIEW v2 AS SELECT 1 AS ` `; +Warnings: +Warning 1474 Name ' ' has become '' +SELECT `` FROM v2; + +1 +CREATE VIEW v3 AS SELECT 1 AS ` x`; +Warnings: +Warning 1466 Leading spaces are removed from name ' x' +SELECT `x` FROM v3; +x +1 +DROP VIEW v1, v2, v3; End of 5.0 tests diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index abf55745080..851e8164c44 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -3460,4 +3460,24 @@ SHOW WARNINGS; DROP TABLE t1; +# +# Bug #27695: Misleading warning when declaring all space column names and +# truncation of one-space column names to zero length names. +# + +SELECT 1 AS ` `; +SELECT 1 AS ` `; +SELECT 1 AS ` x`; + +CREATE VIEW v1 AS SELECT 1 AS ` `; +SELECT `` FROM v1; + +CREATE VIEW v2 AS SELECT 1 AS ` `; +SELECT `` FROM v2; + +CREATE VIEW v3 AS SELECT 1 AS ` x`; +SELECT `x` FROM v3; + +DROP VIEW v1, v2, v3; + --echo End of 5.0 tests diff --git a/sql/item.cc b/sql/item.cc index 66379d5dcf9..e9b2904e3da 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -700,10 +700,16 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs) str++; } if (orig_len != length && !is_autogenerated_name) - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES), - str + length - orig_len); - + { + if (length == 0) + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY), + str + length - orig_len); + else + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES), + str + length - orig_len); + } } if (!my_charset_same(cs, system_charset_info)) { diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 6d4ca33ccc7..709cd1fc0a9 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5637,3 +5637,5 @@ ER_ADMIN_WRONG_MRG_TABLE eng "Table '%-.64s' is differently defined or of non-MyISAM type or doesn't exist" ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT eng "Too high level of nesting for select" +ER_NAME_BECOMES_EMPTY + eng "Name '%-.64s' has become ''"