summaryrefslogtreecommitdiff
path: root/sql/sp_pcontext.cc
diff options
context:
space:
mode:
authorunknown <pem@mysql.comhem.se>2003-11-13 19:34:56 +0100
committerunknown <pem@mysql.comhem.se>2003-11-13 19:34:56 +0100
commitc9232c60e2ec287932158b6d820352dd98e85fd7 (patch)
treedf91989d7134f7e1e4a3a6c110312d910b30c970 /sql/sp_pcontext.cc
parent4696bb41b4cce563ffff8d7b6c32576214109113 (diff)
downloadmariadb-git-c9232c60e2ec287932158b6d820352dd98e85fd7.tar.gz
Various bug fixes:
- Duplicate parameters/variables, conditions and cursors (not allowed). - ITERATE in labelled BEGIN-END (not allowed). - Missing SQLSTATE [VALUE] keywords in CONDITION/HANDLER declaration (added). - Empty BEGIN-END (now allowed). - End label (now optional). include/mysqld_error.h: New error code for duplicate things (vars et al) in SPs. mysql-test/r/sp-error.result: New error tests for ITERATE in begin-end block and duplicate variables, conditions and cursors. mysql-test/r/sp.result: New tests for empty begin-end blocks, overriding local variables outside scope only, leave a begin-end block, and SQLSTATE [VALUE] words for CONDITION/HANDLER declarations. mysql-test/t/sp-error.test: New error tests for ITERATE in begin-end block and duplicate variables, conditions and cursors. mysql-test/t/sp.test: New tests for empty begin-end blocks, overriding local variables outside scope only, leave a begin-end block, and SQLSTATE [VALUE] words for CONDITION/HANDLER declarations. sql/lex.h: New SQLSTATE keyword. sql/share/czech/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/danish/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/dutch/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/english/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/estonian/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/french/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/german/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/greek/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/hungarian/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/italian/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/japanese/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/korean/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/norwegian-ny/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/norwegian/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/polish/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/portuguese/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/romanian/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/russian/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/serbian/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/slovak/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/spanish/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/swedish/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/share/ukrainian/errmsg.txt: New error message for duplicate things (vars et al) in SPs. sql/sp_pcontext.cc: Keep track on scope limits for error checking of duplicate variables, conditions and cursors. sql/sp_pcontext.h: Keep track on scope limits for error checking of duplicate variables, conditions and cursors. Also need to flag BEGIN labels to check for illegal ITERATEs. sql/sql_yacc.yy: End-labels in SPs loop and begin-end blocks are now optional. SQLSTATE [VALUE] added to syntax for sqlstates. Check for duplicate variable, condition and cursor declarations, but only in the same scope. Empty BEGIN-END statements now allowed. Check if ITERATE is referring to a BEGIN label.
Diffstat (limited to 'sql/sp_pcontext.cc')
-rw-r--r--sql/sp_pcontext.cc67
1 files changed, 60 insertions, 7 deletions
diff --git a/sql/sp_pcontext.cc b/sql/sp_pcontext.cc
index 3730230d47d..b7e23c9f5ad 100644
--- a/sql/sp_pcontext.cc
+++ b/sql/sp_pcontext.cc
@@ -32,6 +32,7 @@ sp_pcontext::sp_pcontext()
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));
VOID(my_init_dynamic_array(&m_cursor, sizeof(LEX_STRING), 16, 8));
+ VOID(my_init_dynamic_array(&m_scopes, sizeof(sp_scope_t), 16, 8));
m_label.empty();
}
@@ -41,23 +42,52 @@ sp_pcontext::destroy()
delete_dynamic(&m_pvar);
delete_dynamic(&m_cond);
delete_dynamic(&m_cursor);
+ delete_dynamic(&m_scopes);
m_label.empty();
}
+void
+sp_pcontext::push_scope()
+{
+ sp_scope_t s;
+
+ s.vars= m_pvar.elements;
+ s.conds= m_cond.elements;
+ s.curs= m_cursor.elements;
+ insert_dynamic(&m_scopes, (gptr)&s);
+}
+
+void
+sp_pcontext::pop_scope()
+{
+ (void)pop_dynamic(&m_scopes);
+}
+
/* This does a linear search (from newer to older variables, in case
** we have shadowed names).
** It's possible to have a more efficient allocation and search method,
** but it might not be worth it. The typical number of parameters and
** variables will in most cases be low (a handfull).
-** And this is only called during parsing.
+** ...and, this is only called during parsing.
*/
sp_pvar_t *
-sp_pcontext::find_pvar(LEX_STRING *name)
+sp_pcontext::find_pvar(LEX_STRING *name, my_bool scoped)
{
uint i = m_pvar.elements;
+ uint limit;
- while (i-- > 0)
+ if (! scoped || m_scopes.elements == 0)
+ limit= 0;
+ else
+ {
+ sp_scope_t s;
+
+ get_dynamic(&m_scopes, (gptr)&s, m_scopes.elements-1);
+ limit= s.vars;
+ }
+
+ while (i-- > limit)
{
sp_pvar_t *p;
@@ -101,6 +131,7 @@ sp_pcontext::push_label(char *name, uint ip)
{
lab->name= name;
lab->ip= ip;
+ lab->isbegin= FALSE;
m_label.push_front(lab);
}
return lab;
@@ -137,11 +168,22 @@ sp_pcontext::push_cond(LEX_STRING *name, sp_cond_type_t *val)
* See comment for find_pvar() above
*/
sp_cond_type_t *
-sp_pcontext::find_cond(LEX_STRING *name)
+sp_pcontext::find_cond(LEX_STRING *name, my_bool scoped)
{
uint i = m_cond.elements;
+ uint limit;
- while (i-- > 0)
+ if (! scoped || m_scopes.elements == 0)
+ limit= 0;
+ else
+ {
+ sp_scope_t s;
+
+ get_dynamic(&m_scopes, (gptr)&s, m_scopes.elements-1);
+ limit= s.conds;
+ }
+
+ while (i-- > limit)
{
sp_cond_t *p;
@@ -172,11 +214,22 @@ sp_pcontext::push_cursor(LEX_STRING *name)
* See comment for find_pvar() above
*/
my_bool
-sp_pcontext::find_cursor(LEX_STRING *name, uint *poff)
+sp_pcontext::find_cursor(LEX_STRING *name, uint *poff, my_bool scoped)
{
uint i = m_cursor.elements;
+ uint limit;
+
+ if (! scoped || m_scopes.elements == 0)
+ limit= 0;
+ else
+ {
+ sp_scope_t s;
- while (i-- > 0)
+ get_dynamic(&m_scopes, (gptr)&s, m_scopes.elements-1);
+ limit= s.curs;
+ }
+
+ while (i-- > limit)
{
LEX_STRING n;