diff options
author | unknown <anozdrin@mysql.com> | 2005-12-07 17:01:17 +0300 |
---|---|---|
committer | unknown <anozdrin@mysql.com> | 2005-12-07 17:01:17 +0300 |
commit | 6b2f13098a59d9ad520828dca4cb63da8c86b5e3 (patch) | |
tree | 82814a574624a8e813cc8dfad8c31d3fa4adf898 /sql/sp_rcontext.h | |
parent | 29eac312cda3bebddeb7f5ab7a2af6b81ea89205 (diff) | |
download | mariadb-git-6b2f13098a59d9ad520828dca4cb63da8c86b5e3.tar.gz |
Patch for WL#2894: Make stored routine variables work
according to the standard.
The idea is to use Field-classes to implement stored routines
variables. Also, we should provide facade to Item-hierarchy
by Item_field class (it is necessary, since SRVs take part
in expressions).
The patch fixes the following bugs:
- BUG#8702: Stored Procedures: No Error/Warning shown for inappropriate data
type matching;
- BUG#8768: Functions: For any unsigned data type, -ve values can be passed
and returned;
- BUG#8769: Functions: For Int datatypes, out of range values can be passed
and returned;
- BUG#9078: STORED PROCDURE: Decimal digits are not displayed when we use
DECIMAL datatype;
- BUG#9572: Stored procedures: variable type declarations ignored;
- BUG#12903: upper function does not work inside a function;
- BUG#13705: parameters to stored procedures are not verified;
- BUG#13808: ENUM type stored procedure parameter accepts non-enumerated
data;
- BUG#13909: Varchar Stored Procedure Parameter always BINARY string (ignores
CHARACTER SET);
- BUG#14161: Stored procedure cannot retrieve bigint unsigned;
- BUG#14188: BINARY variables have no 0x00 padding;
- BUG#15148: Stored procedure variables accept non-scalar values;
mysql-test/r/ctype_ujis.result:
Explicitly specify correct charset.
mysql-test/r/schema.result:
Drop our test database to not affect this test if some test
left it cause of failure.
mysql-test/r/show_check.result:
Drop our test database to not affect this test if some test
left it cause of failure.
mysql-test/r/skip_name_resolve.result:
Ignore columns with unpredictable values.
mysql-test/r/sp-big.result:
Add cleanup statement.
mysql-test/r/sp-dynamic.result:
Add cleanup statements.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sum_distinct-big.result:
Update result file.
mysql-test/r/type_newdecimal-big.result:
Update result file.
mysql-test/t/ctype_ujis.test:
Explicitly specify correct charset.
mysql-test/t/schema.test:
Drop our test database to not affect this test if some test
left it cause of failure.
mysql-test/t/show_check.test:
Drop our test database to not affect this test if some test
left it cause of failure.
mysql-test/t/skip_name_resolve.test:
Ignore columns with unpredictable values.
mysql-test/t/sp-big.test:
Add cleanup statement.
mysql-test/t/sp-dynamic.test:
Add cleanup statements.
mysql-test/t/sp.test:
Non-scalar values prohibited for assignment to SP-vars;
polishing.
mysql-test/t/type_newdecimal-big.test:
Update type specification so that the variables
can contain the large values used in the test.
sql/field.cc:
Extract create_field::init() to initialize an existing
instance of create_field from new_create_field().
sql/field.h:
Extract create_field::init() to initialize an existing
instance of create_field from new_create_field().
sql/item.cc:
- Introduce a new class: Item_sp_variable -- a base class
of stored-routine-variables classes;
- Introduce Item_case_expr -- an Item, which is used to access
to the expression of CASE statement;
sql/item.h:
- Introduce a new class: Item_sp_variable -- a base class
of stored-routine-variables classes;
- Introduce Item_case_expr -- an Item, which is used to access
to the expression of CASE statement;
sql/item_func.cc:
Pass the Field (instead of Item) for the return value of
a function to the function execution routine.
sql/item_func.h:
Pass the Field (instead of Item) for the return value of
a function to the function execution routine.
sql/mysql_priv.h:
Move create_virtual_tmp_table() out of sql_select.h.
sql/sp.cc:
Use create_result_field() instead of make_field().
sql/sp_head.cc:
- Add a function to map enum_field_types to Item::Type;
- Add sp_instr_push_case_expr instruction -- an instruction
to push CASE expression into the active running context;
- Add sp_instr_pop_case_expr instruction -- an instruction
to pop CASE expression from the active running context;
- Adapt the SP-execution code to using Fields instead of Items
for SP-vars;
- Use create_field structure for field description instead of
a set of members.
sql/sp_head.h:
- Add a function to map enum_field_types to Item::Type;
- Add sp_instr_push_case_expr instruction -- an instruction
to push CASE expression into the active running context;
- Add sp_instr_pop_case_expr instruction -- an instruction
to pop CASE expression from the active running context;
- Adapt the SP-execution code to using Fields instead of Items
for SP-vars;
- Use create_field structure for field description instead of
a set of members.
sql/sp_pcontext.cc:
- Change rules to assign an index of SP-variable: use
transparent index;
- Add an operation to retrieve a list of defined SP-vars
from the processing context recursively.
sql/sp_pcontext.h:
- Change rules to assign an index of SP-variable: use
transparent index;
- Add an operation to retrieve a list of defined SP-vars
from the processing context recursively.
sql/sp_rcontext.cc:
- Change rules to assign an index of SP-variable: use
transparent index;
- Use a tmp virtual table to store SP-vars instead of Items;
- Provide operations to work with CASE expresion.
sql/sp_rcontext.h:
- Change rules to assign an index of SP-variable: use
transparent index;
- Use a tmp virtual table to store SP-vars instead of Items;
- Provide operations to work with CASE expresion.
sql/sql_class.cc:
- Reflect Item_splocal ctor changes;
- Item_splocal::get_offset() has been renamed to get_var_idx().
sql/sql_class.h:
Polishing.
sql/sql_parse.cc:
Extract create_field::init() to initialize an existing
instance of create_field from new_create_field().
sql/sql_select.cc:
Take care of BLOB columns in create_virtual_tmp_table().
sql/sql_select.h:
Move create_virtual_tmp_table() out of sql_select.h.
sql/sql_trigger.cc:
Use boolean constants for boolean type instead of numerical ones.
sql/sql_yacc.yy:
Provide an instance of create_field for each SP-var.
mysql-test/include/sp-vars.inc:
The definitions of common-procedures, which are created
under different circumstances.
mysql-test/r/sp-vars.result:
Result file for the SP-vars test.
mysql-test/sp-vars.test:
A new test for checking SP-vars functionality.
Diffstat (limited to 'sql/sp_rcontext.h')
-rw-r--r-- | sql/sp_rcontext.h | 142 |
1 files changed, 77 insertions, 65 deletions
diff --git a/sql/sp_rcontext.h b/sql/sp_rcontext.h index d54188aa96f..c3c05228eef 100644 --- a/sql/sp_rcontext.h +++ b/sql/sp_rcontext.h @@ -43,12 +43,22 @@ typedef struct /* - This is a run context? of one SP ? - THis is - - a stack of cursors? - - a stack of handlers? - - a stack of Items ? - - a stack of instruction locations in SP? + This class is a runtime context of a Stored Routine. It is used in an + execution and is intended to contain all dynamic objects (i.e. objects, which + can be changed during execution), such as: + - stored routine variables; + - cursors; + - handlers; + + Runtime context is used with sp_head class. sp_head class is intended to + contain all static things, related to the stored routines (code, for example). + sp_head instance creates runtime context for the execution of a stored + routine. + + There is a parsing context (an instance of sp_pcontext class), which is used + on parsing stage. However, now it contains some necessary for an execution + things, such as definition of used stored routine variables. That's why + runtime context needs a reference to the parsing context. */ class sp_rcontext : public Sql_alloc @@ -68,62 +78,34 @@ class sp_rcontext : public Sql_alloc #ifndef DBUG_OFF /* - Routine to which this Item_splocal belongs. Used for checking if correct - runtime context is used for variable handling. + The routine for which this runtime context is created. Used for checking + if correct runtime context is used for variable handling. */ - sp_head *owner; + sp_head *sp; #endif - sp_rcontext(sp_rcontext *prev, uint fsize, uint hmax, uint cmax); + sp_rcontext(sp_pcontext *root_parsing_ctx, Field *return_value_fld, + sp_rcontext *prev_runtime_ctx); + bool init(THD *thd); - ~sp_rcontext() - { - // Not needed? - //sql_element_free(m_frame); - //m_saved.empty(); - } - - inline void - push_item(Item *i) - { - if (m_count < m_fsize) - m_frame[m_count++]= i; - } + ~sp_rcontext(); - inline void - set_item(uint idx, Item *i) - { - if (idx < m_count) - m_frame[idx]= i; - } - - /* Returns 0 on success, -1 on (eval) failure */ int - set_item_eval(THD *thd, uint idx, Item **i, enum_field_types type); - - inline Item * - get_item(uint idx) - { - return m_frame[idx]; - } + set_variable(THD *thd, uint var_idx, Item *value); - inline Item ** - get_item_addr(uint idx) - { - return m_frame + idx; - } + Item * + get_item(uint var_idx); + Item ** + get_item_addr(uint var_idx); - inline void - set_result(Item *it) - { - m_result= it; - } + bool + set_return_value(THD *thd, Item *return_value_item); - inline Item * - get_result() + inline bool + is_return_value_set() const { - return m_result; + return m_return_value_set; } inline void @@ -195,14 +177,6 @@ class sp_rcontext : public Sql_alloc m_ihsp-= 1; } - // Save variables starting at fp and up - void - save_variables(uint fp); - - // Restore variables down to fp - void - restore_variables(uint fp); - void push_cursor(sp_lex_keeper *lex_keeper, sp_instr_cpush *i); @@ -221,13 +195,42 @@ class sp_rcontext : public Sql_alloc return m_cstack[i]; } + /* + CASE expressions support. + */ + + int + set_case_expr(THD *thd, int case_expr_id, Item *case_expr_item); + + Item * + get_case_expr(int case_expr_id); + + Item ** + get_case_expr_addr(int case_expr_id); + private: + sp_pcontext *m_root_parsing_ctx; - uint m_count; - uint m_fsize; - Item **m_frame; + /* Virtual table for storing variables. */ + TABLE *m_var_table; - Item *m_result; // For FUNCTIONs + /* + Collection of Item_field proxies, each of them points to the corresponding + field in m_var_table. + */ + Item **m_var_items; + + /* + This is a pointer to a field, which should contain return value for stored + functions (only). For stored procedures, this pointer is NULL. + */ + Field *m_return_value_fld; + + /* + Indicates whether the return value (in m_return_value_fld) has been set + during execution. + */ + bool m_return_value_set; sp_handler_t *m_handler; // Visible handlers uint m_hcount; // Stack pointer for m_handler @@ -236,13 +239,22 @@ private: uint *m_in_handler; // Active handler, for recursion check uint m_ihsp; // Stack pointer for m_in_handler int m_hfound; // Set by find_handler; -1 if not found - List<Item> m_saved; // Saved variables during handler exec. sp_cursor **m_cstack; uint m_ccount; - sp_rcontext *m_prev_ctx; // Previous context (NULL if none) + Item_cache **m_case_expr_holders; + + /* Previous runtime context (NULL if none) */ + sp_rcontext *m_prev_runtime_ctx; + +private: + bool init_var_table(THD *thd); + bool init_var_items(); + + Item_cache *create_case_expr_holder(THD *thd, Item_result result_type); + int set_variable(THD *thd, Field *field, Item *value); }; // class sp_rcontext : public Sql_alloc |