18 #include "sp_pcontext.h"
34 case sp_condition_value::ERROR_CODE:
37 case sp_condition_value::SQLSTATE:
46 void sp_pcontext::init(uint var_offset,
48 int num_case_expressions)
50 m_var_offset= var_offset;
51 m_cursor_offset= cursor_offset;
52 m_num_case_exprs= num_case_expressions;
58 sp_pcontext::sp_pcontext()
61 m_max_var_index(0), m_max_cursor_index(0),
62 m_parent(NULL), m_pboundary(0),
63 m_scope(REGULAR_SCOPE)
71 m_level(prev->m_level + 1),
72 m_max_var_index(0), m_max_cursor_index(0),
73 m_parent(prev), m_pboundary(0),
76 init(prev->m_var_offset + prev->m_max_var_index,
77 prev->current_cursor_count(),
78 prev->get_num_case_exprs());
82 sp_pcontext::~sp_pcontext()
84 for (
int i= 0;
i < m_children.elements(); ++
i)
85 delete m_children.
at(
i);
101 m_parent->m_max_var_index+= m_max_var_index;
103 uint submax= max_cursor_index();
104 if (submax > m_parent->m_max_cursor_index)
105 m_parent->m_max_cursor_index= submax;
107 if (m_num_case_exprs > m_parent->m_num_case_exprs)
108 m_parent->m_num_case_exprs= m_num_case_exprs;
120 while (pctx && pctx != ctx)
122 n+= pctx->m_handlers.elements();
124 pctx= pctx->parent_context();
127 return (exclusive && last_ctx ? n - last_ctx->m_handlers.elements() :
n);
138 while (pctx && pctx != ctx)
140 n+= pctx->m_cursors.elements();
142 pctx= pctx->parent_context();
145 return (exclusive && last_ctx ? n - last_ctx->m_cursors.elements() :
n);
151 bool current_scope_only)
const
153 uint
i= m_vars.elements() - m_pboundary;
159 if (my_strnncoll(system_charset_info,
160 (
const uchar *)name.str, name.length,
161 (
const uchar *)p->
name.str, p->
name.length) == 0)
167 return (!current_scope_only && m_parent) ?
175 if (m_var_offset <= offset && offset < m_var_offset + m_vars.elements())
176 return m_vars.
at(offset - m_var_offset);
186 enum enum_field_types
type,
187 sp_variable::enum_mode
mode)
197 return m_vars.
append(p) ? NULL : p;
209 m_labels.push_front(label);
222 if (my_strcasecmp(system_charset_info, name.str, lab->
name.str) == 0)
235 m_parent->find_label(name) :
240 bool sp_pcontext::add_condition(THD *thd,
249 return m_conditions.
append(p);
254 bool current_scope_only)
const
256 uint
i= m_conditions.elements();
262 if (my_strnncoll(system_charset_info,
263 (
const uchar *) name.str, name.length,
264 (
const uchar *) p->
name.str, p->
name.length) == 0)
270 return (!current_scope_only && m_parent) ?
276 sp_handler *sp_pcontext::add_handler(THD *thd,
284 return m_handlers.
append(h) ? NULL : h;
291 for (
int i= 0;
i < m_handlers.elements(); ++
i)
300 if (cond_value->
equals(cv))
312 Sql_condition::enum_warning_level
level)
const
317 for (
int i= 0;
i < m_handlers.elements(); ++
i)
328 case sp_condition_value::ERROR_CODE:
331 found_cv->
type > sp_condition_value::ERROR_CODE))
338 case sp_condition_value::SQLSTATE:
339 if (strcmp(sql_state, cv->
sql_state) == 0 &&
341 found_cv->
type > sp_condition_value::SQLSTATE))
348 case sp_condition_value::WARNING:
349 if ((is_sqlstate_warning(sql_state) ||
350 level == Sql_condition::WARN_LEVEL_WARN) && !found_cv)
357 case sp_condition_value::NOT_FOUND:
358 if (is_sqlstate_not_found(sql_state) && !found_cv)
365 case sp_condition_value::EXCEPTION:
366 if (is_sqlstate_exception(sql_state) &&
367 level == Sql_condition::WARN_LEVEL_ERROR && !found_cv)
378 return found_handler;
412 if (!p || !p->m_parent)
415 return p->m_parent->
find_handler(sql_state, sql_errno, level);
421 if (m_cursors.elements() == (int) m_max_cursor_index)
422 ++m_max_cursor_index;
424 return m_cursors.
append(name);
430 bool current_scope_only)
const
432 uint
i= m_cursors.elements();
438 if (my_strnncoll(system_charset_info,
439 (
const uchar *) name.str, name.length,
440 (
const uchar *) n.str, n.length) == 0)
442 *poff= m_cursor_offset +
i;
447 return (!current_scope_only && m_parent) ?
458 for (
int i= 0;
i < m_vars.elements(); ++
i)
462 field_def_lst->push_back(&var_def->
field_def);
467 for (
int i= 0;
i < m_children.elements(); ++
i)
474 if (m_cursor_offset <= offset &&
475 offset < m_cursor_offset + m_cursors.elements())
477 return &m_cursors.
at(offset - m_cursor_offset);