diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 1cd80b857ab..2a593f7c6df 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -977,3 +977,9 @@ 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' +create procedure p11 () begin declare v int; create view v1 as select v; end;// +Warnings: +Warning 1310 Referring to uninitialized variable v +call p11(); +ERROR HY000: View's SELECT contains a variable or parameter +drop procedure p11; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index b6ea504bc2e..33ffa114c28 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -900,3 +900,13 @@ drop view v1; # -- error 1060 create view v1 (a,a) as select 'a','a'; + +# +# SP variables inside view test +# +delimiter //; +create procedure p11 () begin declare v int; create view v1 as select v; end;// +delimiter ;// +-- error 1350 +call p11(); +drop procedure p11; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 03074ee3ba9..4fe30e50ffb 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1760,7 +1760,7 @@ int open_and_lock_tables(THD *thd, TABLE_LIST *tables) DBUG_ENTER("open_and_lock_tables"); uint counter; if (open_tables(thd, tables, &counter) || lock_tables(thd, tables, counter)) - DBUG_RETURN(-1); /* purecov: inspected */ + DBUG_RETURN(thd->net.report_error ? -1 : 1); /* purecov: inspected */ DBUG_RETURN(mysql_handle_derived(thd->lex)); } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index af6694c6318..9458b3830bf 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1987,7 +1987,8 @@ sp_elseifs: sp_case: expr THEN_SYM { - sp_head *sp= Lex->sphead; + LEX *lex= Lex; + sp_head *sp= lex->sphead; sp_pcontext *ctx= Lex->spcont; uint ip= sp->instructions(); sp_instr_jump_if_not *i; @@ -2005,6 +2006,7 @@ sp_case: Item *expr= new Item_func_eq(var, $1); i= new sp_instr_jump_if_not(ip, expr); + lex->variables_used= 1; } sp->push_backpatch(i, ctx->push_label((char *)"", 0)); sp->add_instr(i); @@ -6170,6 +6172,7 @@ simple_ident: $1.str); } $$ = (Item*) new Item_splocal($1, spv->offset); + lex->variables_used= 1; } else {