Commit f1346cf8 authored by evgen@moonbone.local's avatar evgen@moonbone.local

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.
parent 10b2590c
...@@ -3398,3 +3398,8 @@ drop table t1,t2; ...@@ -3398,3 +3398,8 @@ drop table t1,t2;
SELECT 0.9888889889 * 1.011111411911; SELECT 0.9888889889 * 1.011111411911;
0.9888889889 * 1.011111411911 0.9888889889 * 1.011111411911
0.9998769417899202067879 0.9998769417899202067879
select 1 as ' a ';
a
1
Warnings:
Warning 1466 Leading spaces are removed from name ' a '
...@@ -2906,3 +2906,8 @@ drop table t1,t2; ...@@ -2906,3 +2906,8 @@ drop table t1,t2;
# Bug #20569: Garbage in DECIMAL results from some mathematical functions # Bug #20569: Garbage in DECIMAL results from some mathematical functions
# #
SELECT 0.9888889889 * 1.011111411911; SELECT 0.9888889889 * 1.011111411911;
#
# Bug #10977: No warning issued if a column name is truncated
#
select 1 as ' a ';
...@@ -573,6 +573,7 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs) ...@@ -573,6 +573,7 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs)
} }
if (cs->ctype) if (cs->ctype)
{ {
uint orig_len= length;
/* /*
This will probably need a better implementation in the future: This will probably need a better implementation in the future:
a function in CHARSET_INFO structure. a function in CHARSET_INFO structure.
...@@ -582,6 +583,11 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs) ...@@ -582,6 +583,11 @@ void Item::set_name(const char *str, uint length, CHARSET_INFO *cs)
length--; length--;
str++; 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)) if (!my_charset_same(cs, system_charset_info))
{ {
......
...@@ -4060,8 +4060,8 @@ select_item: ...@@ -4060,8 +4060,8 @@ select_item:
YYABORT; YYABORT;
if ($4.str) if ($4.str)
{ {
$2->set_name($4.str, $4.length, system_charset_info);
$2->is_autogenerated_name= FALSE; $2->is_autogenerated_name= FALSE;
$2->set_name($4.str, $4.length, system_charset_info);
} }
else if (!$2->name) { else if (!$2->name) {
char *str = $1; char *str = $1;
...@@ -4936,8 +4936,8 @@ udf_expr: ...@@ -4936,8 +4936,8 @@ udf_expr:
{ {
if ($4.str) if ($4.str)
{ {
$2->set_name($4.str, $4.length, system_charset_info);
$2->is_autogenerated_name= FALSE; $2->is_autogenerated_name= FALSE;
$2->set_name($4.str, $4.length, system_charset_info);
} }
else else
$2->set_name($1, (uint) ($3 - $1), YYTHD->charset()); $2->set_name($1, (uint) ($3 - $1), YYTHD->charset());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment