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_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
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_class.h" // select_result_interceptor
|
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
struct sp_cond_type;
|
2003-12-21 01:07:45 +01:00
|
|
|
class sp_cursor;
|
2006-04-07 16:53:15 +02:00
|
|
|
struct sp_variable;
|
2005-03-04 14:35:28 +01:00
|
|
|
class sp_lex_keeper;
|
2005-06-30 18:07:06 +02:00
|
|
|
class sp_instr_cpush;
|
2010-03-31 16:05:33 +02:00
|
|
|
class Query_arena;
|
|
|
|
class sp_head;
|
|
|
|
class sp_pcontext;
|
|
|
|
class Item_cache;
|
|
|
|
typedef class st_select_lex_unit SELECT_LEX_UNIT;
|
|
|
|
class Server_side_cursor;
|
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
|
|
|
|
{
|
2009-09-10 11:18:29 +02:00
|
|
|
/** Condition caught by this HANDLER. */
|
2003-09-16 14:26:08 +02:00
|
|
|
struct sp_cond_type *cond;
|
2009-09-10 11:18:29 +02:00
|
|
|
/** Location (instruction pointer) of the handler code. */
|
|
|
|
uint handler;
|
|
|
|
/** Handler type (EXIT, CONTINUE). */
|
2003-09-16 14:26:08 +02:00
|
|
|
int type;
|
|
|
|
} sp_handler_t;
|
|
|
|
|
2009-09-10 11:18:29 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/** Instruction pointer of the active handler. */
|
|
|
|
uint ip;
|
|
|
|
/** Handler index of the active handler. */
|
|
|
|
uint index;
|
|
|
|
} sp_active_handler_t;
|
2005-08-25 15:34:34 +02:00
|
|
|
|
|
|
|
/*
|
2005-12-07 15:01:17 +01:00
|
|
|
This class is a runtime context of a Stored Routine. It is used in an
|
|
|
|
execution and is intended to contain all dynamic objects (i.e. objects, which
|
|
|
|
can be changed during execution), such as:
|
|
|
|
- stored routine variables;
|
|
|
|
- cursors;
|
|
|
|
- handlers;
|
|
|
|
|
|
|
|
Runtime context is used with sp_head class. sp_head class is intended to
|
|
|
|
contain all static things, related to the stored routines (code, for example).
|
|
|
|
sp_head instance creates runtime context for the execution of a stored
|
|
|
|
routine.
|
|
|
|
|
|
|
|
There is a parsing context (an instance of sp_pcontext class), which is used
|
|
|
|
on parsing stage. However, now it contains some necessary for an execution
|
|
|
|
things, such as definition of used stored routine variables. That's why
|
|
|
|
runtime context needs a reference to the parsing context.
|
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_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
|
|
|
|
2009-09-10 11:18:29 +02:00
|
|
|
/*
|
|
|
|
End a open result set before start executing a continue/exit
|
|
|
|
handler if one is found as otherwise the client will hang
|
|
|
|
due to a violation of the client/server protocol.
|
|
|
|
*/
|
|
|
|
bool end_partial_result_set;
|
|
|
|
|
2005-11-22 23:50:37 +01:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
/*
|
2005-12-07 15:01:17 +01:00
|
|
|
The routine for which this runtime context is created. Used for checking
|
|
|
|
if correct runtime context is used for variable handling.
|
2005-11-22 23:50:37 +01:00
|
|
|
*/
|
2005-12-07 15:01:17 +01:00
|
|
|
sp_head *sp;
|
2005-11-22 23:50:37 +01:00
|
|
|
#endif
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
sp_rcontext(sp_pcontext *root_parsing_ctx, Field *return_value_fld,
|
|
|
|
sp_rcontext *prev_runtime_ctx);
|
|
|
|
bool init(THD *thd);
|
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
|
|
|
~sp_rcontext();
|
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
|
|
|
int
|
2006-05-15 12:01:55 +02:00
|
|
|
set_variable(THD *thd, uint var_idx, Item **value);
|
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
|
|
|
Item *
|
|
|
|
get_item(uint var_idx);
|
2005-05-09 00:59:10 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
Item **
|
|
|
|
get_item_addr(uint var_idx);
|
2005-05-09 00:59:10 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
bool
|
2006-05-15 12:01:55 +02:00
|
|
|
set_return_value(THD *thd, Item **return_value_item);
|
2003-02-26 19:22:29 +01:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
inline bool
|
|
|
|
is_return_value_set() const
|
2003-02-26 19:22:29 +01:00
|
|
|
{
|
2005-12-07 15:01:17 +01:00
|
|
|
return m_return_value_set;
|
2003-02-26 19:22:29 +01:00
|
|
|
}
|
|
|
|
|
2009-09-10 11:18:29 +02:00
|
|
|
void push_handler(struct sp_cond_type *cond, uint h, int type);
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2008-01-23 21:26:41 +01:00
|
|
|
void pop_handlers(uint count);
|
2003-09-16 14:26:08 +02:00
|
|
|
|
|
|
|
// Returns 1 if a handler was found, 0 otherwise.
|
2004-10-23 14:23:32 +02:00
|
|
|
bool
|
2009-09-10 11:18:29 +02:00
|
|
|
find_handler(THD *thd,
|
|
|
|
uint sql_errno,
|
|
|
|
const char* sqlstate,
|
|
|
|
MYSQL_ERROR::enum_warning_level level,
|
|
|
|
const char* msg,
|
|
|
|
MYSQL_ERROR ** cond_hdl);
|
2003-09-16 14:26:08 +02:00
|
|
|
|
Bug#8153 (Stored procedure with subquery and continue handler, wrong result)
Before this fix,
- a runtime error in a statement in a stored procedure with no error handlers
was properly detected (as expected)
- a runtime error in a statement with an error handler inherited from a non
local runtime context (i.e., proc a with a handler, calling proc b) was
properly detected (as expected)
- a runtime error in a statement with a *local* error handler was executed
as follows :
a) the statement would succeed, regardless of the error condition, (bug)
b) the error handler would be called (as expected).
The root cause is that functions like my_messqge_sql would "forget" to set
the thread flag thd->net.report_error to 1, because of the check involving
sp_rcontext::found_handler_here().
Failure to set this flag would cause, later in the call stack,
in Item_func::fix_fields() at line 190, the code to return FALSE and consider
that executing the statement was successful.
With this fix :
- error handling code, that was duplicated in different places in the code,
is now implemented in sp_rcontext::handle_error(),
- handle_error() correctly sets thd->net.report_error when a handler is
present, regardless of the handler location (local, or in the call stack).
A test case, bug8153_subselect, has been written to demonstrate the change
of behavior before and after the fix.
Another test case, bug8153_function_a, as also been writen.
This test has the same behavior before and after the fix.
This test has been written to demonstrate that the previous expected
result of procedure bug18787, was incorrect, since select no_such_function()
should fail and therefore not produce a result.
The incorrect result for bug18787 has the same root cause as Bug#8153,
and the expected result has been adjusted.
2006-08-03 07:18:49 +02:00
|
|
|
// If there is an error handler for this error, handle it and return TRUE.
|
|
|
|
bool
|
2009-09-10 11:18:29 +02:00
|
|
|
handle_condition(THD *thd,
|
|
|
|
uint sql_errno,
|
|
|
|
const char* sqlstate,
|
|
|
|
MYSQL_ERROR::enum_warning_level level,
|
|
|
|
const char* msg,
|
|
|
|
MYSQL_ERROR ** cond_hdl);
|
Bug#8153 (Stored procedure with subquery and continue handler, wrong result)
Before this fix,
- a runtime error in a statement in a stored procedure with no error handlers
was properly detected (as expected)
- a runtime error in a statement with an error handler inherited from a non
local runtime context (i.e., proc a with a handler, calling proc b) was
properly detected (as expected)
- a runtime error in a statement with a *local* error handler was executed
as follows :
a) the statement would succeed, regardless of the error condition, (bug)
b) the error handler would be called (as expected).
The root cause is that functions like my_messqge_sql would "forget" to set
the thread flag thd->net.report_error to 1, because of the check involving
sp_rcontext::found_handler_here().
Failure to set this flag would cause, later in the call stack,
in Item_func::fix_fields() at line 190, the code to return FALSE and consider
that executing the statement was successful.
With this fix :
- error handling code, that was duplicated in different places in the code,
is now implemented in sp_rcontext::handle_error(),
- handle_error() correctly sets thd->net.report_error when a handler is
present, regardless of the handler location (local, or in the call stack).
A test case, bug8153_subselect, has been written to demonstrate the change
of behavior before and after the fix.
Another test case, bug8153_function_a, as also been writen.
This test has the same behavior before and after the fix.
This test has been written to demonstrate that the previous expected
result of procedure bug18787, was incorrect, since select no_such_function()
should fail and therefore not produce a result.
The incorrect result for bug18787 has the same root cause as Bug#8153,
and the expected result has been adjusted.
2006-08-03 07:18:49 +02:00
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
// Returns handler type and sets *ip to location if one was found
|
|
|
|
inline int
|
2009-09-10 11:18:29 +02:00
|
|
|
found_handler(uint *ip, uint *index)
|
2003-09-16 14:26:08 +02:00
|
|
|
{
|
|
|
|
if (m_hfound < 0)
|
|
|
|
return SP_HANDLER_NONE;
|
|
|
|
*ip= m_handler[m_hfound].handler;
|
2009-09-10 11:18:29 +02:00
|
|
|
*index= m_hfound;
|
2003-09-16 14:26:08 +02:00
|
|
|
return m_handler[m_hfound].type;
|
|
|
|
}
|
|
|
|
|
2009-09-10 11:18:29 +02:00
|
|
|
MYSQL_ERROR* raised_condition() const;
|
|
|
|
|
2005-10-17 15:07:47 +02:00
|
|
|
// Returns true if we found a handler in this context
|
|
|
|
inline bool
|
|
|
|
found_handler_here()
|
|
|
|
{
|
|
|
|
return (m_hfound >= 0);
|
|
|
|
}
|
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
// Clears the handler find state
|
|
|
|
inline void
|
|
|
|
clear_handler()
|
|
|
|
{
|
|
|
|
m_hfound= -1;
|
|
|
|
}
|
|
|
|
|
2008-01-23 21:26:41 +01:00
|
|
|
void push_hstack(uint h);
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2008-01-23 21:26:41 +01:00
|
|
|
uint pop_hstack();
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2009-09-10 11:18:29 +02:00
|
|
|
/**
|
|
|
|
Enter a SQL exception handler.
|
|
|
|
@param hip the handler instruction pointer
|
|
|
|
@param index the handler index
|
|
|
|
*/
|
|
|
|
void enter_handler(uint hip, uint index);
|
2005-09-26 18:22:00 +02:00
|
|
|
|
2008-01-23 21:26:41 +01:00
|
|
|
void exit_handler();
|
2005-09-26 18:22:00 +02:00
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
/*
|
|
|
|
CASE expressions support.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2006-05-15 12:01:55 +02:00
|
|
|
set_case_expr(THD *thd, int case_expr_id, Item **case_expr_item_ptr);
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
Item *
|
|
|
|
get_case_expr(int case_expr_id);
|
|
|
|
|
|
|
|
Item **
|
|
|
|
get_case_expr_addr(int case_expr_id);
|
|
|
|
|
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:
|
2005-12-07 15:01:17 +01:00
|
|
|
sp_pcontext *m_root_parsing_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....
2002-12-08 19:59:22 +01:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
/* Virtual table for storing variables. */
|
|
|
|
TABLE *m_var_table;
|
2003-10-10 16:57:21 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
/*
|
|
|
|
Collection of Item_field proxies, each of them points to the corresponding
|
|
|
|
field in m_var_table.
|
|
|
|
*/
|
|
|
|
Item **m_var_items;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This is a pointer to a field, which should contain return value for stored
|
|
|
|
functions (only). For stored procedures, this pointer is NULL.
|
|
|
|
*/
|
|
|
|
Field *m_return_value_fld;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Indicates whether the return value (in m_return_value_fld) has been set
|
|
|
|
during execution.
|
|
|
|
*/
|
|
|
|
bool m_return_value_set;
|
2007-07-30 15:14:34 +02:00
|
|
|
/**
|
|
|
|
TRUE if the context is created for a sub-statement.
|
|
|
|
*/
|
|
|
|
bool in_sub_stmt;
|
2003-10-10 16:57:21 +02:00
|
|
|
|
2005-09-26 18:22:00 +02:00
|
|
|
sp_handler_t *m_handler; // Visible handlers
|
2009-09-10 11:18:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
SQL conditions caught by each handler.
|
|
|
|
This is an array indexed by handler index.
|
|
|
|
*/
|
|
|
|
MYSQL_ERROR *m_raised_conditions;
|
|
|
|
|
2005-09-26 18:22:00 +02:00
|
|
|
uint m_hcount; // Stack pointer for m_handler
|
|
|
|
uint *m_hstack; // Return stack for continue handlers
|
|
|
|
uint m_hsp; // Stack pointer for m_hstack
|
2009-09-10 11:18:29 +02:00
|
|
|
/** Active handler stack. */
|
|
|
|
sp_active_handler_t *m_in_handler;
|
2005-09-26 18:22:00 +02:00
|
|
|
uint m_ihsp; // Stack pointer for m_in_handler
|
|
|
|
int m_hfound; // Set by find_handler; -1 if not found
|
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;
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
Item_cache **m_case_expr_holders;
|
|
|
|
|
|
|
|
/* Previous runtime context (NULL if none) */
|
|
|
|
sp_rcontext *m_prev_runtime_ctx;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool init_var_table(THD *thd);
|
|
|
|
bool init_var_items();
|
|
|
|
|
2007-11-10 20:44:48 +01:00
|
|
|
Item_cache *create_case_expr_holder(THD *thd, const Item *item);
|
2005-09-26 18:46:31 +02:00
|
|
|
|
2006-05-15 12:01:55 +02:00
|
|
|
int set_variable(THD *thd, Field *field, Item **value);
|
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
|
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
List<struct sp_variable> *spvar_list;
|
2005-09-22 00:11:21 +02:00
|
|
|
uint field_count;
|
|
|
|
public:
|
2006-02-25 16:46:30 +01:00
|
|
|
Select_fetch_into_spvars() {} /* Remove gcc warning */
|
2005-09-22 00:11:21 +02:00
|
|
|
uint get_field_count() { return field_count; }
|
2006-04-07 16:53:15 +02:00
|
|
|
void set_spvar_list(List<struct sp_variable> *vars) { spvar_list= vars; }
|
2005-09-22 00:11:21 +02:00
|
|
|
|
|
|
|
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
|
2006-04-07 16:53:15 +02:00
|
|
|
fetch(THD *, List<struct sp_variable> *vars);
|
2003-10-10 16:57:21 +02:00
|
|
|
|
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_ */
|