summaryrefslogtreecommitdiff
path: root/sql/sql_view.cc
diff options
context:
space:
mode:
authorunknown <gshchepa/uchum@gleb.loc>2007-09-06 19:15:31 +0500
committerunknown <gshchepa/uchum@gleb.loc>2007-09-06 19:15:31 +0500
commit414d345071297b8a377a9643c3a20ab576d61e2f (patch)
treebbd6d8c264f52e951930024d8102a0973711582c /sql/sql_view.cc
parenta3dc9569e983db92ca1ace1f3fe66428cd8098e2 (diff)
parent403ed43b1d338e7e7b845546178cac2e3334e1e2 (diff)
downloadmariadb-git-414d345071297b8a377a9643c3a20ab576d61e2f.tar.gz
Merge gleb.loc:/home/uchum/work/bk/5.0-opt
into gleb.loc:/home/uchum/work/bk/5.1-opt BitKeeper/etc/ignore: auto-union mysql-test/r/distinct.result: Auto merged sql/sql_yacc.yy: Auto merged mysql-test/include/mix1.inc: Merge with 5.0-opt. mysql-test/r/group_by.result: Merge with 5.0-opt. mysql-test/r/innodb_mysql.result: Merge with 5.0-opt. mysql-test/r/sp.result: Merge with 5.0-opt. mysql-test/t/group_by.test: Merge with 5.0-opt. mysql-test/t/sp.test: Merge with 5.0-opt. sql/sql_parse.cc: Merge with 5.0-opt. sql/sql_select.cc: Merge with 5.0-opt. sql/sql_view.cc: Merge with 5.0-opt.
Diffstat (limited to 'sql/sql_view.cc')
-rw-r--r--sql/sql_view.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 38d7174b7ca..b444992f4e9 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -1044,10 +1044,20 @@ 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->select_stmt.str,
table->select_stmt.length);
+ /*
+ 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;
@@ -1091,6 +1101,9 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
lex->sql_command= old_lex->sql_command;
thd->variables.sql_mode= saved_mode;
+
+ if (dbchanged && mysql_change_db(thd, &old_db, TRUE))
+ goto err;
}
if (!parse_status)
{