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
|
|
|
|
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_RCONTEXT_H_
|
|
|
|
#define _SP_RCONTEXT_H_
|
|
|
|
|
2005-05-27 12:03:37 +02:00
|
|
|
#ifdef USE_PRAGMA_INTERFACE
|
2003-09-16 14:26:08 +02:00
|
|
|
#pragma interface /* gcc class implementation */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct sp_cond_type;
|
2003-12-21 01:07:45 +01:00
|
|
|
class sp_cursor;
|
2003-10-10 16:57:21 +02:00
|
|
|
struct sp_pvar;
|
2005-03-04 14:35:28 +01:00
|
|
|
class sp_lex_keeper;
|
2005-06-30 18:07:06 +02:00
|
|
|
class sp_instr_cpush;
|
2003-09-16 14:26:08 +02:00
|
|
|
|
|
|
|
#define SP_HANDLER_NONE 0
|
|
|
|
#define SP_HANDLER_EXIT 1
|
|
|
|
#define SP_HANDLER_CONTINUE 2
|
|
|
|
#define SP_HANDLER_UNDO 3
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
struct sp_cond_type *cond;
|
|
|
|
uint handler; // Location of handler
|
|
|
|
int type;
|
|
|
|
uint foffset; // Frame offset for the handlers declare level
|
|
|
|
} sp_handler_t;
|
|
|
|
|
2005-08-25 15:34:34 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
This is a run context? of one SP ?
|
|
|
|
THis is
|
|
|
|
- a stack of cursors?
|
|
|
|
- a stack of handlers?
|
|
|
|
- a stack of Items ?
|
|
|
|
- a stack of instruction locations in SP?
|
|
|
|
*/
|
|
|
|
|
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_rcontext : public Sql_alloc
|
|
|
|
{
|
|
|
|
sp_rcontext(const sp_rcontext &); /* Prevent use of these */
|
|
|
|
void operator=(sp_rcontext &);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2005-08-18 11:23:54 +02:00
|
|
|
/*
|
|
|
|
Arena used to (re) allocate items on . E.g. reallocate INOUT/OUT
|
|
|
|
SP parameters when they don't fit into prealloced items. This
|
|
|
|
is common situation with String items. It is used mainly in
|
|
|
|
sp_eval_func_item().
|
|
|
|
*/
|
|
|
|
Query_arena *callers_arena;
|
2004-09-10 11:11:52 +02:00
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
sp_rcontext(uint fsize, uint hmax, uint cmax);
|
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
|
|
|
|
|
|
|
~sp_rcontext()
|
|
|
|
{
|
|
|
|
// Not needed?
|
|
|
|
//sql_element_free(m_frame);
|
2003-09-16 14:26:08 +02:00
|
|
|
//m_saved.empty();
|
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
|
|
|
|
push_item(Item *i)
|
|
|
|
{
|
2003-09-16 14:26:08 +02:00
|
|
|
if (m_count < m_fsize)
|
2005-05-23 23:43:43 +02:00
|
|
|
m_frame[m_count++]= 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
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
set_item(uint idx, Item *i)
|
|
|
|
{
|
|
|
|
if (idx < m_count)
|
2005-05-23 23:43:43 +02:00
|
|
|
m_frame[idx]= 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
|
|
|
}
|
|
|
|
|
2004-07-21 14:53:09 +02:00
|
|
|
/* Returns 0 on success, -1 on (eval) failure */
|
|
|
|
int
|
2005-05-23 23:43:43 +02:00
|
|
|
set_item_eval(THD *thd, uint idx, Item **i, enum_field_types type);
|
2003-10-14 12:59:28 +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
|
|
|
inline Item *
|
|
|
|
get_item(uint idx)
|
|
|
|
{
|
|
|
|
return m_frame[idx];
|
|
|
|
}
|
|
|
|
|
2005-05-09 00:59:10 +02:00
|
|
|
inline Item **
|
|
|
|
get_item_addr(uint idx)
|
|
|
|
{
|
|
|
|
return m_frame + idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-26 19:22:29 +01:00
|
|
|
inline void
|
|
|
|
set_result(Item *it)
|
|
|
|
{
|
|
|
|
m_result= it;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Item *
|
|
|
|
get_result()
|
|
|
|
{
|
|
|
|
return m_result;
|
|
|
|
}
|
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
inline void
|
|
|
|
push_handler(struct sp_cond_type *cond, uint h, int type, uint f)
|
|
|
|
{
|
|
|
|
m_handler[m_hcount].cond= cond;
|
|
|
|
m_handler[m_hcount].handler= h;
|
|
|
|
m_handler[m_hcount].type= type;
|
|
|
|
m_handler[m_hcount].foffset= f;
|
|
|
|
m_hcount+= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
pop_handlers(uint count)
|
|
|
|
{
|
|
|
|
m_hcount-= count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns 1 if a handler was found, 0 otherwise.
|
2004-10-23 14:23:32 +02:00
|
|
|
bool
|
2004-09-28 19:08:00 +02:00
|
|
|
find_handler(uint sql_errno,MYSQL_ERROR::enum_warning_level level);
|
2003-09-16 14:26:08 +02:00
|
|
|
|
|
|
|
// Returns handler type and sets *ip to location if one was found
|
|
|
|
inline int
|
|
|
|
found_handler(uint *ip, uint *fp)
|
|
|
|
{
|
|
|
|
if (m_hfound < 0)
|
|
|
|
return SP_HANDLER_NONE;
|
|
|
|
*ip= m_handler[m_hfound].handler;
|
|
|
|
*fp= m_handler[m_hfound].foffset;
|
|
|
|
return m_handler[m_hfound].type;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clears the handler find state
|
|
|
|
inline void
|
|
|
|
clear_handler()
|
|
|
|
{
|
|
|
|
m_hfound= -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
push_hstack(uint h)
|
|
|
|
{
|
|
|
|
m_hstack[m_hsp++]= h;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint
|
|
|
|
pop_hstack()
|
|
|
|
{
|
|
|
|
return m_hstack[--m_hsp];
|
|
|
|
}
|
|
|
|
|
2005-09-26 18:22:00 +02:00
|
|
|
inline void
|
|
|
|
enter_handler(int hid)
|
|
|
|
{
|
|
|
|
m_in_handler[m_ihsp++]= hid;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
exit_handler()
|
|
|
|
{
|
|
|
|
m_ihsp-= 1;
|
|
|
|
}
|
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
// Save variables starting at fp and up
|
|
|
|
void
|
|
|
|
save_variables(uint fp);
|
|
|
|
|
|
|
|
// Restore variables down to fp
|
|
|
|
void
|
|
|
|
restore_variables(uint fp);
|
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
void
|
2005-06-30 18:07:06 +02:00
|
|
|
push_cursor(sp_lex_keeper *lex_keeper, sp_instr_cpush *i);
|
2003-10-10 16:57:21 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
pop_cursors(uint count);
|
|
|
|
|
|
|
|
void
|
|
|
|
pop_all_cursors()
|
|
|
|
{
|
|
|
|
pop_cursors(m_ccount);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline sp_cursor *
|
|
|
|
get_cursor(uint i)
|
|
|
|
{
|
|
|
|
return m_cstack[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
|
|
|
private:
|
|
|
|
|
|
|
|
uint m_count;
|
2003-09-16 14:26:08 +02:00
|
|
|
uint m_fsize;
|
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
|
|
|
Item **m_frame;
|
2003-10-10 16:57:21 +02:00
|
|
|
|
2003-02-26 19:22:29 +01:00
|
|
|
Item *m_result; // For FUNCTIONs
|
2003-10-10 16:57:21 +02:00
|
|
|
|
2005-09-26 18:22:00 +02:00
|
|
|
sp_handler_t *m_handler; // Visible handlers
|
|
|
|
uint m_hcount; // Stack pointer for m_handler
|
|
|
|
uint *m_hstack; // Return stack for continue handlers
|
|
|
|
uint m_hsp; // Stack pointer for m_hstack
|
|
|
|
uint *m_in_handler; // Active handler, for recursion check
|
|
|
|
uint m_ihsp; // Stack pointer for m_in_handler
|
|
|
|
int m_hfound; // Set by find_handler; -1 if not found
|
|
|
|
List<Item> m_saved; // Saved variables during handler exec.
|
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-10-10 16:57:21 +02:00
|
|
|
sp_cursor **m_cstack;
|
|
|
|
uint m_ccount;
|
|
|
|
|
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_rcontext : public Sql_alloc
|
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
|
2005-09-22 00:11:21 +02:00
|
|
|
/*
|
|
|
|
An interceptor of cursor result set used to implement
|
|
|
|
FETCH <cname> INTO <varlist>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Select_fetch_into_spvars: public select_result_interceptor
|
|
|
|
{
|
|
|
|
List<struct sp_pvar> *spvar_list;
|
|
|
|
uint field_count;
|
|
|
|
public:
|
|
|
|
uint get_field_count() { return field_count; }
|
|
|
|
void set_spvar_list(List<struct sp_pvar> *vars) { spvar_list= vars; }
|
|
|
|
|
|
|
|
virtual bool send_eof() { return FALSE; }
|
|
|
|
virtual bool send_data(List<Item> &items);
|
|
|
|
virtual int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* A mediator between stored procedures and server side cursors */
|
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
class sp_cursor : public Sql_alloc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2005-06-30 18:07:06 +02:00
|
|
|
sp_cursor(sp_lex_keeper *lex_keeper, sp_instr_cpush *i);
|
2003-10-10 16:57:21 +02:00
|
|
|
|
|
|
|
virtual ~sp_cursor()
|
|
|
|
{
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
|
2005-03-04 14:35:28 +01:00
|
|
|
sp_lex_keeper *
|
2005-09-22 00:11:21 +02:00
|
|
|
get_lex_keeper() { return m_lex_keeper; }
|
|
|
|
|
|
|
|
int
|
|
|
|
open(THD *thd);
|
2003-10-10 16:57:21 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
close(THD *thd);
|
|
|
|
|
|
|
|
inline my_bool
|
|
|
|
is_open()
|
|
|
|
{
|
2005-09-22 00:11:21 +02:00
|
|
|
return test(server_side_cursor);
|
2003-10-10 16:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fetch(THD *, List<struct sp_pvar> *vars);
|
|
|
|
|
2005-06-30 18:07:06 +02:00
|
|
|
inline sp_instr_cpush *
|
|
|
|
get_instr()
|
|
|
|
{
|
|
|
|
return m_i;
|
|
|
|
}
|
2005-09-22 00:11:21 +02:00
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
private:
|
|
|
|
|
2005-09-22 00:11:21 +02:00
|
|
|
Select_fetch_into_spvars result;
|
2005-03-04 14:35:28 +01:00
|
|
|
sp_lex_keeper *m_lex_keeper;
|
2005-09-22 00:11:21 +02:00
|
|
|
Server_side_cursor *server_side_cursor;
|
2005-06-30 18:07:06 +02:00
|
|
|
sp_instr_cpush *m_i; // My push instruction
|
2003-10-10 16:57:21 +02:00
|
|
|
void
|
|
|
|
destroy();
|
|
|
|
|
|
|
|
}; // class sp_cursor : 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....
2002-12-08 19:59:22 +01:00
|
|
|
#endif /* _SP_RCONTEXT_H_ */
|