diff options
author | gluh@mysql.com/eagle.(none) <> | 2007-09-03 12:22:56 +0500 |
---|---|---|
committer | gluh@mysql.com/eagle.(none) <> | 2007-09-03 12:22:56 +0500 |
commit | 33eaf2cd958fbd05e877db4525ef181693e58358 (patch) | |
tree | 01077acbc6ab3c38492a9f4d98bee49549e17a52 | |
parent | df7771de65b8b737e9da50314277bb65a907a0c9 (diff) | |
download | mariadb-git-33eaf2cd958fbd05e877db4525ef181693e58358.tar.gz |
Bug#29408 Cannot find view in columns table if the selection contains a function
Use view db name as thread default database, in order to ensure
that the view is parsed and prepared correctly.
-rw-r--r-- | mysql-test/r/sp.result | 22 | ||||
-rw-r--r-- | mysql-test/t/sp.test | 33 | ||||
-rw-r--r-- | sql/sql_parse.cc | 2 | ||||
-rw-r--r-- | sql/sql_view.cc | 14 |
4 files changed, 70 insertions, 1 deletions
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 4a278cd4aec..917ade02e0a 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -6314,4 +6314,26 @@ CALL p1(); NULL SET NAMES default; DROP PROCEDURE p1; +create function f1() +returns int(11) +not deterministic +contains sql +sql security definer +comment '' +begin +declare x int(11); +set x=-1; +return x; +end| +create view v1 as select 1 as one, f1() as days; +show create view test.v1; +View Create View +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `test`.`v1` AS select 1 AS `one`,`f1`() AS `days` +select column_name from information_schema.columns +where table_name='v1' and table_schema='test'; +column_name +one +days +drop view v1; +drop function f1; End of 5.0 tests diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 46a1b1dc740..f1c7c6969db 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -7299,4 +7299,37 @@ CALL p1(); SET NAMES default; DROP PROCEDURE p1; +# +# Bug#29408 Cannot find view in columns table if the selection contains a function +# +delimiter |; + +create function f1() + returns int(11) +not deterministic +contains sql +sql security definer +comment '' +begin + declare x int(11); + set x=-1; + return x; +end| + +delimiter ;| + +create view v1 as select 1 as one, f1() as days; + +connect (bug29408, localhost, root,,*NO-ONE*); +connection bug29408; + +show create view test.v1; +select column_name from information_schema.columns +where table_name='v1' and table_schema='test'; + +connection default; +disconnect bug29408; +drop view v1; +drop function f1; + --echo End of 5.0 tests diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index bb3ab9a67fe..084bcfc3c76 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1864,7 +1864,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, statistic_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS], &LOCK_status); bzero((char*) &table_list,sizeof(table_list)); - if (thd->copy_db_to(&table_list.db, 0)) + if (thd->copy_db_to(&table_list.db, &table_list.db_length)) break; pend= strend(packet); thd->convert_string(&conv_name, system_charset_info, diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 56d7a3f8a9d..35a97411511 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1008,8 +1008,19 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, table->view= lex= thd->lex= (LEX*) new(thd->mem_root) st_lex_local; { + char old_db_buf[NAME_LEN+1]; + LEX_STRING old_db= { old_db_buf, sizeof(old_db_buf) }; + bool dbchanged; Lex_input_stream lip(thd, table->query.str, table->query.length); thd->m_lip= &lip; + + /* + Use view db name as thread default database, in order to ensure + that the view is parsed and prepared correctly. + */ + if ((result= sp_use_new_db(thd, table->view_db, &old_db, 1, &dbchanged))) + goto end; + lex_start(thd); view_select= &lex->select_lex; view_select->select_number= ++thd->select_number; @@ -1051,6 +1062,9 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, thd->variables.character_set_client= save_cs; thd->variables.sql_mode= save_mode; + + if (dbchanged && mysql_change_db(thd, &old_db, TRUE)) + goto err; } if (!res && !thd->is_fatal_error) { |