From d3f575c3647d4bb444192b7938a8aa4df64d1be9 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Jul 2004 12:14:45 +0300 Subject: [PATCH] test of duplicate field names (BUG#4608) mysql-test/r/view.result: test of duplicate field names mysql-test/t/view.test: test of duplicate field names sql/sql_view.cc: test of duplicate field names --- mysql-test/r/view.result | 2 ++ mysql-test/t/view.test | 6 ++++++ sql/sql_view.cc | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 16d51b4d90d..00ddc497b54 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -975,3 +975,5 @@ drop table t1; select * from v1; ERROR HY000: View 'test.v1' references invalid table(s) or column(s) drop view v1; +create view v1 (a,a) as select 'a','a'; +ERROR 42S21: Duplicate column name 'a' diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 5af65594606..dc8ea065902 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -894,3 +894,9 @@ drop table t1; -- error 1354 select * from v1; drop view v1; + +# +# check of duplication of column names +# +-- error 1060 +create view v1 (a,a) as select 'a','a'; diff --git a/sql/sql_view.cc b/sql/sql_view.cc index a4293bd4cd7..ed42c684803 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -204,6 +204,26 @@ int mysql_create_view(THD *thd, } } + /* Test absence of duplicates names */ + { + Item *item; + List_iterator_fast it(select_lex->item_list); + it++; + while((item= it++)) + { + Item *check; + List_iterator_fast itc(select_lex->item_list); + while((check= itc++) && check != item) + { + if (strcmp(item->name, check->name) == 0) + { + my_error(ER_DUP_FIELDNAME, MYF(0), item->name); + DBUG_RETURN(-1); + } + } + } + } + #ifndef NO_EMBEDDED_ACCESS_CHECKS /* Compare/check grants on view with grants of underlaying tables