diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sp_pcontext.cc | 4 | ||||
-rw-r--r-- | sql/sp_pcontext.h | 17 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 8 |
3 files changed, 26 insertions, 3 deletions
diff --git a/sql/sp_pcontext.cc b/sql/sp_pcontext.cc index 147173ab4d8..6f3a9cb04aa 100644 --- a/sql/sp_pcontext.cc +++ b/sql/sp_pcontext.cc @@ -52,7 +52,7 @@ sp_cond_check(LEX_STRING *sqlstate) sp_pcontext::sp_pcontext(sp_pcontext *prev) : Sql_alloc(), m_psubsize(0), m_csubsize(0), m_hsubsize(0), - m_handlers(0), m_parent(prev) + m_handlers(0), m_parent(prev), m_pboundary(0) { VOID(my_init_dynamic_array(&m_pvar, sizeof(sp_pvar_t *), 16, 8)); VOID(my_init_dynamic_array(&m_cond, sizeof(sp_cond_type_t *), 16, 8)); @@ -150,7 +150,7 @@ sp_pcontext::diff_cursors(sp_pcontext *ctx) sp_pvar_t * sp_pcontext::find_pvar(LEX_STRING *name, my_bool scoped) { - uint i= m_pvar.elements; + uint i= m_pvar.elements - m_pboundary; while (i--) { diff --git a/sql/sp_pcontext.h b/sql/sp_pcontext.h index b8dd1742f7e..5c5890f82cd 100644 --- a/sql/sp_pcontext.h +++ b/sql/sp_pcontext.h @@ -174,6 +174,16 @@ class sp_pcontext : public Sql_alloc sp_pvar_t * find_pvar(uint offset); + /* + Set the current scope boundary (for default values) + The argument is the number of variables to skip. + */ + inline void + declare_var_boundary(uint n) + { + m_pboundary= n; + } + // // Labels // @@ -282,6 +292,13 @@ private: uint m_poffset; // Variable offset for this context uint m_coffset; // Cursor offset for this context + /* + Boundary for finding variables in this context. This is the number + of variables currently "invisible" to default clauses. + This is normally 0, but will be larger during parsing of + DECLARE ... DEFAULT, to get the scope right for DEFAULT values. + */ + uint m_pboundary; DYNAMIC_ARRAY m_pvar; // Parameters/variables DYNAMIC_ARRAY m_cond; // Conditions diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 671e2b1740d..3c478e6d52f 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1592,7 +1592,12 @@ sp_decls: sp_decl: DECLARE_SYM sp_decl_idents type - { Lex->sphead->reset_lex(YYTHD); } + { + LEX *lex= Lex; + + lex->sphead->reset_lex(YYTHD); + lex->spcont->declare_var_boundary($2); + } sp_opt_default { LEX *lex= Lex; @@ -1623,6 +1628,7 @@ sp_decl: lex->sphead->add_instr(in); ctx->set_default(off, it); } + ctx->declare_var_boundary(0); lex->sphead->restore_lex(YYTHD); $$.vars= $2; $$.conds= $$.hndlrs= $$.curs= 0; |