diff options
author | Dmitry Shulga <dmitry.shulga@mariadb.com> | 2022-12-15 21:19:56 +0700 |
---|---|---|
committer | Dmitry Shulga <dmitry.shulga@mariadb.com> | 2022-12-15 21:19:56 +0700 |
commit | e7d2a50c3490a102dea580fd54dd760eeabe7906 (patch) | |
tree | 3e2294ec7fc93aa9a83cd4bb54c7ffc96029cdaf | |
parent | f89cf1cf4bb89cadfc997f08be7b6b26fbe9d40d (diff) | |
download | mariadb-git-10.11-MDEV-5816-1.tar.gz |
MDEV-5816: Stored programs: validation of stored program statements10.11-MDEV-5816-1
This is the follow-up to the commit i943b463cfaa303845a298d50a5c757cba6ab05e4
that fixes the issue with NEW/OLD pseudo-column in re-comipling SP statement.
-rw-r--r-- | sql/sp_instr.cc | 26 | ||||
-rw-r--r-- | sql/sp_instr.h | 31 |
2 files changed, 47 insertions, 10 deletions
diff --git a/sql/sp_instr.cc b/sql/sp_instr.cc index 4e62f7892fc..5714a08d250 100644 --- a/sql/sp_instr.cc +++ b/sql/sp_instr.cc @@ -695,12 +695,13 @@ LEX* sp_lex_instr::parse_expr(THD *thd, sp_head *sp) if (!parsing_failed) { thd->lex->set_trg_event_type_for_tables(); + adjust_sql_command(thd->lex); + parsing_failed= on_after_expr_parsing(thd); + if (sp->m_handler->type() == SP_TYPE_TRIGGER) setup_table_fields_for_trigger(thd, sp, saved_ptr_to_next_trg_items_list); - adjust_sql_command(thd->lex); - parsing_failed= on_after_expr_parsing(thd); /* Assign the list of items created on parsing to the current stored routine instruction. @@ -1057,6 +1058,27 @@ sp_instr_set_trigger_field::print(String *str) } +bool sp_instr_set_trigger_field::on_after_expr_parsing(THD *thd) +{ + DBUG_ASSERT(thd->lex->current_select->item_list.elements == 1); + + value= thd->lex->current_select->item_list.head(); + DBUG_ASSERT(value != nullptr); + + trigger_field = new (thd->mem_root) + Item_trigger_field(thd, thd->lex->current_context(), + Item_trigger_field::NEW_ROW, + m_trigger_field_name, UPDATE_ACL, false); + + if (!value || !trigger_field) + return true; + + thd->spcont->m_sp->m_cur_instr_trig_field_items.link_in_list( + trigger_field, &trigger_field->next_trg_field); + + return false; +} + /* sp_instr_jump class functions diff --git a/sql/sp_instr.h b/sql/sp_instr.h index b8e9d79d34c..ffdc36133a6 100644 --- a/sql/sp_instr.h +++ b/sql/sp_instr.h @@ -601,12 +601,11 @@ protected: { DBUG_ASSERT(thd->lex->current_select->item_list.elements == 1); - // TODO: how to get an item corresponding to an expression in - // the statement SET var=expr ? m_value= thd->lex->current_select->item_list.head(); DBUG_ASSERT(m_value != nullptr); - return false; + // Return error in release version if m_value == nullptr + return m_value == nullptr; } sp_rcontext *get_rcontext(THD *thd) const; @@ -714,7 +713,11 @@ public: trigger_field(trg_fld), value(val), m_expr_str(value_query) - {} + { + m_trigger_field_name= + LEX_CSTRING{strdup_root(current_thd->mem_root, trg_fld->field_name.str), + trg_fld->field_name.length}; + } int execute(THD *thd, uint *nextp) override; @@ -732,6 +735,8 @@ public: value= nullptr; } + bool on_after_expr_parsing(THD *thd) override; + protected: LEX_CSTRING get_expr_query() const override { @@ -746,6 +751,7 @@ private: */ LEX_CSTRING m_expr_str; + LEX_CSTRING m_trigger_field_name; public: PSI_statement_info* get_psi_info() override { return & psi_info; } static PSI_statement_info psi_info; @@ -925,7 +931,8 @@ protected: m_expr= thd->lex->current_select->item_list.head(); DBUG_ASSERT(m_expr != nullptr); - return false; + // Return error in release version if m_expr == nullptr + return m_expr == nullptr; } private: @@ -1013,8 +1020,6 @@ protected: void invalidate() override { - /* TODO: be careful and check that the object referenced by m_value - is not leaked */ m_value= nullptr; } @@ -1022,6 +1027,9 @@ protected: { DBUG_ASSERT(thd->lex->current_select->item_list.elements == 1); m_value= thd->lex->current_select->item_list.head(); + DBUG_ASSERT(m_value != nullptr); + + // Return error in release version if m_value == nullptr return m_value == nullptr; } @@ -1230,6 +1238,12 @@ protected: return m_cursor_query; } + bool on_after_expr_parsing(THD *) override + { + m_metadata_changed= false; + return false; + } + private: uint m_cursor; /**< Frame offset (for debugging) */ @@ -1544,7 +1558,8 @@ protected: m_case_expr= thd->lex->current_select->item_list.head(); DBUG_ASSERT(m_case_expr != nullptr); - return false; + // Return error in release version if m_case_expr == nullptr + return m_case_expr == nullptr; } private: |