summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <pem@mysql.comhem.se>2004-04-06 15:48:58 +0200
committerunknown <pem@mysql.comhem.se>2004-04-06 15:48:58 +0200
commitc22ccc136bfe8eaeaa9797775bde423cf0931bc1 (patch)
treebc2c17cd1e1f52242adcfb62808c8e18f12dc83a /sql
parent91dcd01159b2bcca753dd699fdf6a52d496ff7c1 (diff)
downloadmariadb-git-c22ccc136bfe8eaeaa9797775bde423cf0931bc1.tar.gz
Fixed BUG#2776: Stored procedure crash if variable assigned to default.
Keep track on the default value and use it. (Or NULL, if not declared.) mysql-test/r/sp.result: New testcases for BUG#2776. mysql-test/t/sp.test: New testcases for BUG#2776. sql/sp_pcontext.cc: Initialize local variable default value. sql/sp_pcontext.h: New method for saving default value. sql/sql_yacc.yy: If DEFAULT is use as a value in SET variable = ... in an SP, actually use the default.
Diffstat (limited to 'sql')
-rw-r--r--sql/sp_pcontext.cc1
-rw-r--r--sql/sp_pcontext.h10
-rw-r--r--sql/sql_yacc.yy17
3 files changed, 25 insertions, 3 deletions
diff --git a/sql/sp_pcontext.cc b/sql/sp_pcontext.cc
index b7e23c9f5ad..03333a2da72 100644
--- a/sql/sp_pcontext.cc
+++ b/sql/sp_pcontext.cc
@@ -118,6 +118,7 @@ sp_pcontext::push_pvar(LEX_STRING *name, enum enum_field_types type,
p->mode= mode;
p->offset= m_pvar.elements;
p->isset= (mode == sp_param_out ? FALSE : TRUE);
+ p->dflt= NULL;
insert_dynamic(&m_pvar, (gptr)&p);
}
}
diff --git a/sql/sp_pcontext.h b/sql/sp_pcontext.h
index 02134e3604f..a82cefa2e42 100644
--- a/sql/sp_pcontext.h
+++ b/sql/sp_pcontext.h
@@ -36,6 +36,7 @@ typedef struct sp_pvar
sp_param_mode_t mode;
uint offset; // Offset in current frame
my_bool isset;
+ Item *dflt;
} sp_pvar_t;
typedef struct sp_label
@@ -130,6 +131,15 @@ class sp_pcontext : public Sql_alloc
p->isset= val;
}
+ inline void
+ set_default(uint i, Item *it)
+ {
+ sp_pvar_t *p= find_pvar(i);
+
+ if (p)
+ p->dflt= it;
+ }
+
void
push_pvar(LEX_STRING *name, enum enum_field_types type, sp_param_mode_t mode);
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 4060554706d..79ede4dbfa7 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1365,6 +1365,7 @@ sp_decl:
lex->sphead->add_instr(in);
lex->spcont->set_isset(i, TRUE);
+ lex->spcont->set_default(i, it);
}
}
$$.vars= $2;
@@ -6246,15 +6247,25 @@ option_value:
}
else
{ /* An SP local variable */
+ sp_pvar_t *spv;
+ sp_instr_set *i;
+ Item *it;
+
if ($3 && $3->type() == Item::SUBSELECT_ITEM)
{ /* QQ For now, just disallow subselects as values */
send_error(lex->thd, ER_SP_SUBSELECT_NYI);
YYABORT;
}
- sp_pvar_t *spv= lex->spcont->find_pvar(&$1.base_name);
- sp_instr_set *i= new sp_instr_set(lex->sphead->instructions(),
- spv->offset, $3, spv->type);
+ spv= lex->spcont->find_pvar(&$1.base_name);
+ if ($3)
+ it= $3;
+ else if (spv->dflt)
+ it= spv->dflt;
+ else
+ it= new Item_null();
+ i= new sp_instr_set(lex->sphead->instructions(),
+ spv->offset, it, spv->type);
lex->sphead->add_instr(i);
spv->isset= TRUE;
}