Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
/* -*- C++ -*- */
|
2011-06-30 17:46:53 +02:00
|
|
|
/* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2011-06-30 17:46:53 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
|
|
|
#ifndef _SP_PCONTEXT_H_
|
|
|
|
#define _SP_PCONTEXT_H_
|
|
|
|
|
2005-05-27 12:03:37 +02:00
|
|
|
#ifdef USE_PRAGMA_INTERFACE
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
#pragma interface /* gcc class implementation */
|
|
|
|
#endif
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_string.h" // LEX_STRING
|
|
|
|
#include "mysql_com.h" // enum_field_types
|
|
|
|
#include "field.h" // Create_field
|
2013-06-19 13:32:14 +02:00
|
|
|
#include "sql_array.h" // Dynamic_array
|
2010-03-31 16:05:33 +02:00
|
|
|
|
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// This class represents a stored program variable or a parameter
|
|
|
|
/// (also referenced as 'SP-variable').
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
class sp_variable : public Sql_alloc
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2013-06-19 13:32:14 +02:00
|
|
|
public:
|
|
|
|
enum enum_mode
|
|
|
|
{
|
|
|
|
MODE_IN,
|
|
|
|
MODE_OUT,
|
|
|
|
MODE_INOUT
|
|
|
|
};
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Name of the SP-variable.
|
|
|
|
LEX_STRING name;
|
2004-08-17 20:20:58 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Mode of the SP-variable.
|
|
|
|
enum_mode mode;
|
2006-01-16 15:22:29 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// The index to the variable's value in the runtime frame.
|
|
|
|
///
|
|
|
|
/// It is calculated during parsing and used when creating sp_instr_set
|
|
|
|
/// instructions and Item_splocal items. I.e. values are set/referred by
|
|
|
|
/// array indexing in runtime.
|
|
|
|
uint offset;
|
2002-12-11 14:24:29 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Default value of the SP-variable (if any).
|
|
|
|
Item *default_value;
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Full type information (field meta-data) of the SP-variable.
|
2016-12-06 06:05:52 +01:00
|
|
|
Spvar_definition field_def;
|
2005-02-28 18:07:06 +01:00
|
|
|
|
2015-11-26 12:04:55 +01:00
|
|
|
/// Field-type of the SP-variable.
|
|
|
|
enum_field_types sql_type() const { return field_def.sql_type; }
|
2013-06-19 13:32:14 +02:00
|
|
|
public:
|
2014-11-08 17:37:19 +01:00
|
|
|
sp_variable(LEX_STRING _name, uint _offset)
|
2013-06-19 13:32:14 +02:00
|
|
|
:Sql_alloc(),
|
|
|
|
name(_name),
|
2014-11-08 17:37:19 +01:00
|
|
|
mode(MODE_IN),
|
2013-06-19 13:32:14 +02:00
|
|
|
offset(_offset),
|
|
|
|
default_value(NULL)
|
|
|
|
{ }
|
2017-02-02 19:59:07 +01:00
|
|
|
/*
|
|
|
|
Find a ROW field by its qualified name.
|
|
|
|
@param var_name - the name of the variable
|
|
|
|
@param field_name - the name of the variable field
|
|
|
|
@param[OUT] row_field_offset - the index of the field
|
|
|
|
|
|
|
|
@retval NULL if the variable with the given name was not found,
|
|
|
|
or it is not a row variable, or it does not have a field
|
|
|
|
with the given name, or a non-null pointer otherwise.
|
|
|
|
row_field_offset[0] is set only when the method returns !NULL.
|
|
|
|
*/
|
|
|
|
const Spvar_definition *find_row_field(const LEX_STRING &var_name,
|
|
|
|
const LEX_STRING &field_name,
|
|
|
|
uint *row_field_offset);
|
Bug#26503 (Illegal SQL exception handler code causes the server to crash)
Before this fix, the parser would accept illegal code in SQL exceptions
handlers, that later causes the runtime to crash when executing the code,
due to memory violations in the exception handler stack.
The root cause of the problem is instructions within an exception handler
that jumps to code located outside of the handler. This is illegal according
to the SQL 2003 standard, since labels located outside the handler are not
supposed to be visible (they are "out of scope"), so any instruction that
jumps to these labels, like ITERATE or LEAVE, should not parse.
The section of the standard that is relevant for this is :
SQL:2003 SQL/PSM (ISO/IEC 9075-4:2003)
section 13.1 <compound statement>,
syntax rule 4
<quote>
The scope of the <beginning label> is CS excluding every <SQL schema
statement> contained in CS and excluding every
<local handler declaration list> contained in CS. <beginning label> shall
not be equivalent to any other <beginning label>s within that scope.
</quote>
With this fix, the C++ class sp_pcontext, which represent the "parsing
context" tree (a.k.a symbol table) of a stored procedure, has been changed
as follows:
- constructors have been cleaned up, so that only building a root node for
the tree is public; building nodes inside a tree is not public.
- a new member, m_label_scope, indicates if a given syntactic context
belongs to a DECLARE HANDLER block,
- label resolution, in the method find_label(), has been changed to
implement the restriction of scope regarding labels used in a compound
statement.
The actions in the parser, when parsing the body of a SQL exception handler,
have been changed as follows:
- the implementation of an exception handler (DECLARE HANDLER) now creates
explicitly a new sp_pcontext, to isolate the code inside the handler from
the containing compound statement context.
- registering exception handlers as a result occurs in the parent context,
see the rule sp_hcond_element
- the code in sp_hcond_list has been cleaned up, to avoid code duplication
In addition, the flags IN_SIMPLE_CASE and IN_HANDLER, declared in sp_head.h
have been removed, since they are unused and broken by design (as seen with
Bug 19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation), representing a stack in a single flag is not possible.
Tests in sp-error have been added to show that illegal constructs are now
rejected.
Tests in sp have been added for code coverage, to show that ITERATE or LEAVE
statements are legal when jumping to a label in scope, inside the body of
an exception handler.
mysql-test/r/sp-error.result:
SQL Exception handlers define a parsing context for label resolution.
mysql-test/r/sp.result:
SQL Exception handlers define a parsing context for label resolution.
mysql-test/t/sp-error.test:
SQL Exception handlers define a parsing context for label resolution.
mysql-test/t/sp.test:
SQL Exception handlers define a parsing context for label resolution.
sql/sp_head.cc:
Minor cleanup
sql/sp_head.h:
Minor cleanup
sql/sp_pcontext.cc:
SQL Exception handlers define a parsing context for label resolution.
sql/sp_pcontext.h:
SQL Exception handlers define a parsing context for label resolution.
sql/sql_yacc.yy:
SQL Exception handlers define a parsing context for label resolution.
2007-03-14 19:02:32 +01:00
|
|
|
};
|
2005-08-25 15:34:34 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2005-08-25 15:34:34 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// This class represents an SQL/PSM label. Can refer to the identifier
|
|
|
|
/// used with the "label_name:" construct which may precede some SQL/PSM
|
|
|
|
/// statements, or to an implicit implementation-dependent identifier which
|
|
|
|
/// the parser inserts before a high-level flow control statement such as
|
|
|
|
/// IF/WHILE/REPEAT/LOOP, when such statement is rewritten into a
|
|
|
|
/// combination of low-level jump/jump_if instructions and labels.
|
|
|
|
|
|
|
|
class sp_label : public Sql_alloc
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
{
|
Bug#26503 (Illegal SQL exception handler code causes the server to crash)
Before this fix, the parser would accept illegal code in SQL exceptions
handlers, that later causes the runtime to crash when executing the code,
due to memory violations in the exception handler stack.
The root cause of the problem is instructions within an exception handler
that jumps to code located outside of the handler. This is illegal according
to the SQL 2003 standard, since labels located outside the handler are not
supposed to be visible (they are "out of scope"), so any instruction that
jumps to these labels, like ITERATE or LEAVE, should not parse.
The section of the standard that is relevant for this is :
SQL:2003 SQL/PSM (ISO/IEC 9075-4:2003)
section 13.1 <compound statement>,
syntax rule 4
<quote>
The scope of the <beginning label> is CS excluding every <SQL schema
statement> contained in CS and excluding every
<local handler declaration list> contained in CS. <beginning label> shall
not be equivalent to any other <beginning label>s within that scope.
</quote>
With this fix, the C++ class sp_pcontext, which represent the "parsing
context" tree (a.k.a symbol table) of a stored procedure, has been changed
as follows:
- constructors have been cleaned up, so that only building a root node for
the tree is public; building nodes inside a tree is not public.
- a new member, m_label_scope, indicates if a given syntactic context
belongs to a DECLARE HANDLER block,
- label resolution, in the method find_label(), has been changed to
implement the restriction of scope regarding labels used in a compound
statement.
The actions in the parser, when parsing the body of a SQL exception handler,
have been changed as follows:
- the implementation of an exception handler (DECLARE HANDLER) now creates
explicitly a new sp_pcontext, to isolate the code inside the handler from
the containing compound statement context.
- registering exception handlers as a result occurs in the parent context,
see the rule sp_hcond_element
- the code in sp_hcond_list has been cleaned up, to avoid code duplication
In addition, the flags IN_SIMPLE_CASE and IN_HANDLER, declared in sp_head.h
have been removed, since they are unused and broken by design (as seen with
Bug 19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation), representing a stack in a single flag is not possible.
Tests in sp-error have been added to show that illegal constructs are now
rejected.
Tests in sp have been added for code coverage, to show that ITERATE or LEAVE
statements are legal when jumping to a label in scope, inside the body of
an exception handler.
mysql-test/r/sp-error.result:
SQL Exception handlers define a parsing context for label resolution.
mysql-test/r/sp.result:
SQL Exception handlers define a parsing context for label resolution.
mysql-test/t/sp-error.test:
SQL Exception handlers define a parsing context for label resolution.
mysql-test/t/sp.test:
SQL Exception handlers define a parsing context for label resolution.
sql/sp_head.cc:
Minor cleanup
sql/sp_head.h:
Minor cleanup
sql/sp_pcontext.cc:
SQL Exception handlers define a parsing context for label resolution.
sql/sp_pcontext.h:
SQL Exception handlers define a parsing context for label resolution.
sql/sql_yacc.yy:
SQL Exception handlers define a parsing context for label resolution.
2007-03-14 19:02:32 +01:00
|
|
|
public:
|
2013-06-19 13:32:14 +02:00
|
|
|
enum enum_type
|
2004-08-17 20:20:58 +02:00
|
|
|
{
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Implicit label generated by parser.
|
|
|
|
IMPLICIT,
|
2004-08-17 20:20:58 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Label at BEGIN.
|
|
|
|
BEGIN,
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Label at iteration control
|
|
|
|
ITERATION
|
|
|
|
};
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Name of the label.
|
|
|
|
LEX_STRING name;
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Instruction pointer of the label.
|
|
|
|
uint ip;
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Type of the label.
|
|
|
|
enum_type type;
|
2003-04-02 20:42:28 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Scope of the label.
|
|
|
|
class sp_pcontext *ctx;
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
public:
|
2016-08-09 12:58:20 +02:00
|
|
|
sp_label(const LEX_STRING _name,
|
|
|
|
uint _ip, enum_type _type, sp_pcontext *_ctx)
|
2013-06-19 13:32:14 +02:00
|
|
|
:Sql_alloc(),
|
|
|
|
name(_name),
|
|
|
|
ip(_ip),
|
|
|
|
type(_type),
|
|
|
|
ctx(_ctx)
|
|
|
|
{ }
|
|
|
|
};
|
2004-04-06 15:48:58 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/// This class represents condition-value term in DECLARE CONDITION or
|
|
|
|
/// DECLARE HANDLER statements. sp_condition_value has little to do with
|
|
|
|
/// SQL-conditions.
|
|
|
|
///
|
|
|
|
/// In some sense, this class is a union -- a set of filled attributes
|
|
|
|
/// depends on the sp_condition_value::type value.
|
2004-04-06 15:48:58 +02:00
|
|
|
|
2016-10-12 16:16:38 +02:00
|
|
|
class sp_condition_value : public Sql_alloc, public Sql_state_errno
|
2013-06-19 13:32:14 +02:00
|
|
|
{
|
2016-10-14 14:52:33 +02:00
|
|
|
bool m_is_user_defined;
|
2013-06-19 13:32:14 +02:00
|
|
|
public:
|
|
|
|
enum enum_type
|
2005-11-01 14:58:52 +01:00
|
|
|
{
|
2013-06-19 13:32:14 +02:00
|
|
|
ERROR_CODE,
|
|
|
|
SQLSTATE,
|
|
|
|
WARNING,
|
|
|
|
NOT_FOUND,
|
|
|
|
EXCEPTION
|
|
|
|
};
|
2005-11-01 14:58:52 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Type of the condition value.
|
|
|
|
enum_type type;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
public:
|
|
|
|
sp_condition_value(uint _mysqlerr)
|
|
|
|
:Sql_alloc(),
|
2016-10-12 16:16:38 +02:00
|
|
|
Sql_state_errno(_mysqlerr),
|
2016-10-14 14:52:33 +02:00
|
|
|
m_is_user_defined(false),
|
2016-10-12 16:16:38 +02:00
|
|
|
type(ERROR_CODE)
|
|
|
|
{ }
|
2016-09-27 11:22:38 +02:00
|
|
|
|
|
|
|
sp_condition_value(uint _mysqlerr, const char *_sql_state)
|
|
|
|
:Sql_alloc(),
|
2016-10-12 16:16:38 +02:00
|
|
|
Sql_state_errno(_mysqlerr, _sql_state),
|
2016-10-14 14:52:33 +02:00
|
|
|
m_is_user_defined(false),
|
2016-10-12 16:16:38 +02:00
|
|
|
type(ERROR_CODE)
|
|
|
|
{ }
|
2013-06-19 13:32:14 +02:00
|
|
|
|
2016-10-14 14:52:33 +02:00
|
|
|
sp_condition_value(const char *_sql_state, bool is_user_defined= false)
|
2013-06-19 13:32:14 +02:00
|
|
|
:Sql_alloc(),
|
2016-10-12 16:16:38 +02:00
|
|
|
Sql_state_errno(0, _sql_state),
|
2016-10-14 14:52:33 +02:00
|
|
|
m_is_user_defined(is_user_defined),
|
2016-10-12 16:16:38 +02:00
|
|
|
type(SQLSTATE)
|
|
|
|
{ }
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
sp_condition_value(enum_type _type)
|
|
|
|
:Sql_alloc(),
|
2016-10-14 14:52:33 +02:00
|
|
|
m_is_user_defined(false),
|
2016-10-12 16:16:38 +02:00
|
|
|
type(_type)
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
2013-06-19 13:32:14 +02:00
|
|
|
DBUG_ASSERT(type != ERROR_CODE && type != SQLSTATE);
|
2005-12-07 15:01:17 +01:00
|
|
|
}
|
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Check if two instances of sp_condition_value are equal or not.
|
|
|
|
///
|
|
|
|
/// @param cv another instance of sp_condition_value to check.
|
|
|
|
///
|
|
|
|
/// @return true if the instances are equal, false otherwise.
|
|
|
|
bool equals(const sp_condition_value *cv) const;
|
2016-10-14 14:52:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Checks if this condition is OK for search.
|
|
|
|
See also sp_context::find_handler().
|
|
|
|
|
|
|
|
@param identity - The condition identity
|
|
|
|
@param found_cv - A previously found matching condition or NULL.
|
|
|
|
@return true - If the current value matches identity and
|
|
|
|
makes a stronger match than the previously
|
|
|
|
found condition found_cv.
|
|
|
|
@return false - If the current value does not match identity,
|
|
|
|
of the current value makes a weaker match than found_cv.
|
|
|
|
*/
|
|
|
|
bool matches(const Sql_condition_identity &identity,
|
|
|
|
const sp_condition_value *found_cv) const;
|
|
|
|
|
|
|
|
Sql_user_condition_identity get_user_condition_identity() const
|
|
|
|
{
|
|
|
|
return Sql_user_condition_identity(m_is_user_defined ? this : NULL);
|
|
|
|
}
|
2013-06-19 13:32:14 +02:00
|
|
|
};
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2016-10-14 14:52:33 +02:00
|
|
|
|
|
|
|
class sp_condition_value_user_defined: public sp_condition_value
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
sp_condition_value_user_defined()
|
|
|
|
:sp_condition_value("45000", true)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// This class represents 'DECLARE CONDITION' statement.
|
|
|
|
/// sp_condition has little to do with SQL-conditions.
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
class sp_condition : public Sql_alloc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Name of the condition.
|
|
|
|
LEX_STRING name;
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Value of the condition.
|
|
|
|
sp_condition_value *value;
|
2002-12-11 14:24:29 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
public:
|
2016-08-09 10:08:11 +02:00
|
|
|
sp_condition(const LEX_STRING _name, sp_condition_value *_value)
|
2013-06-19 13:32:14 +02:00
|
|
|
:Sql_alloc(),
|
|
|
|
name(_name),
|
|
|
|
value(_value)
|
|
|
|
{ }
|
2016-09-20 13:30:15 +02:00
|
|
|
sp_condition(const char *name_arg, size_t name_length_arg,
|
|
|
|
sp_condition_value *value_arg)
|
|
|
|
:value(value_arg)
|
|
|
|
{
|
|
|
|
name.str= (char *) name_arg;
|
|
|
|
name.length= name_length_arg;
|
|
|
|
}
|
|
|
|
bool eq_name(const LEX_STRING str) const
|
|
|
|
{
|
|
|
|
return my_strnncoll(system_charset_info,
|
|
|
|
(const uchar *) name.str, name.length,
|
|
|
|
(const uchar *) str.str, str.length) == 0;
|
|
|
|
}
|
2013-06-19 13:32:14 +02:00
|
|
|
};
|
2002-12-11 14:24:29 +01:00
|
|
|
|
2016-10-21 09:51:49 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
class sp_pcursor.
|
|
|
|
Stores information about a cursor:
|
|
|
|
- Cursor's name in LEX_STRING.
|
|
|
|
- Cursor's formal parameter descriptions.
|
|
|
|
|
|
|
|
Formal parameter descriptions reside in a separate context block,
|
|
|
|
pointed by the "m_param_context" member.
|
|
|
|
|
|
|
|
m_param_context can be NULL. This means a cursor with no parameters.
|
|
|
|
Otherwise, the number of variables in m_param_context means
|
|
|
|
the number of cursor's formal parameters.
|
|
|
|
|
|
|
|
Note, m_param_context can be not NULL, but have no variables.
|
|
|
|
This is also means a cursor with no parameters (similar to NULL).
|
|
|
|
*/
|
|
|
|
class sp_pcursor: public LEX_STRING
|
|
|
|
{
|
|
|
|
class sp_pcontext *m_param_context; // Formal parameters
|
|
|
|
public:
|
|
|
|
sp_pcursor(const LEX_STRING &name, class sp_pcontext *param_ctx)
|
|
|
|
:LEX_STRING(name), m_param_context(param_ctx)
|
|
|
|
{ }
|
|
|
|
class sp_pcontext *param_context() const { return m_param_context; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2004-08-26 12:54:30 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// This class represents 'DECLARE HANDLER' statement.
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
class sp_handler : public Sql_alloc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Enumeration of possible handler types.
|
|
|
|
/// Note: UNDO handlers are not (and have never been) supported.
|
|
|
|
enum enum_type
|
2002-12-11 14:24:29 +01:00
|
|
|
{
|
2013-06-19 13:32:14 +02:00
|
|
|
EXIT,
|
|
|
|
CONTINUE
|
|
|
|
};
|
2002-12-11 14:24:29 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Handler type.
|
|
|
|
enum_type type;
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Conditions caught by this handler.
|
|
|
|
List<sp_condition_value> condition_values;
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
public:
|
|
|
|
/// The constructor.
|
|
|
|
///
|
|
|
|
/// @param _type SQL-handler type.
|
|
|
|
sp_handler(enum_type _type)
|
|
|
|
:Sql_alloc(),
|
|
|
|
type(_type)
|
|
|
|
{ }
|
|
|
|
};
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/// The class represents parse-time context, which keeps track of declared
|
|
|
|
/// variables/parameters, conditions, handlers, cursors and labels.
|
|
|
|
///
|
2013-06-20 13:49:25 +02:00
|
|
|
/// sp_pcontext objects are organized in a tree according to the following
|
2013-06-19 13:32:14 +02:00
|
|
|
/// rules:
|
|
|
|
/// - one sp_pcontext object corresponds for for each BEGIN..END block;
|
|
|
|
/// - one sp_pcontext object corresponds for each exception handler;
|
|
|
|
/// - one additional sp_pcontext object is created to contain
|
|
|
|
/// Stored Program parameters.
|
|
|
|
///
|
|
|
|
/// sp_pcontext objects are used both at parse-time and at runtime.
|
|
|
|
///
|
|
|
|
/// During the parsing stage sp_pcontext objects are used:
|
|
|
|
/// - to look up defined names (e.g. declared variables and visible
|
|
|
|
/// labels);
|
|
|
|
/// - to check for duplicates;
|
|
|
|
/// - for error checking;
|
|
|
|
/// - to calculate offsets to be used at runtime.
|
|
|
|
///
|
|
|
|
/// During the runtime phase, a tree of sp_pcontext objects is used:
|
|
|
|
/// - for error checking (e.g. to check correct number of parameters);
|
|
|
|
/// - to resolve SQL-handlers.
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
class sp_pcontext : public Sql_alloc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum enum_scope
|
2005-04-08 19:58:04 +02:00
|
|
|
{
|
2013-06-19 13:32:14 +02:00
|
|
|
/// REGULAR_SCOPE designates regular BEGIN ... END blocks.
|
|
|
|
REGULAR_SCOPE,
|
2005-04-08 19:58:04 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// HANDLER_SCOPE designates SQL-handler blocks.
|
|
|
|
HANDLER_SCOPE
|
|
|
|
};
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2016-08-24 10:30:27 +02:00
|
|
|
class Lex_for_loop: public Lex_for_loop_st
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Lex_for_loop() { init(); }
|
|
|
|
};
|
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
public:
|
|
|
|
sp_pcontext();
|
|
|
|
~sp_pcontext();
|
|
|
|
|
|
|
|
|
|
|
|
/// Create and push a new context in the tree.
|
|
|
|
|
|
|
|
/// @param thd thread context.
|
|
|
|
/// @param scope scope of the new parsing context.
|
|
|
|
/// @return the node created.
|
|
|
|
sp_pcontext *push_context(THD *thd, enum_scope scope);
|
|
|
|
|
|
|
|
/// Pop a node from the parsing context tree.
|
|
|
|
/// @return the parent node.
|
|
|
|
sp_pcontext *pop_context();
|
|
|
|
|
|
|
|
sp_pcontext *parent_context() const
|
|
|
|
{ return m_parent; }
|
|
|
|
|
|
|
|
/// Calculate and return the number of handlers to pop between the given
|
|
|
|
/// context and this one.
|
|
|
|
///
|
|
|
|
/// @param ctx the other parsing context.
|
|
|
|
/// @param exclusive specifies if the last scope should be excluded.
|
|
|
|
///
|
|
|
|
/// @return the number of handlers to pop between the given context and
|
|
|
|
/// this one. If 'exclusive' is true, don't count the last scope we are
|
|
|
|
/// leaving; this is used for LEAVE where we will jump to the hpop
|
|
|
|
/// instructions.
|
|
|
|
uint diff_handlers(const sp_pcontext *ctx, bool exclusive) const;
|
|
|
|
|
|
|
|
/// Calculate and return the number of cursors to pop between the given
|
|
|
|
/// context and this one.
|
|
|
|
///
|
|
|
|
/// @param ctx the other parsing context.
|
|
|
|
/// @param exclusive specifies if the last scope should be excluded.
|
|
|
|
///
|
|
|
|
/// @return the number of cursors to pop between the given context and
|
|
|
|
/// this one. If 'exclusive' is true, don't count the last scope we are
|
|
|
|
/// leaving; this is used for LEAVE where we will jump to the cpop
|
|
|
|
/// instructions.
|
|
|
|
uint diff_cursors(const sp_pcontext *ctx, bool exclusive) const;
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// SP-variables (parameters and variables).
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/// @return the maximum number of variables used in this and all child
|
|
|
|
/// contexts. For the root parsing context, this gives us the number of
|
|
|
|
/// slots needed for variables during the runtime phase.
|
|
|
|
uint max_var_index() const
|
|
|
|
{ return m_max_var_index; }
|
|
|
|
|
|
|
|
/// @return the current number of variables used in the parent contexts
|
|
|
|
/// (from the root), including this context.
|
|
|
|
uint current_var_count() const
|
|
|
|
{ return m_var_offset + m_vars.elements(); }
|
|
|
|
|
|
|
|
/// @return the number of variables in this context alone.
|
|
|
|
uint context_var_count() const
|
|
|
|
{ return m_vars.elements(); }
|
|
|
|
|
2016-10-21 09:51:49 +02:00
|
|
|
/// return the i-th variable on the current context
|
|
|
|
sp_variable *find_context_variable(uint i) const
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(i < m_vars.elements());
|
|
|
|
return m_vars.at(i);
|
|
|
|
}
|
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// @return map index in this parsing context to runtime offset.
|
|
|
|
uint var_context2runtime(uint i) const
|
|
|
|
{ return m_var_offset + i; }
|
|
|
|
|
|
|
|
/// Add SP-variable to the parsing context.
|
|
|
|
///
|
|
|
|
/// @param thd Thread context.
|
|
|
|
/// @param name Name of the SP-variable.
|
|
|
|
///
|
|
|
|
/// @return instance of newly added SP-variable.
|
2014-11-08 17:37:19 +01:00
|
|
|
sp_variable *add_variable(THD *thd, LEX_STRING name);
|
2013-06-19 13:32:14 +02:00
|
|
|
|
|
|
|
/// Retrieve full type information about SP-variables in this parsing
|
|
|
|
/// context and its children.
|
|
|
|
///
|
|
|
|
/// @param field_def_lst[out] Container to store type information.
|
2016-12-06 06:05:52 +01:00
|
|
|
void retrieve_field_definitions(List<Spvar_definition> *field_def_lst) const;
|
2013-06-19 13:32:14 +02:00
|
|
|
|
|
|
|
/// Find SP-variable by name.
|
|
|
|
///
|
|
|
|
/// The function does a linear search (from newer to older variables,
|
|
|
|
/// in case we have shadowed names).
|
|
|
|
///
|
|
|
|
/// The function is called only at parsing time.
|
|
|
|
///
|
|
|
|
/// @param name Variable name.
|
|
|
|
/// @param current_scope_only A flag if we search only in current scope.
|
|
|
|
///
|
|
|
|
/// @return instance of found SP-variable, or NULL if not found.
|
|
|
|
sp_variable *find_variable(LEX_STRING name, bool current_scope_only) const;
|
|
|
|
|
|
|
|
/// Find SP-variable by the offset in the root parsing context.
|
|
|
|
///
|
|
|
|
/// The function is used for two things:
|
|
|
|
/// - When evaluating parameters at the beginning, and setting out parameters
|
|
|
|
/// at the end, of invocation. (Top frame only, so no recursion then.)
|
|
|
|
/// - For printing of sp_instr_set. (Debug mode only.)
|
|
|
|
///
|
|
|
|
/// @param offset Variable offset in the root parsing context.
|
|
|
|
///
|
|
|
|
/// @return instance of found SP-variable, or NULL if not found.
|
|
|
|
sp_variable *find_variable(uint offset) const;
|
|
|
|
|
|
|
|
/// Set the current scope boundary (for default values).
|
|
|
|
///
|
|
|
|
/// @param n The number of variables to skip.
|
|
|
|
void declare_var_boundary(uint n)
|
|
|
|
{ m_pboundary= n; }
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// CASE expressions.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int register_case_expr()
|
|
|
|
{ return m_num_case_exprs++; }
|
|
|
|
|
|
|
|
int get_num_case_exprs() const
|
|
|
|
{ return m_num_case_exprs; }
|
|
|
|
|
|
|
|
bool push_case_expr_id(int case_expr_id)
|
|
|
|
{ return m_case_expr_ids.append(case_expr_id); }
|
|
|
|
|
|
|
|
void pop_case_expr_id()
|
|
|
|
{ m_case_expr_ids.pop(); }
|
|
|
|
|
|
|
|
int get_current_case_expr_id() const
|
|
|
|
{ return *m_case_expr_ids.back(); }
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// Labels.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-17 08:33:31 +02:00
|
|
|
sp_label *push_label(THD *thd, const LEX_STRING name, uint ip,
|
|
|
|
sp_label::enum_type type);
|
|
|
|
|
|
|
|
sp_label *push_label(THD *thd, const LEX_STRING name, uint ip)
|
|
|
|
{
|
|
|
|
return push_label(thd, name, ip, sp_label::IMPLICIT);
|
|
|
|
}
|
2013-06-19 13:32:14 +02:00
|
|
|
|
2016-08-09 12:58:20 +02:00
|
|
|
sp_label *find_label(const LEX_STRING name);
|
2013-06-19 13:32:14 +02:00
|
|
|
|
2016-08-17 08:33:31 +02:00
|
|
|
sp_label *find_label_current_loop_start();
|
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
sp_label *last_label()
|
2004-08-17 20:20:58 +02:00
|
|
|
{
|
2013-06-19 13:32:14 +02:00
|
|
|
sp_label *label= m_labels.head();
|
2003-10-10 16:57:21 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
if (!label && m_parent)
|
|
|
|
label= m_parent->last_label();
|
2003-10-10 16:57:21 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
return label;
|
2003-10-10 16:57:21 +02:00
|
|
|
}
|
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
sp_label *pop_label()
|
|
|
|
{ return m_labels.pop(); }
|
|
|
|
|
2016-08-09 12:58:20 +02:00
|
|
|
bool block_label_declare(LEX_STRING label)
|
|
|
|
{
|
|
|
|
sp_label *lab= find_label(label);
|
|
|
|
if (lab)
|
|
|
|
{
|
|
|
|
my_error(ER_SP_LABEL_REDEFINE, MYF(0), label.str);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// Conditions.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-09 10:08:11 +02:00
|
|
|
bool add_condition(THD *thd, const LEX_STRING name,
|
|
|
|
sp_condition_value *value);
|
2013-06-19 13:32:14 +02:00
|
|
|
|
|
|
|
/// See comment for find_variable() above.
|
2016-08-09 10:08:11 +02:00
|
|
|
sp_condition_value *find_condition(const LEX_STRING name,
|
2013-06-19 13:32:14 +02:00
|
|
|
bool current_scope_only) const;
|
2016-09-20 13:30:15 +02:00
|
|
|
|
|
|
|
sp_condition_value *
|
|
|
|
find_declared_or_predefined_condition(const LEX_STRING name) const
|
|
|
|
{
|
|
|
|
sp_condition_value *p= find_condition(name, false);
|
|
|
|
if (p)
|
|
|
|
return p;
|
|
|
|
return find_predefined_condition(name);
|
|
|
|
}
|
|
|
|
|
2016-08-09 10:08:11 +02:00
|
|
|
bool declare_condition(THD *thd, const LEX_STRING name,
|
|
|
|
sp_condition_value *val)
|
|
|
|
{
|
|
|
|
if (find_condition(name, true))
|
|
|
|
{
|
|
|
|
my_error(ER_SP_DUP_COND, MYF(0), name.str);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return add_condition(thd, name, val);
|
|
|
|
}
|
2013-06-19 13:32:14 +02:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// Handlers.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
sp_handler *add_handler(THD* thd, sp_handler::enum_type type);
|
|
|
|
|
|
|
|
/// This is an auxilary parsing-time function to check if an SQL-handler
|
|
|
|
/// exists in the current parsing context (current scope) for the given
|
|
|
|
/// SQL-condition. This function is used to check for duplicates during
|
|
|
|
/// the parsing phase.
|
|
|
|
///
|
|
|
|
/// This function can not be used during the runtime phase to check
|
|
|
|
/// SQL-handler existence because it searches for the SQL-handler in the
|
|
|
|
/// current scope only (during runtime, current and parent scopes
|
|
|
|
/// should be checked according to the SQL-handler resolution rules).
|
|
|
|
///
|
|
|
|
/// @param condition_value the handler condition value
|
|
|
|
/// (not SQL-condition!).
|
|
|
|
///
|
|
|
|
/// @retval true if such SQL-handler exists.
|
|
|
|
/// @retval false otherwise.
|
|
|
|
bool check_duplicate_handler(const sp_condition_value *cond_value) const;
|
|
|
|
|
|
|
|
/// Find an SQL handler for the given SQL condition according to the
|
|
|
|
/// SQL-handler resolution rules. This function is used at runtime.
|
|
|
|
///
|
2016-10-12 16:16:38 +02:00
|
|
|
/// @param value The error code and the SQL state
|
2013-06-19 13:32:14 +02:00
|
|
|
/// @param level The SQL condition level
|
|
|
|
///
|
|
|
|
/// @return a pointer to the found SQL-handler or NULL.
|
2016-10-14 14:52:33 +02:00
|
|
|
sp_handler *find_handler(const Sql_condition_identity &identity) const;
|
2013-06-19 13:32:14 +02:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// Cursors.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-21 09:51:49 +02:00
|
|
|
bool add_cursor(const LEX_STRING name, sp_pcontext *param_ctx);
|
2013-06-19 13:32:14 +02:00
|
|
|
|
|
|
|
/// See comment for find_variable() above.
|
2016-10-21 09:51:49 +02:00
|
|
|
const sp_pcursor *find_cursor(const LEX_STRING name,
|
|
|
|
uint *poff, bool current_scope_only) const;
|
2013-06-19 13:32:14 +02:00
|
|
|
|
2016-10-21 09:51:49 +02:00
|
|
|
/// Find cursor by offset (for SHOW {PROCEDURE|FUNCTION} CODE only).
|
|
|
|
const sp_pcursor *find_cursor(uint offset) const;
|
2013-06-19 13:32:14 +02:00
|
|
|
|
|
|
|
uint max_cursor_index() const
|
|
|
|
{ return m_max_cursor_index + m_cursors.elements(); }
|
|
|
|
|
|
|
|
uint current_cursor_count() const
|
|
|
|
{ return m_cursor_offset + m_cursors.elements(); }
|
2004-08-17 20:20:58 +02:00
|
|
|
|
2016-08-24 10:30:27 +02:00
|
|
|
void set_for_loop(const Lex_for_loop_st &for_loop)
|
|
|
|
{
|
|
|
|
m_for_loop.init(for_loop);
|
|
|
|
}
|
|
|
|
const Lex_for_loop_st &for_loop()
|
|
|
|
{
|
|
|
|
return m_for_loop;
|
|
|
|
}
|
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
private:
|
|
|
|
/// Constructor for a tree node.
|
|
|
|
/// @param prev the parent parsing context
|
|
|
|
/// @param scope scope of this parsing context
|
|
|
|
sp_pcontext(sp_pcontext *prev, enum_scope scope);
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
void init(uint var_offset, uint cursor_offset, int num_case_expressions);
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/* Prevent use of these */
|
|
|
|
sp_pcontext(const sp_pcontext &);
|
|
|
|
void operator=(sp_pcontext &);
|
2004-08-17 20:20:58 +02:00
|
|
|
|
2016-09-20 13:30:15 +02:00
|
|
|
sp_condition_value *find_predefined_condition(const LEX_STRING name) const;
|
|
|
|
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
private:
|
2013-06-19 13:32:14 +02:00
|
|
|
/// m_max_var_index -- number of variables (including all types of arguments)
|
|
|
|
/// in this context including all children contexts.
|
|
|
|
///
|
|
|
|
/// m_max_var_index >= m_vars.elements().
|
|
|
|
///
|
|
|
|
/// m_max_var_index of the root parsing context contains number of all
|
|
|
|
/// variables (including arguments) in all enclosed contexts.
|
|
|
|
uint m_max_var_index;
|
|
|
|
|
|
|
|
/// The maximum sub context's framesizes.
|
|
|
|
uint m_max_cursor_index;
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Parent context.
|
|
|
|
sp_pcontext *m_parent;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// An index of the first SP-variable in this parsing context. The index
|
|
|
|
/// belongs to a runtime table of SP-variables.
|
|
|
|
///
|
|
|
|
/// Note:
|
|
|
|
/// - m_var_offset is 0 for root parsing context;
|
|
|
|
/// - m_var_offset is different for all nested parsing contexts.
|
2006-04-07 16:53:15 +02:00
|
|
|
uint m_var_offset;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Cursor offset for this context.
|
|
|
|
uint m_cursor_offset;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Boundary for finding variables in this context. This is the number of
|
|
|
|
/// variables currently "invisible" to default clauses. This is normally 0,
|
|
|
|
/// but will be larger during parsing of DECLARE ... DEFAULT, to get the
|
|
|
|
/// scope right for DEFAULT values.
|
2005-11-01 14:58:52 +01:00
|
|
|
uint m_pboundary;
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
int m_num_case_exprs;
|
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// SP parameters/variables.
|
|
|
|
Dynamic_array<sp_variable *> m_vars;
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Stack of CASE expression ids.
|
|
|
|
Dynamic_array<int> m_case_expr_ids;
|
2002-12-11 14:24:29 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Stack of SQL-conditions.
|
|
|
|
Dynamic_array<sp_condition *> m_conditions;
|
2004-08-26 12:54:30 +02:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Stack of cursors.
|
2016-10-21 09:51:49 +02:00
|
|
|
Dynamic_array<sp_pcursor> m_cursors;
|
Bug#26503 (Illegal SQL exception handler code causes the server to crash)
Before this fix, the parser would accept illegal code in SQL exceptions
handlers, that later causes the runtime to crash when executing the code,
due to memory violations in the exception handler stack.
The root cause of the problem is instructions within an exception handler
that jumps to code located outside of the handler. This is illegal according
to the SQL 2003 standard, since labels located outside the handler are not
supposed to be visible (they are "out of scope"), so any instruction that
jumps to these labels, like ITERATE or LEAVE, should not parse.
The section of the standard that is relevant for this is :
SQL:2003 SQL/PSM (ISO/IEC 9075-4:2003)
section 13.1 <compound statement>,
syntax rule 4
<quote>
The scope of the <beginning label> is CS excluding every <SQL schema
statement> contained in CS and excluding every
<local handler declaration list> contained in CS. <beginning label> shall
not be equivalent to any other <beginning label>s within that scope.
</quote>
With this fix, the C++ class sp_pcontext, which represent the "parsing
context" tree (a.k.a symbol table) of a stored procedure, has been changed
as follows:
- constructors have been cleaned up, so that only building a root node for
the tree is public; building nodes inside a tree is not public.
- a new member, m_label_scope, indicates if a given syntactic context
belongs to a DECLARE HANDLER block,
- label resolution, in the method find_label(), has been changed to
implement the restriction of scope regarding labels used in a compound
statement.
The actions in the parser, when parsing the body of a SQL exception handler,
have been changed as follows:
- the implementation of an exception handler (DECLARE HANDLER) now creates
explicitly a new sp_pcontext, to isolate the code inside the handler from
the containing compound statement context.
- registering exception handlers as a result occurs in the parent context,
see the rule sp_hcond_element
- the code in sp_hcond_list has been cleaned up, to avoid code duplication
In addition, the flags IN_SIMPLE_CASE and IN_HANDLER, declared in sp_head.h
have been removed, since they are unused and broken by design (as seen with
Bug 19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation), representing a stack in a single flag is not possible.
Tests in sp-error have been added to show that illegal constructs are now
rejected.
Tests in sp have been added for code coverage, to show that ITERATE or LEAVE
statements are legal when jumping to a label in scope, inside the body of
an exception handler.
mysql-test/r/sp-error.result:
SQL Exception handlers define a parsing context for label resolution.
mysql-test/r/sp.result:
SQL Exception handlers define a parsing context for label resolution.
mysql-test/t/sp-error.test:
SQL Exception handlers define a parsing context for label resolution.
mysql-test/t/sp.test:
SQL Exception handlers define a parsing context for label resolution.
sql/sp_head.cc:
Minor cleanup
sql/sp_head.h:
Minor cleanup
sql/sp_pcontext.cc:
SQL Exception handlers define a parsing context for label resolution.
sql/sp_pcontext.h:
SQL Exception handlers define a parsing context for label resolution.
sql/sql_yacc.yy:
SQL Exception handlers define a parsing context for label resolution.
2007-03-14 19:02:32 +01:00
|
|
|
|
2013-06-19 13:32:14 +02:00
|
|
|
/// Stack of SQL-handlers.
|
|
|
|
Dynamic_array<sp_handler *> m_handlers;
|
|
|
|
|
|
|
|
/// List of labels.
|
|
|
|
List<sp_label> m_labels;
|
|
|
|
|
|
|
|
/// Children contexts, used for destruction.
|
|
|
|
Dynamic_array<sp_pcontext *> m_children;
|
|
|
|
|
|
|
|
/// Scope of this parsing context.
|
|
|
|
enum_scope m_scope;
|
2016-08-24 10:30:27 +02:00
|
|
|
|
|
|
|
/// FOR LOOP characteristics
|
|
|
|
Lex_for_loop m_for_loop;
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
}; // class sp_pcontext : public Sql_alloc
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _SP_PCONTEXT_H_ */
|