summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2017-08-18 23:36:42 +0400
committerAlexander Barkov <bar@mariadb.org>2018-02-25 21:08:19 +0400
commit583eb96c2492adb87e88a014b24eb0724fb00257 (patch)
tree501cb4e5e3855400e79df8911ac43ef1f89300b3 /sql/item.cc
parent83ea839fb15dd5ed616d2b3152ccc5472ee5e5e6 (diff)
downloadmariadb-git-bb-10.3-compatibility.tar.gz
MDEV-11952 Oracle-style packages: stage#5mariadb-10.3.5bb-10.3-compatibility
- CREATE PACKAGE [BODY] statements are now entirely written to mysql.proc with type='PACKAGE' and type='PACKAGE BODY'. - CREATE PACKAGE BODY now supports IF NOT EXISTS - DROP PACKAGE BODY now supports IF EXISTS - CREATE OR REPLACE PACKAGE [BODY] is now supported - CREATE PACKAGE [BODY] now support the DEFINER clause: CREATE DEFINER user@host PACKAGE pkg ... END; CREATE DEFINER user@host PACKAGE BODY pkg ... END; - CREATE PACKAGE [BODY] now supports SQL SECURITY and COMMENT clauses, e.g.: CREATE PACKAGE p1 SQL SECURITY INVOKER COMMENT "comment" AS ... END; - Package routines are now created from the package CREATE PACKAGE BODY statement and don't produce individual records in mysql.proc. - CREATE PACKAGE BODY now supports package-wide variables. Package variables can be read and set inside package routines. Package variables are stored in a separate sp_rcontext, which is cached in THD on the first packate routine call. - CREATE PACKAGE BODY now supports the initialization section. - All public routines (i.e. declared in CREATE PACKAGE) must have implementations in CREATE PACKAGE BODY - Only public package routines are available outside of the package - {CREATE|DROP} PACKAGE [BODY] now respects CREATE ROUTINE and ALTER ROUTINE privileges - "GRANT EXECUTE ON PACKAGE BODY pkg" is now supported - SHOW CREATE PACKAGE [BODY] is now supported - SHOW PACKAGE [BODY] STATUS is now supported - CREATE and DROP for PACKAGE [BODY] now works for non-current databases - mysqldump now supports packages - "SHOW {PROCEDURE|FUNCTION) CODE pkg.routine" now works for package routines - "SHOW PACKAGE BODY CODE pkg" now works (the package initialization section) - A new package body level MDL was added - Recursive calls for package procedures are now possible - Routine forward declarations in CREATE PACKATE BODY are now supported. - Package body variables now work as SP OUT parameters - Package body variables now work as SELECT INTO targets - Package body variables now support ROW, %ROWTYPE, %TYPE
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc59
1 files changed, 41 insertions, 18 deletions
diff --git a/sql/item.cc b/sql/item.cc
index d3345f69a40..9f0280b678c 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1789,13 +1789,16 @@ void Item_sp_variable::make_field(THD *thd, Send_field *field)
Item_splocal methods
*****************************************************************************/
-Item_splocal::Item_splocal(THD *thd, const LEX_CSTRING *sp_var_name,
+Item_splocal::Item_splocal(THD *thd,
+ const Sp_rcontext_handler *rh,
+ const LEX_CSTRING *sp_var_name,
uint sp_var_idx,
const Type_handler *handler,
uint pos_in_q, uint len_in_q):
Item_sp_variable(thd, sp_var_name),
Rewritable_query_parameter(pos_in_q, len_in_q),
Type_handler_hybrid_field_type(handler),
+ m_rcontext_handler(rh),
m_var_idx(sp_var_idx)
{
maybe_null= TRUE;
@@ -1803,9 +1806,21 @@ Item_splocal::Item_splocal(THD *thd, const LEX_CSTRING *sp_var_name,
}
+sp_rcontext *Item_splocal::get_rcontext(sp_rcontext *local_ctx) const
+{
+ return m_rcontext_handler->get_rcontext(local_ctx);
+}
+
+
+Item_field *Item_splocal::get_variable(sp_rcontext *ctx) const
+{
+ return get_rcontext(ctx)->get_variable(m_var_idx);
+}
+
+
bool Item_splocal::fix_fields(THD *thd, Item **ref)
{
- Item_field *item= thd->spcont->get_variable(m_var_idx);
+ Item *item= get_variable(thd->spcont);
set_handler(item->type_handler());
return fix_fields_from_item(thd, ref, item);
}
@@ -1816,7 +1831,7 @@ Item_splocal::this_item()
{
DBUG_ASSERT(m_sp == m_thd->spcont->m_sp);
DBUG_ASSERT(fixed);
- return m_thd->spcont->get_variable(m_var_idx);
+ return get_variable(m_thd->spcont);
}
const Item *
@@ -1824,7 +1839,7 @@ Item_splocal::this_item() const
{
DBUG_ASSERT(m_sp == m_thd->spcont->m_sp);
DBUG_ASSERT(fixed);
- return m_thd->spcont->get_variable(m_var_idx);
+ return get_variable(m_thd->spcont);
}
@@ -1833,13 +1848,15 @@ Item_splocal::this_item_addr(THD *thd, Item **)
{
DBUG_ASSERT(m_sp == thd->spcont->m_sp);
DBUG_ASSERT(fixed);
- return thd->spcont->get_variable_addr(m_var_idx);
+ return get_rcontext(thd->spcont)->get_variable_addr(m_var_idx);
}
void Item_splocal::print(String *str, enum_query_type)
{
- str->reserve(m_name.length+8);
+ const LEX_CSTRING *prefix= m_rcontext_handler->get_name_prefix();
+ str->reserve(m_name.length + 8 + prefix->length);
+ str->append(prefix);
str->append(&m_name);
str->append('@');
str->qs_append(m_var_idx);
@@ -1848,7 +1865,7 @@ void Item_splocal::print(String *str, enum_query_type)
bool Item_splocal::set_value(THD *thd, sp_rcontext *ctx, Item **it)
{
- return ctx->set_variable(thd, get_var_idx(), it);
+ return get_rcontext(ctx)->set_variable(thd, get_var_idx(), it);
}
@@ -1930,7 +1947,7 @@ bool Item_splocal::check_cols(uint n)
bool Item_splocal_row_field::fix_fields(THD *thd, Item **ref)
{
- Item *item= thd->spcont->get_variable(m_var_idx)->element_index(m_field_idx);
+ Item *item= get_variable(thd->spcont)->element_index(m_field_idx);
return fix_fields_from_item(thd, ref, item);
}
@@ -1940,7 +1957,7 @@ Item_splocal_row_field::this_item()
{
DBUG_ASSERT(m_sp == m_thd->spcont->m_sp);
DBUG_ASSERT(fixed);
- return m_thd->spcont->get_variable(m_var_idx)->element_index(m_field_idx);
+ return get_variable(m_thd->spcont)->element_index(m_field_idx);
}
@@ -1949,7 +1966,7 @@ Item_splocal_row_field::this_item() const
{
DBUG_ASSERT(m_sp == m_thd->spcont->m_sp);
DBUG_ASSERT(fixed);
- return m_thd->spcont->get_variable(m_var_idx)->element_index(m_field_idx);
+ return get_variable(m_thd->spcont)->element_index(m_field_idx);
}
@@ -1958,13 +1975,15 @@ Item_splocal_row_field::this_item_addr(THD *thd, Item **)
{
DBUG_ASSERT(m_sp == thd->spcont->m_sp);
DBUG_ASSERT(fixed);
- return thd->spcont->get_variable(m_var_idx)->addr(m_field_idx);
+ return get_variable(thd->spcont)->addr(m_field_idx);
}
void Item_splocal_row_field::print(String *str, enum_query_type)
{
- str->reserve(m_name.length + m_field_name.length + 8);
+ const LEX_CSTRING *prefix= m_rcontext_handler->get_name_prefix();
+ str->reserve(m_name.length + m_field_name.length + 8 + prefix->length);
+ str->append(prefix);
str->append(&m_name);
str->append('.');
str->append(&m_field_name);
@@ -1978,18 +1997,19 @@ void Item_splocal_row_field::print(String *str, enum_query_type)
bool Item_splocal_row_field::set_value(THD *thd, sp_rcontext *ctx, Item **it)
{
- return ctx->set_variable_row_field(thd, m_var_idx, m_field_idx, it);
+ return get_rcontext(ctx)->set_variable_row_field(thd, m_var_idx, m_field_idx,
+ it);
}
bool Item_splocal_row_field_by_name::fix_fields(THD *thd, Item **it)
{
m_thd= thd;
- if (thd->spcont->find_row_field_by_name_or_error(&m_field_idx,
- m_var_idx,
- m_field_name))
+ if (get_rcontext(thd->spcont)->find_row_field_by_name_or_error(&m_field_idx,
+ m_var_idx,
+ m_field_name))
return true;
- Item *item= thd->spcont->get_variable(m_var_idx)->element_index(m_field_idx);
+ Item *item= get_variable(thd->spcont)->element_index(m_field_idx);
set_handler(item->type_handler());
return fix_fields_from_item(thd, it, item);
}
@@ -1997,9 +2017,12 @@ bool Item_splocal_row_field_by_name::fix_fields(THD *thd, Item **it)
void Item_splocal_row_field_by_name::print(String *str, enum_query_type)
{
+ const LEX_CSTRING *prefix= m_rcontext_handler->get_name_prefix();
// +16 should be enough for .NNN@[""]
- if (str->reserve(m_name.length + 2 * m_field_name.length + 16))
+ if (str->reserve(m_name.length + 2 * m_field_name.length +
+ prefix->length + 16))
return;
+ str->qs_append(prefix);
str->qs_append(&m_name);
str->qs_append('.');
str->qs_append(&m_field_name);