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....
2002-12-08 19:59:22 +01:00
|
|
|
/* -*- C++ -*- */
|
|
|
|
/* Copyright (C) 2002 MySQL AB
|
|
|
|
|
|
|
|
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....
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
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
#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....
2002-12-08 19:59:22 +01:00
|
|
|
#pragma interface /* gcc class implementation */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
sp_param_in,
|
|
|
|
sp_param_out,
|
|
|
|
sp_param_inout
|
|
|
|
} sp_param_mode_t;
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
typedef struct 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....
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2003-03-26 12:29:58 +01:00
|
|
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
enum enum_field_types type;
|
|
|
|
sp_param_mode_t mode;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
/*
|
2006-04-07 16:53:15 +02:00
|
|
|
offset -- this the index to the variable's value in the runtime frame.
|
|
|
|
This 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.
|
2005-12-07 15:01:17 +01:00
|
|
|
*/
|
|
|
|
uint offset;
|
|
|
|
|
2004-04-06 15:48:58 +02:00
|
|
|
Item *dflt;
|
2005-12-07 15:01:17 +01:00
|
|
|
create_field field_def;
|
2006-04-07 16:53:15 +02:00
|
|
|
} sp_variable_t;
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
|
2004-08-17 20:20:58 +02:00
|
|
|
|
2006-04-18 11:07:34 +02:00
|
|
|
#define SP_LAB_IMPL 0 // Implicit label generated by parser
|
|
|
|
#define SP_LAB_BEGIN 1 // Label at BEGIN
|
|
|
|
#define SP_LAB_ITER 2 // Label at iteration control
|
2004-08-17 20:20:58 +02:00
|
|
|
|
2006-01-16 15:22:29 +01:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2002-12-16 15:40:44 +01:00
|
|
|
typedef struct sp_label
|
2002-12-11 14:24:29 +01:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
uint ip; // Instruction index
|
2004-08-17 20:20:58 +02:00
|
|
|
int type; // begin/iter or ref/free
|
2004-11-17 11:45:05 +01:00
|
|
|
sp_pcontext *ctx; // The label's context
|
2002-12-11 14:24:29 +01:00
|
|
|
} sp_label_t;
|
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
typedef struct sp_cond_type
|
|
|
|
{
|
|
|
|
enum { number, state, warning, notfound, exception } type;
|
|
|
|
char sqlstate[6];
|
|
|
|
uint mysqlerr;
|
|
|
|
} sp_cond_type_t;
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
/*
|
|
|
|
Sanity check for SQLSTATEs. Will not check if it's really an existing
|
|
|
|
state (there are just too many), but will check length bad characters.
|
|
|
|
*/
|
2005-02-28 18:07:06 +01:00
|
|
|
extern bool
|
|
|
|
sp_cond_check(LEX_STRING *sqlstate);
|
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
typedef struct sp_cond
|
|
|
|
{
|
|
|
|
LEX_STRING name;
|
|
|
|
sp_cond_type_t *val;
|
|
|
|
} sp_cond_t;
|
|
|
|
|
2005-08-25 15:34:34 +02:00
|
|
|
|
|
|
|
/*
|
2006-04-07 16:53:15 +02:00
|
|
|
The parse-time context, used to keep track on declared variables/parameters,
|
|
|
|
conditions, handlers, cursors and labels, during parsing.
|
|
|
|
sp_contexts are organized as a tree, with one object for each begin-end
|
|
|
|
block, plus a root-context for the parameters.
|
|
|
|
This is used during parsing for looking up defined names (e.g. declared
|
|
|
|
variables and visible labels), for error checking, and to calculate offsets
|
|
|
|
to be used at runtime. (During execution variable values, active handlers
|
|
|
|
and cursors, etc, are referred to by an index in a stack.)
|
|
|
|
The pcontext tree is also kept during execution and is used for error
|
|
|
|
checking (e.g. correct number of parameters), and in the future, used by
|
|
|
|
the debugger.
|
2005-08-25 15:34:34 +02:00
|
|
|
*/
|
|
|
|
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
class sp_pcontext : public Sql_alloc
|
|
|
|
{
|
|
|
|
sp_pcontext(const sp_pcontext &); /* Prevent use of these */
|
|
|
|
void operator=(sp_pcontext &);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2004-08-26 12:54:30 +02:00
|
|
|
sp_pcontext(sp_pcontext *prev);
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
|
2003-04-02 20:42:28 +02:00
|
|
|
// Free memory
|
|
|
|
void
|
|
|
|
destroy();
|
|
|
|
|
2004-08-26 12:54:30 +02:00
|
|
|
sp_pcontext *
|
|
|
|
push_context();
|
2003-11-13 19:34:56 +01:00
|
|
|
|
2004-08-26 12:54:30 +02:00
|
|
|
// Returns the previous context, not the one we pop
|
|
|
|
sp_pcontext *
|
|
|
|
pop_context();
|
2004-08-17 20:20:58 +02:00
|
|
|
|
2004-08-26 12:54:30 +02:00
|
|
|
sp_pcontext *
|
|
|
|
parent_context()
|
2004-08-17 20:20:58 +02:00
|
|
|
{
|
2004-08-26 12:54:30 +02:00
|
|
|
return m_parent;
|
2004-08-17 20:20:58 +02:00
|
|
|
}
|
|
|
|
|
2006-02-15 12:11:29 +01:00
|
|
|
/*
|
|
|
|
Number of handlers/cursors to pop between this context and 'ctx'.
|
|
|
|
If 'exclusive' is true, don't count the last block we are leaving;
|
|
|
|
this is used for LEAVE where we will jump to the cpop/hpop instructions.
|
|
|
|
*/
|
2004-08-26 12:54:30 +02:00
|
|
|
uint
|
2006-02-15 12:11:29 +01:00
|
|
|
diff_handlers(sp_pcontext *ctx, bool exclusive);
|
2004-08-26 12:54:30 +02:00
|
|
|
uint
|
2006-02-15 12:11:29 +01:00
|
|
|
diff_cursors(sp_pcontext *ctx, bool exclusive);
|
2004-08-17 20:20:58 +02:00
|
|
|
|
2003-11-13 19:34:56 +01:00
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
//
|
|
|
|
// Parameters and variables
|
|
|
|
//
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
/*
|
|
|
|
The maximum number of variables used in this and all child contexts
|
|
|
|
In the root, this gives us the number of slots needed for variables
|
|
|
|
during execution.
|
|
|
|
*/
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
inline uint
|
2006-04-07 16:53:15 +02:00
|
|
|
max_var_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....
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
return m_max_var_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....
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
/*
|
|
|
|
The current number of variables used in the parents (from the root),
|
|
|
|
including this context.
|
|
|
|
*/
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
inline uint
|
2006-04-07 16:53:15 +02:00
|
|
|
current_var_count()
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
return m_var_offset + m_vars.elements;
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
/* The number of variables in this context alone */
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
inline uint
|
2006-04-07 16:53:15 +02:00
|
|
|
context_var_count()
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
return m_vars.elements;
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
/* Map index in this pcontext to runtime offset */
|
2004-08-26 12:54:30 +02:00
|
|
|
inline uint
|
2006-04-07 16:53:15 +02:00
|
|
|
var_context2runtime(uint i)
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
return m_var_offset + i;
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
/* Set type of variable. 'i' is the offset from the top */
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
inline void
|
|
|
|
set_type(uint i, enum enum_field_types type)
|
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
sp_variable_t *p= find_variable(i);
|
2003-04-02 20:42:28 +02:00
|
|
|
|
|
|
|
if (p)
|
|
|
|
p->type= type;
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
/* Set default value of variable. 'i' is the offset from the top */
|
2004-04-06 15:48:58 +02:00
|
|
|
inline void
|
|
|
|
set_default(uint i, Item *it)
|
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
sp_variable_t *p= find_variable(i);
|
2004-04-06 15:48:58 +02:00
|
|
|
|
|
|
|
if (p)
|
|
|
|
p->dflt= it;
|
|
|
|
}
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
sp_variable_t *
|
|
|
|
push_variable(LEX_STRING *name, enum enum_field_types type,
|
|
|
|
sp_param_mode_t mode);
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
/*
|
|
|
|
Retrieve definitions of fields from the current context and its
|
|
|
|
children.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
retrieve_field_definitions(List<create_field> *field_def_lst);
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
|
|
|
|
// Find by name
|
2006-04-07 16:53:15 +02:00
|
|
|
sp_variable_t *
|
|
|
|
find_variable(LEX_STRING *name, my_bool scoped=0);
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
// Find by offset (from the top)
|
|
|
|
sp_variable_t *
|
|
|
|
find_variable(uint offset);
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
|
2005-12-02 14:30:42 +01:00
|
|
|
/*
|
2005-12-07 15:01:17 +01:00
|
|
|
Set the current scope boundary (for default values).
|
2005-12-02 14:30:42 +01:00
|
|
|
The argument is the number of variables to skip.
|
|
|
|
*/
|
2005-11-01 14:58:52 +01:00
|
|
|
inline void
|
|
|
|
declare_var_boundary(uint n)
|
|
|
|
{
|
2005-12-02 14:30:42 +01:00
|
|
|
m_pboundary= n;
|
2005-11-01 14:58:52 +01:00
|
|
|
}
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
/*
|
|
|
|
CASE expressions support.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline int
|
|
|
|
register_case_expr()
|
|
|
|
{
|
|
|
|
return m_num_case_exprs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
|
|
|
get_num_case_exprs() const
|
|
|
|
{
|
|
|
|
return m_num_case_exprs;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
push_case_expr_id(int case_expr_id)
|
|
|
|
{
|
|
|
|
return insert_dynamic(&m_case_expr_id_lst, (gptr) &case_expr_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
pop_case_expr_id()
|
|
|
|
{
|
|
|
|
pop_dynamic(&m_case_expr_id_lst);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
|
|
|
get_current_case_expr_id() const
|
|
|
|
{
|
|
|
|
int case_expr_id;
|
|
|
|
|
|
|
|
get_dynamic((DYNAMIC_ARRAY*)&m_case_expr_id_lst, (gptr) &case_expr_id,
|
|
|
|
m_case_expr_id_lst.elements - 1);
|
|
|
|
|
|
|
|
return case_expr_id;
|
|
|
|
}
|
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
//
|
|
|
|
// Labels
|
|
|
|
//
|
|
|
|
|
2002-12-16 15:40:44 +01:00
|
|
|
sp_label_t *
|
2002-12-11 14:24:29 +01:00
|
|
|
push_label(char *name, uint ip);
|
|
|
|
|
|
|
|
sp_label_t *
|
|
|
|
find_label(char *name);
|
|
|
|
|
2002-12-12 13:14:23 +01:00
|
|
|
inline sp_label_t *
|
|
|
|
last_label()
|
|
|
|
{
|
2004-08-26 12:54:30 +02:00
|
|
|
sp_label_t *lab= m_label.head();
|
|
|
|
|
|
|
|
if (!lab && m_parent)
|
|
|
|
lab= m_parent->last_label();
|
|
|
|
return lab;
|
2002-12-12 13:14:23 +01:00
|
|
|
}
|
|
|
|
|
2002-12-16 15:40:44 +01:00
|
|
|
inline sp_label_t *
|
2002-12-11 14:24:29 +01:00
|
|
|
pop_label()
|
|
|
|
{
|
2002-12-16 15:40:44 +01:00
|
|
|
return m_label.pop();
|
2002-12-11 14:24:29 +01:00
|
|
|
}
|
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
//
|
|
|
|
// Conditions
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
push_cond(LEX_STRING *name, sp_cond_type_t *val);
|
|
|
|
|
|
|
|
inline void
|
|
|
|
pop_cond(uint num)
|
|
|
|
{
|
|
|
|
while (num--)
|
2006-04-07 16:53:15 +02:00
|
|
|
pop_dynamic(&m_conds);
|
2003-09-16 14:26:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sp_cond_type_t *
|
2003-11-13 19:34:56 +01:00
|
|
|
find_cond(LEX_STRING *name, my_bool scoped=0);
|
2003-09-16 14:26:08 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Handlers
|
|
|
|
//
|
|
|
|
|
2005-04-08 19:58:04 +02:00
|
|
|
inline void
|
|
|
|
push_handler(sp_cond_type_t *cond)
|
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
insert_dynamic(&m_handlers, (gptr)&cond);
|
2005-04-08 19:58:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
find_handler(sp_cond_type *cond);
|
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
inline uint
|
2006-04-07 16:53:15 +02:00
|
|
|
max_handler_index()
|
2003-09-16 14:26:08 +02:00
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
return m_max_handler_index + m_context_handlers;
|
2003-09-16 14:26:08 +02:00
|
|
|
}
|
|
|
|
|
2004-08-17 20:20:58 +02:00
|
|
|
inline void
|
2005-04-13 16:57:49 +02:00
|
|
|
add_handlers(uint n)
|
2004-08-17 20:20:58 +02:00
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
m_context_handlers+= n;
|
2004-08-17 20:20:58 +02:00
|
|
|
}
|
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
//
|
|
|
|
// Cursors
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
push_cursor(LEX_STRING *name);
|
|
|
|
|
|
|
|
my_bool
|
2003-11-13 19:34:56 +01:00
|
|
|
find_cursor(LEX_STRING *name, uint *poff, my_bool scoped=0);
|
2003-10-10 16:57:21 +02:00
|
|
|
|
2005-11-18 16:30:27 +01:00
|
|
|
/* Find by offset (for debugging only) */
|
2005-11-17 11:11:48 +01:00
|
|
|
my_bool
|
2005-11-18 16:30:27 +01:00
|
|
|
find_cursor(uint offset, LEX_STRING *n);
|
2005-11-17 11:11:48 +01:00
|
|
|
|
2004-08-26 12:54:30 +02:00
|
|
|
inline uint
|
2006-04-07 16:53:15 +02:00
|
|
|
max_cursor_index()
|
2003-10-10 16:57:21 +02:00
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
return m_max_cursor_index + m_cursors.elements;
|
2003-10-10 16:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline uint
|
2006-04-07 16:53:15 +02:00
|
|
|
current_cursor_count()
|
2003-10-10 16:57:21 +02:00
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
return m_cursor_offset + m_cursors.elements;
|
2003-10-10 16:57:21 +02:00
|
|
|
}
|
|
|
|
|
2004-08-26 12:54:30 +02:00
|
|
|
protected:
|
2004-08-17 20:20:58 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
/*
|
2006-04-07 16:53:15 +02:00
|
|
|
m_max_var_index -- number of variables (including all types of arguments)
|
2005-12-07 15:01:17 +01:00
|
|
|
in this context including all children contexts.
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
m_max_var_index >= m_vars.elements.
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
m_max_var_index of the root parsing context contains number of all
|
2005-12-07 15:01:17 +01:00
|
|
|
variables (including arguments) in all enclosed contexts.
|
|
|
|
*/
|
2006-04-07 16:53:15 +02:00
|
|
|
uint m_max_var_index;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2004-08-26 12:54:30 +02:00
|
|
|
// The maximum sub context's framesizes
|
2006-04-07 16:53:15 +02:00
|
|
|
uint m_max_cursor_index;
|
|
|
|
uint m_max_handler_index;
|
|
|
|
uint m_context_handlers; // No. of handlers in this context
|
2004-08-17 20:20:58 +02:00
|
|
|
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
private:
|
|
|
|
|
2004-08-26 12:54:30 +02:00
|
|
|
sp_pcontext *m_parent; // Parent context
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
/*
|
2006-04-07 16:53:15 +02:00
|
|
|
m_var_offset -- this is an index of the first variable in this
|
|
|
|
parsing context.
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
m_var_offset is 0 for root context.
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
Since now each variable is stored in separate place, no reuse is done,
|
2006-04-07 16:53:15 +02:00
|
|
|
so m_var_offset is different for all enclosed contexts.
|
2005-12-07 15:01:17 +01:00
|
|
|
*/
|
2006-04-07 16:53:15 +02:00
|
|
|
uint m_var_offset;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
uint m_cursor_offset; // Cursor offset for this context
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2005-11-01 14:58:52 +01:00
|
|
|
/*
|
2005-12-02 14:30:42 +01: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....
2002-12-08 19:59:22 +01:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
int m_num_case_exprs;
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
DYNAMIC_ARRAY m_vars; // Parameters/variables
|
2005-12-07 15:01:17 +01:00
|
|
|
DYNAMIC_ARRAY m_case_expr_id_lst; /* Stack of CASE expression ids. */
|
2006-04-07 16:53:15 +02:00
|
|
|
DYNAMIC_ARRAY m_conds; // Conditions
|
|
|
|
DYNAMIC_ARRAY m_cursors; // Cursors
|
|
|
|
DYNAMIC_ARRAY m_handlers; // Handlers, for checking for duplicates
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
|
2002-12-11 14:24:29 +01:00
|
|
|
List<sp_label_t> m_label; // The label list
|
|
|
|
|
2004-08-26 12:54:30 +02:00
|
|
|
List<sp_pcontext> m_children; // Children contexts, used for destruction
|
|
|
|
|
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....
2002-12-08 19:59:22 +01:00
|
|
|
}; // class sp_pcontext : public Sql_alloc
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _SP_PCONTEXT_H_ */
|