summaryrefslogtreecommitdiff
path: root/sql/sql_lex.cc
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2017-03-16 16:28:52 +0400
committerAlexander Barkov <bar@mariadb.org>2017-04-05 15:03:00 +0400
commit9dfe7bf86dd1743dc3bf33a8c09937aca9db503a (patch)
treefec18db97f751592fe62bacd19faca4d96cab23f /sql/sql_lex.cc
parent84c55a5668db582aa92dd2ccf076fbb783894b12 (diff)
downloadmariadb-git-9dfe7bf86dd1743dc3bf33a8c09937aca9db503a.tar.gz
MDEV-10598 Variable declarations can go after cursor declarations
Based on a contributed patch from Jerome Brauge.
Diffstat (limited to 'sql/sql_lex.cc')
-rw-r--r--sql/sql_lex.cc20
1 files changed, 13 insertions, 7 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index d0d60b2c7b2..7e5d29cd675 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -5628,7 +5628,7 @@ bool LEX::sp_for_loop_cursor_finalize(THD *thd, const Lex_for_loop_st &loop)
bool LEX::sp_declare_cursor(THD *thd, const LEX_STRING name,
sp_lex_cursor *cursor_stmt,
- sp_pcontext *param_ctx)
+ sp_pcontext *param_ctx, bool add_cpush_instr)
{
uint offp;
sp_instr_cpush *i;
@@ -5639,12 +5639,18 @@ bool LEX::sp_declare_cursor(THD *thd, const LEX_STRING name,
return true;
}
cursor_stmt->set_cursor_name(name);
- i= new (thd->mem_root)
- sp_instr_cpush(sphead->instructions(), spcont, cursor_stmt,
- spcont->current_cursor_count());
- return i == NULL ||
- sphead->add_instr(i) ||
- spcont->add_cursor(name, param_ctx, cursor_stmt);
+
+ if (spcont->add_cursor(name, param_ctx, cursor_stmt))
+ return true;
+
+ if (add_cpush_instr)
+ {
+ i= new (thd->mem_root)
+ sp_instr_cpush(sphead->instructions(), spcont, cursor_stmt,
+ spcont->current_cursor_count() - 1);
+ return i == NULL || sphead->add_instr(i);
+ }
+ return false;
}