summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/select.result5
-rw-r--r--mysql-test/t/select.test5
-rw-r--r--sql/item.cc6
-rw-r--r--sql/sql_yacc.yy4
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());