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++ -*- */
|
|
|
|
/* 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
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
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_
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#pragma interface /* gcc class implementation */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
sp_param_in,
|
|
|
|
sp_param_out,
|
|
|
|
sp_param_inout
|
|
|
|
} sp_param_mode_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
Item_string *name;
|
|
|
|
enum enum_field_types type;
|
|
|
|
sp_param_mode_t mode;
|
|
|
|
uint offset; // Offset in current frame
|
|
|
|
my_bool isset;
|
|
|
|
} sp_pvar_t;
|
|
|
|
|
2002-12-11 14:24:29 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
uint ip; // Instruction index
|
|
|
|
} sp_label_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....
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
|
|
|
|
{
|
|
|
|
sp_pcontext(const sp_pcontext &); /* Prevent use of these */
|
|
|
|
void operator=(sp_pcontext &);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
sp_pcontext();
|
|
|
|
|
|
|
|
inline uint
|
|
|
|
max_framesize()
|
|
|
|
{
|
|
|
|
return m_framesize;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint
|
|
|
|
current_framesize()
|
|
|
|
{
|
|
|
|
return m_i;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint
|
|
|
|
params()
|
|
|
|
{
|
|
|
|
return m_params;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the number of parameters to the current esize
|
|
|
|
inline void
|
|
|
|
set_params()
|
|
|
|
{
|
|
|
|
m_params= m_i;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
set_type(uint i, enum enum_field_types type)
|
|
|
|
{
|
|
|
|
if (i < m_i)
|
|
|
|
m_pvar[i].type= type;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
set_isset(uint i, my_bool val)
|
|
|
|
{
|
|
|
|
if (i < m_i)
|
|
|
|
m_pvar[i].isset= val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
push(LEX_STRING *name, enum enum_field_types type, sp_param_mode_t mode);
|
|
|
|
|
2002-12-11 14:24:29 +01:00
|
|
|
// Pop the last 'num' slots of the frame
|
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
|
|
|
inline void
|
|
|
|
pop(uint num = 1)
|
|
|
|
{
|
|
|
|
if (num >= m_i)
|
|
|
|
m_i -= num;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find by name
|
|
|
|
sp_pvar_t *
|
|
|
|
find_pvar(LEX_STRING *name);
|
|
|
|
|
|
|
|
// Find by index
|
|
|
|
sp_pvar_t *
|
|
|
|
find_pvar(uint i)
|
|
|
|
{
|
|
|
|
if (i >= m_i)
|
|
|
|
return NULL;
|
|
|
|
return m_pvar+i;
|
|
|
|
}
|
|
|
|
|
2002-12-11 14:24:29 +01:00
|
|
|
void
|
|
|
|
push_label(char *name, uint ip);
|
|
|
|
|
|
|
|
void
|
|
|
|
push_gen_label(uint ip);
|
|
|
|
|
|
|
|
sp_label_t *
|
|
|
|
find_label(char *name);
|
|
|
|
|
2002-12-12 13:14:23 +01:00
|
|
|
inline sp_label_t *
|
|
|
|
last_label()
|
|
|
|
{
|
|
|
|
return m_label.head();
|
|
|
|
}
|
|
|
|
|
2002-12-11 14:24:29 +01:00
|
|
|
inline void
|
|
|
|
pop_label()
|
|
|
|
{
|
|
|
|
m_label.pop();
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
uint m_params; // The number of parameters
|
|
|
|
uint m_framesize; // The maximum framesize
|
|
|
|
uint m_i; // The current index (during parsing)
|
|
|
|
|
|
|
|
sp_pvar_t *m_pvar;
|
|
|
|
uint m_pvar_size; // Current size of m_pvar.
|
|
|
|
|
|
|
|
void
|
|
|
|
grow();
|
|
|
|
|
2002-12-11 14:24:29 +01:00
|
|
|
List<sp_label_t> m_label; // The label list
|
|
|
|
uint m_genlab; // Gen. label counter
|
|
|
|
|
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_ */
|