Commit f5b60857 authored by Alexander Barkov's avatar Alexander Barkov

A cleanup for 84c55a56 (that implemented cursor FOR loops earlier):

  MDEV-10581 sql_mode=ORACLE: Explicit cursor FOR LOOP
  MDEV-12098 sql_mode=ORACLE: Implicit cursor FOR loop

Cleanup changes:
- Removing sp_lex_cursor::m_cursor_name
- Adding sp_instr_cursor_copy_struct::m_cursor (the cursor global index)
- Fixing sp_instr_cursor_copy_struct::print() to access to the cursor
  name using m_ctx and m_cursor (like other cursor related instructions do)
  instead of m_cursor_name.

This change is needed to unify sp_assignment_lex and sp_cursor_lex later,
to fix this problem easier:
 MDEV-16558 Parenthesized expression does not work as a lower FOR loop bound
parent 1ba5b38b
...@@ -4506,7 +4506,7 @@ void ...@@ -4506,7 +4506,7 @@ void
sp_instr_cursor_copy_struct::print(String *str) sp_instr_cursor_copy_struct::print(String *str)
{ {
sp_variable *var= m_ctx->find_variable(m_var); sp_variable *var= m_ctx->find_variable(m_var);
const LEX_CSTRING *name= m_lex_keeper.cursor_name(); const LEX_CSTRING *name= m_ctx->find_cursor(m_cursor);
str->append(STRING_WITH_LEN("cursor_copy_struct ")); str->append(STRING_WITH_LEN("cursor_copy_struct "));
str->append(name); str->append(name);
str->append(' '); str->append(' ');
...@@ -5001,7 +5001,8 @@ bool sp_head::add_for_loop_open_cursor(THD *thd, sp_pcontext *spcont, ...@@ -5001,7 +5001,8 @@ bool sp_head::add_for_loop_open_cursor(THD *thd, sp_pcontext *spcont,
sp_instr *instr_copy_struct= sp_instr *instr_copy_struct=
new (thd->mem_root) sp_instr_cursor_copy_struct(instructions(), new (thd->mem_root) sp_instr_cursor_copy_struct(instructions(),
spcont, pcursor->lex(), spcont, coffset,
pcursor->lex(),
index->offset); index->offset);
if (instr_copy_struct == NULL || add_instr(instr_copy_struct)) if (instr_copy_struct == NULL || add_instr(instr_copy_struct))
return true; return true;
......
...@@ -1004,12 +1004,10 @@ class sp_package: public sp_head ...@@ -1004,12 +1004,10 @@ class sp_package: public sp_head
class sp_lex_cursor: public sp_lex_local, public Query_arena class sp_lex_cursor: public sp_lex_local, public Query_arena
{ {
LEX_CSTRING m_cursor_name;
public: public:
sp_lex_cursor(THD *thd, const LEX *oldlex, MEM_ROOT *mem_root_arg) sp_lex_cursor(THD *thd, const LEX *oldlex, MEM_ROOT *mem_root_arg)
:sp_lex_local(thd, oldlex), :sp_lex_local(thd, oldlex),
Query_arena(mem_root_arg, STMT_INITIALIZED_FOR_SP), Query_arena(mem_root_arg, STMT_INITIALIZED_FOR_SP)
m_cursor_name(null_clex_str)
{ } { }
sp_lex_cursor(THD *thd, const LEX *oldlex) sp_lex_cursor(THD *thd, const LEX *oldlex)
:sp_lex_local(thd, oldlex), :sp_lex_local(thd, oldlex),
...@@ -1037,8 +1035,6 @@ class sp_lex_cursor: public sp_lex_local, public Query_arena ...@@ -1037,8 +1035,6 @@ class sp_lex_cursor: public sp_lex_local, public Query_arena
thd->free_list= NULL; thd->free_list= NULL;
return false; return false;
} }
const LEX_CSTRING *cursor_name() const { return &m_cursor_name; }
void set_cursor_name(const LEX_CSTRING *name) { m_cursor_name= *name; }
}; };
...@@ -1213,10 +1209,6 @@ class sp_lex_keeper ...@@ -1213,10 +1209,6 @@ class sp_lex_keeper
m_lex->safe_to_cache_query= 0; m_lex->safe_to_cache_query= 0;
} }
const LEX_CSTRING *cursor_name() const
{
return m_lex->cursor_name();
}
private: private:
LEX *m_lex; LEX *m_lex;
...@@ -1864,11 +1856,14 @@ class sp_instr_cursor_copy_struct: public sp_instr ...@@ -1864,11 +1856,14 @@ class sp_instr_cursor_copy_struct: public sp_instr
sp_instr_cursor_copy_struct(const sp_instr_cursor_copy_struct &); sp_instr_cursor_copy_struct(const sp_instr_cursor_copy_struct &);
void operator=(sp_instr_cursor_copy_struct &); void operator=(sp_instr_cursor_copy_struct &);
sp_lex_keeper m_lex_keeper; sp_lex_keeper m_lex_keeper;
uint m_cursor;
uint m_var; uint m_var;
public: public:
sp_instr_cursor_copy_struct(uint ip, sp_pcontext *ctx, sp_instr_cursor_copy_struct(uint ip, sp_pcontext *ctx, uint coffs,
sp_lex_cursor *lex, uint voffs) sp_lex_cursor *lex, uint voffs)
: sp_instr(ip, ctx), m_lex_keeper(lex, FALSE), m_var(voffs) : sp_instr(ip, ctx), m_lex_keeper(lex, FALSE),
m_cursor(coffs),
m_var(voffs)
{} {}
virtual ~sp_instr_cursor_copy_struct() virtual ~sp_instr_cursor_copy_struct()
{} {}
......
...@@ -5484,7 +5484,8 @@ LEX::sp_variable_declarations_cursor_rowtype_finalize(THD *thd, int nvars, ...@@ -5484,7 +5484,8 @@ LEX::sp_variable_declarations_cursor_rowtype_finalize(THD *thd, int nvars,
spvar->field_def.set_cursor_rowtype_ref(offset); spvar->field_def.set_cursor_rowtype_ref(offset);
sp_instr_cursor_copy_struct *instr= sp_instr_cursor_copy_struct *instr=
new (thd->mem_root) sp_instr_cursor_copy_struct(sphead->instructions(), new (thd->mem_root) sp_instr_cursor_copy_struct(sphead->instructions(),
spcont, pcursor->lex(), spcont, offset,
pcursor->lex(),
spvar->offset); spvar->offset);
if (instr == NULL || sphead->add_instr(instr)) if (instr == NULL || sphead->add_instr(instr))
return true; return true;
...@@ -5925,7 +5926,6 @@ bool LEX::sp_declare_cursor(THD *thd, const LEX_CSTRING *name, ...@@ -5925,7 +5926,6 @@ bool LEX::sp_declare_cursor(THD *thd, const LEX_CSTRING *name,
my_error(ER_SP_DUP_CURS, MYF(0), name->str); my_error(ER_SP_DUP_CURS, MYF(0), name->str);
return true; return true;
} }
cursor_stmt->set_cursor_name(name);
if (unlikely(spcont->add_cursor(name, param_ctx, cursor_stmt))) if (unlikely(spcont->add_cursor(name, param_ctx, cursor_stmt)))
return true; return true;
......
...@@ -3177,8 +3177,6 @@ struct LEX: public Query_tables_list ...@@ -3177,8 +3177,6 @@ struct LEX: public Query_tables_list
return NULL; return NULL;
} }
virtual const LEX_CSTRING *cursor_name() const { return &null_clex_str; }
void start(THD *thd); void start(THD *thd);
inline bool is_ps_or_view_context_analysis() inline bool is_ps_or_view_context_analysis()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment