summaryrefslogtreecommitdiff
path: root/sql/sql_view.cc
diff options
context:
space:
mode:
authorunknown <gluh@mysql.com/eagle.(none)>2007-09-03 12:22:56 +0500
committerunknown <gluh@mysql.com/eagle.(none)>2007-09-03 12:22:56 +0500
commitee0b7d895d42b0e3c93bdbffa7c4d3f51c1f60c2 (patch)
tree01077acbc6ab3c38492a9f4d98bee49549e17a52 /sql/sql_view.cc
parentb25b8cbc72ca8d723e10b59a4ffd1a8091ebefc7 (diff)
downloadmariadb-git-ee0b7d895d42b0e3c93bdbffa7c4d3f51c1f60c2.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. mysql-test/r/sp.result: test result mysql-test/t/sp.test: test case sql/sql_parse.cc: copy thd->db_length to table_list->db_length sql/sql_view.cc: Use view db name as thread default database, in order to ensure that the view is parsed and prepared correctly.
Diffstat (limited to 'sql/sql_view.cc')
-rw-r--r--sql/sql_view.cc14
1 files changed, 14 insertions, 0 deletions
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)
{