diff options
author | Dmitry Shulga <dmitry.shulga@mariadb.com> | 2022-02-15 12:20:43 +0700 |
---|---|---|
committer | Dmitry Shulga <dmitry.shulga@mariadb.com> | 2022-02-16 21:53:12 +0700 |
commit | e5693d31e2bbb5be23f0f57e309e280a6de2ac4b (patch) | |
tree | 536d0833b4735d46a777d4ac25e9285cd1716a27 /sql/sp_instr.cc | |
parent | e12d841ea7c5f4851e3bb8189668ff9de9135e3b (diff) | |
download | mariadb-git-bb-10.8-MDEV-5816.tar.gz |
MDEV-5816: Stored programs: validation of stored program statementsbb-10.8-MDEV-5816
Added storing of sql expression for instruction being parsed inside
the classes derived from the class sp_lex_instr.
Stored sql expression is returned by the abstract method
sp_lex_instr::get_expr_query
redefined in the derived classes.
The virtual method sp_lex_instr::get_query() has beens added to return
a parseable string for a statement that corresponds to the given
instruction.
Diffstat (limited to 'sql/sp_instr.cc')
-rw-r--r-- | sql/sp_instr.cc | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/sql/sp_instr.cc b/sql/sp_instr.cc index 8d5542e8673..f2901af3e56 100644 --- a/sql/sp_instr.cc +++ b/sql/sp_instr.cc @@ -418,6 +418,27 @@ int sp_instr::exec_core(THD *thd, uint *nextp) return 0; } + +void sp_lex_instr::get_query(String *sql_query) const +{ + LEX_CSTRING expr_query = get_expr_query(); + + /* + the expression string must me initialized in constructor of a derived class + */ + DBUG_ASSERT(expr_query.str != null_clex_str.str && + expr_query.length != null_clex_str.length); + + /* + Leave the method in case of empty query string. + */ + if (!expr_query.length) + return; + + sql_query->append(C_STRING_WITH_LEN("SELECT ")); + sql_query->append(expr_query.str, expr_query.length); +} + /* sp_instr_stmt class functions */ @@ -1192,7 +1213,7 @@ sp_instr_cpush::execute(THD *thd, uint *nextp) { DBUG_ENTER("sp_instr_cpush::execute"); - sp_cursor::reset(thd, &m_lex_keeper); + sp_cursor::reset(thd); m_lex_keeper.disable_query_cache(); thd->spcont->push_cursor(this); @@ -1495,14 +1516,14 @@ sp_instr_cursor_copy_struct::exec_core(THD *thd, uint *nextp) /* Copy structure only once. If the cursor%ROWTYPE variable is declared - inside a LOOP block, it gets its structure on the first loop interation + inside a LOOP block, it gets its structure on the first loop iteration and remembers the structure for all consequent loop iterations. It we recreated the structure on every iteration, we would get potential memory leaks, and it would be less efficient. */ if (!row->arguments()) { - sp_cursor tmp(thd, &m_lex_keeper, true); + sp_cursor tmp(thd, true); // Open the cursor without copying data if (!(ret= tmp.open(thd))) { |