From 1c96f2d73eabc9217a2ad04ad232b0650eab2277 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 16 Jul 2006 00:45:38 +0400 Subject: [PATCH 1/4] Fixed bug#10977: No warning issued if a column name is truncated When an alias is set to a column leading spaces are removed from the alias. But when this is done on aliases set by user this can lead to confusion. Now Item::set_name() method issues the warning if leading spaces were removed from an alias set by user. New warning message is added. mysql-test/t/select.test: Added test case for bug#10977:No warning issued if a column name is truncated. mysql-test/r/select.result: Added test case for bug#10977:No warning issued if a column name is truncated. sql/sql_yacc.yy: Fixed bug#10977: No warning issued if a column name is truncated The is_autogenerated_name flag is set before set_name() method call. sql/item.cc: Fixed bug#10977: No warning issued if a column name is truncated Now Item::set_name() method issues the warning if leading spaces were removed from an alias set by user. --- mysql-test/r/select.result | 5 +++++ mysql-test/t/select.test | 5 +++++ sql/item.cc | 6 ++++++ sql/sql_yacc.yy | 4 ++-- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 7f01d453906..30708c0ccda 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -3398,3 +3398,8 @@ drop table t1,t2; SELECT 0.9888889889 * 1.011111411911; 0.9888889889 * 1.011111411911 0.9998769417899202067879 +select 1 as ' a '; +a +1 +Warnings: +Warning 1466 Leading spaces are removed from name ' a ' diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index b44f682c02e..ac5c121550a 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2906,3 +2906,8 @@ drop table t1,t2; # Bug #20569: Garbage in DECIMAL results from some mathematical functions # SELECT 0.9888889889 * 1.011111411911; + +# +# Bug #10977: No warning issued if a column name is truncated +# +select 1 as ' a '; diff --git a/sql/item.cc b/sql/item.cc index 511ea1ffb44..ad8b79182d4 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -573,6 +573,7 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs) } if (cs->ctype) { + uint orig_len= length; /* This will probably need a better implementation in the future: a function in CHARSET_INFO structure. @@ -582,6 +583,11 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs) length--; 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 (!my_charset_same(cs, system_charset_info)) { diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index deac9cb5c40..425945f525e 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -4060,8 +4060,8 @@ select_item: YYABORT; if ($4.str) { - $2->set_name($4.str, $4.length, system_charset_info); $2->is_autogenerated_name= FALSE; + $2->set_name($4.str, $4.length, system_charset_info); } else if (!$2->name) { char *str = $1; @@ -4936,8 +4936,8 @@ udf_expr: { if ($4.str) { - $2->set_name($4.str, $4.length, system_charset_info); $2->is_autogenerated_name= FALSE; + $2->set_name($4.str, $4.length, system_charset_info); } else $2->set_name($1, (uint) ($3 - $1), YYTHD->charset()); From 84245d4e87174ef4dbd4fdb2d5d1e7f4198642a9 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 16 Jul 2006 01:18:08 +0400 Subject: [PATCH 2/4] errmsg.txt: Fixed bug#10977: No warning issued if a column name is truncated New warning message is added. sql/share/errmsg.txt: Fixed bug#10977: No warning issued if a column name is truncated New warning message is added. --- sql/share/errmsg.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 9b20c37ece2..5c967ba19bd 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5621,3 +5621,5 @@ ER_TABLE_CANT_HANDLE_SPKEYS eng "The used table type doesn't support SPATIAL indexes" ER_NO_TRIGGERS_ON_SYSTEM_SCHEMA eng "Triggers can not be created on system tables" +ER_REMOVED_SPACES + eng "Leading spaces are removed from name '%s'" From 9a5daa602a11a2285b69b3c400d2e683cf63837a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 17 Jul 2006 14:22:21 +0400 Subject: [PATCH 3/4] mysql.test, mysql.result: Corrected the test case after fixing bug#10977 mysql-test/t/mysql.test: Corrected the test case after fixing bug#10977 mysql-test/r/mysql.result: Corrected the test case after fixing bug#10977 --- mysql-test/r/mysql.result | 8 ++++---- mysql-test/t/mysql.test | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result index 4b7084e813c..d70366a7589 100644 --- a/mysql-test/r/mysql.result +++ b/mysql-test/r/mysql.result @@ -36,19 +36,19 @@ Tables_in_test t1 t2 t3 - +_ Test delimiter : from command line a 1 - +_ Test delimiter :; from command line a 1 - +_ Test 'go' command(vertical output) G *************************** 1. row *************************** a: 1 - +_ Test 'go' command g a 1 diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index ac4c323f51e..98fadcfc75d 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -20,16 +20,16 @@ insert into t1 values(1); --disable_query_log # Test delimiter : supplied on the command line -select "Test delimiter : from command line" as " "; +select "Test delimiter : from command line" as "_"; --exec $MYSQL test --delimiter=":" -e "select * from t1:" # Test delimiter :; supplied on the command line -select "Test delimiter :; from command line" as " "; +select "Test delimiter :; from command line" as "_"; --exec $MYSQL test --delimiter=":;" -e "select * from t1:;" # Test 'go' command (vertical output) \G -select "Test 'go' command(vertical output) \G" as " "; +select "Test 'go' command(vertical output) \G" as "_"; --exec $MYSQL test -e "select * from t1\G" # Test 'go' command \g -select "Test 'go' command \g" as " "; +select "Test 'go' command \g" as "_"; --exec $MYSQL test -e "select * from t1\g" --enable_query_log drop table t1; From 14d72663f1eb0d9ec7cf7d353f09c2cc14a30597 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 17 Jul 2006 16:12:42 +0400 Subject: [PATCH 4/4] select.result, select.test: Test case for bug#10977 altered to make it work in both plain and ps-protocol modes. mysql-test/t/select.test: Test case for bug#10977 altered to make it work in both plain and ps-protocol modes. mysql-test/r/select.result: Test case for bug#10977 altered to make it work in both plain and ps-protocol modes. --- mysql-test/r/select.result | 7 ++++--- mysql-test/t/select.test | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 30708c0ccda..c2218585f7c 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -3398,8 +3398,9 @@ drop table t1,t2; SELECT 0.9888889889 * 1.011111411911; 0.9888889889 * 1.011111411911 0.9998769417899202067879 -select 1 as ' a '; -a -1 +prepare stmt from 'select 1 as " a "'; Warnings: Warning 1466 Leading spaces are removed from name ' a ' +execute stmt; +a +1 diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index ac5c121550a..592e366f835 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2910,4 +2910,5 @@ SELECT 0.9888889889 * 1.011111411911; # # Bug #10977: No warning issued if a column name is truncated # -select 1 as ' a '; +prepare stmt from 'select 1 as " a "'; +execute stmt;