Commit 04ff9d4d authored by unknown's avatar unknown

Fixed bug #27695: View should not be allowed to have empty or

all space column names.

The parser has been modified to check VIEW column names
with the check_column_name function and to report an error
on empty and all space column names (same as for TABLE
column names).


sql/sql_yacc.yy:
  Fixed bug #27695.
  The parser has been modified to check VIEW column aliases
  with the check_column_name function and to report an error
  on empty columns and all space columns (same as for TABLE
  column names).
mysql-test/t/select.test:
  Updated test case for bug #27695.
mysql-test/r/select.result:
  Updated test case for bug #27695.
parent 6a8e10d2
...@@ -4077,23 +4077,21 @@ x ...@@ -4077,23 +4077,21 @@ x
1 1
Warnings: Warnings:
Warning 1466 Leading spaces are removed from name ' x' Warning 1466 Leading spaces are removed from name ' x'
CREATE VIEW v1 AS SELECT 1 AS ``;
ERROR 42000: Incorrect column name ''
CREATE VIEW v1 AS SELECT 1 AS ` `; CREATE VIEW v1 AS SELECT 1 AS ` `;
Warnings: ERROR 42000: Incorrect column name ' '
Warning 1474 Name ' ' has become '' CREATE VIEW v1 AS SELECT 1 AS ` `;
SELECT `` FROM v1; ERROR 42000: Incorrect column name ' '
CREATE VIEW v1 AS SELECT (SELECT 1 AS ` `);
1 ERROR 42000: Incorrect column name ' '
CREATE VIEW v2 AS SELECT 1 AS ` `; CREATE VIEW v1 AS SELECT 1 AS ` x`;
Warnings:
Warning 1474 Name ' ' has become ''
SELECT `` FROM v2;
1
CREATE VIEW v3 AS SELECT 1 AS ` x`;
Warnings: Warnings:
Warning 1466 Leading spaces are removed from name ' x' Warning 1466 Leading spaces are removed from name ' x'
SELECT `x` FROM v3; SELECT `x` FROM v1;
x x
1 1
DROP VIEW v1, v2, v3; ALTER VIEW v1 AS SELECT 1 AS ` `;
ERROR 42000: Incorrect column name ' '
DROP VIEW v1;
End of 5.0 tests End of 5.0 tests
...@@ -3466,22 +3466,29 @@ DROP TABLE t1; ...@@ -3466,22 +3466,29 @@ DROP TABLE t1;
# #
--disable_ps_protocol --disable_ps_protocol
SELECT 1 AS ` `; SELECT 1 AS ` `;
SELECT 1 AS ` `; SELECT 1 AS ` `;
SELECT 1 AS ` x`; SELECT 1 AS ` x`;
--enable_ps_protocol
--error 1166
CREATE VIEW v1 AS SELECT 1 AS ``;
--error 1166
CREATE VIEW v1 AS SELECT 1 AS ` `; CREATE VIEW v1 AS SELECT 1 AS ` `;
SELECT `` FROM v1;
CREATE VIEW v2 AS SELECT 1 AS ` `; --error 1166
SELECT `` FROM v2; CREATE VIEW v1 AS SELECT 1 AS ` `;
CREATE VIEW v3 AS SELECT 1 AS ` x`; --error 1166
SELECT `x` FROM v3; CREATE VIEW v1 AS SELECT (SELECT 1 AS ` `);
DROP VIEW v1, v2, v3; CREATE VIEW v1 AS SELECT 1 AS ` x`;
SELECT `x` FROM v1;
--enable_ps_protocol --error 1166
ALTER VIEW v1 AS SELECT 1 AS ` `;
DROP VIEW v1;
--echo End of 5.0 tests --echo End of 5.0 tests
...@@ -4305,6 +4305,12 @@ select_item: ...@@ -4305,6 +4305,12 @@ select_item:
MYSQL_YYABORT; MYSQL_YYABORT;
if ($4.str) if ($4.str)
{ {
if (Lex->sql_command == SQLCOM_CREATE_VIEW &&
check_column_name($4.str))
{
my_error(ER_WRONG_COLUMN_NAME, MYF(0), $4.str);
MYSQL_YYABORT;
}
$2->is_autogenerated_name= FALSE; $2->is_autogenerated_name= FALSE;
$2->set_name($4.str, $4.length, system_charset_info); $2->set_name($4.str, $4.length, system_charset_info);
} }
......
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