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++ -*- */
|
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....
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....
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....
2002-12-08 19:59:22 +01:00
|
|
|
|
|
|
|
#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 02:07:45 +02:00
|
|
|
class sp_cursor;
|
2006-04-07 16:53:15 +02:00
|
|
|
struct sp_variable;
|
2005-03-04 16:35:28 +03: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 03:18:29 -06:00
|
|
|
/** Condition caught by this HANDLER. */
|
2003-09-16 14:26:08 +02:00
|
|
|
struct sp_cond_type *cond;
|
2009-09-10 03:18:29 -06: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 03:18:29 -06: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 17:34:34 +04:00
|
|
|
|
2012-10-04 16:15:13 +02:00
|
|
|
|
|
|
|
class Sql_condition_info : public Sql_alloc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** SQL error code. */
|
|
|
|
uint m_sql_errno;
|
|
|
|
|
|
|
|
/** Error level. */
|
|
|
|
MYSQL_ERROR::enum_warning_level m_level;
|
|
|
|
|
|
|
|
/** SQLSTATE. */
|
|
|
|
char m_sql_state[SQLSTATE_LENGTH + 1];
|
|
|
|
|
|
|
|
/** Text message. */
|
|
|
|
char m_message[MYSQL_ERRMSG_SIZE];
|
|
|
|
|
|
|
|
void set(uint sql_errno, const char* sqlstate,
|
|
|
|
MYSQL_ERROR::enum_warning_level level,
|
|
|
|
const char* msg)
|
|
|
|
{
|
|
|
|
m_sql_errno= sql_errno;
|
|
|
|
m_level= level;
|
|
|
|
|
|
|
|
memcpy(m_sql_state, sqlstate, SQLSTATE_LENGTH);
|
|
|
|
m_sql_state[SQLSTATE_LENGTH]= '\0';
|
|
|
|
|
|
|
|
strncpy(m_message, msg, MYSQL_ERRMSG_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
m_sql_errno= 0;
|
|
|
|
m_level= MYSQL_ERROR::WARN_LEVEL_ERROR;
|
|
|
|
|
|
|
|
m_sql_state[0]= '\0';
|
|
|
|
m_message[0]= '\0';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-08-25 17:34:34 +04:00
|
|
|
/*
|
2005-12-07 17:01:17 +03: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 17:34:34 +04: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 03:18:29 -06: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-23 00:50:37 +02:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
/*
|
2005-12-07 17:01:17 +03:00
|
|
|
The routine for which this runtime context is created. Used for checking
|
|
|
|
if correct runtime context is used for variable handling.
|
2005-11-23 00:50:37 +02:00
|
|
|
*/
|
2005-12-07 17:01:17 +03:00
|
|
|
sp_head *sp;
|
2005-11-23 00:50:37 +02:00
|
|
|
#endif
|
|
|
|
|
2005-12-07 17:01:17 +03: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 17:01:17 +03: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 17:01:17 +03:00
|
|
|
Item *
|
|
|
|
get_item(uint var_idx);
|
2005-05-09 01:59:10 +03:00
|
|
|
|
2005-12-07 17:01:17 +03:00
|
|
|
Item **
|
|
|
|
get_item_addr(uint var_idx);
|
2005-05-09 01:59:10 +03:00
|
|
|
|
2005-12-07 17:01:17 +03: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 17:01:17 +03:00
|
|
|
inline bool
|
|
|
|
is_return_value_set() const
|
2003-02-26 19:22:29 +01:00
|
|
|
{
|
2005-12-07 17:01:17 +03:00
|
|
|
return m_return_value_set;
|
2003-02-26 19:22:29 +01:00
|
|
|
}
|
|
|
|
|
2010-07-30 19:28:36 +04:00
|
|
|
/*
|
|
|
|
SQL handlers support.
|
|
|
|
*/
|
|
|
|
|
2009-09-10 03:18:29 -06:00
|
|
|
void push_handler(struct sp_cond_type *cond, uint h, int type);
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2008-01-23 13:26:41 -07:00
|
|
|
void pop_handlers(uint count);
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2004-10-23 14:23:32 +02:00
|
|
|
bool
|
2009-09-10 03:18:29 -06:00
|
|
|
find_handler(THD *thd,
|
|
|
|
uint sql_errno,
|
2010-07-30 19:28:36 +04:00
|
|
|
const char *sqlstate,
|
2009-09-10 03:18:29 -06:00
|
|
|
MYSQL_ERROR::enum_warning_level level,
|
2010-07-30 19:28:36 +04:00
|
|
|
const char *msg);
|
2009-09-10 03:18:29 -06:00
|
|
|
|
2012-10-04 16:15:13 +02:00
|
|
|
Sql_condition_info *raised_condition() const;
|
2005-10-17 15:07:47 +02:00
|
|
|
|
2010-07-30 19:28:36 +04:00
|
|
|
void
|
|
|
|
push_hstack(uint h);
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2010-07-30 19:28:36 +04:00
|
|
|
uint
|
|
|
|
pop_hstack();
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2010-07-30 19:28:36 +04:00
|
|
|
bool
|
|
|
|
activate_handler(THD *thd,
|
|
|
|
uint *ip,
|
|
|
|
sp_instr *instr,
|
|
|
|
Query_arena *execute_arena,
|
|
|
|
Query_arena *backup_arena);
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2005-09-26 18:22:00 +02:00
|
|
|
|
2010-07-30 19:28:36 +04: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);
|
|
|
|
|
2010-07-30 19:28:36 +04:00
|
|
|
inline void
|
2003-10-10 16:57:21 +02:00
|
|
|
pop_all_cursors()
|
|
|
|
{
|
|
|
|
pop_cursors(m_ccount);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline sp_cursor *
|
|
|
|
get_cursor(uint i)
|
|
|
|
{
|
|
|
|
return m_cstack[i];
|
|
|
|
}
|
|
|
|
|
2005-12-07 17:01:17 +03: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 17:01:17 +03: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 17:01:17 +03: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 17:01:17 +03:00
|
|
|
/* Virtual table for storing variables. */
|
|
|
|
TABLE *m_var_table;
|
2003-10-10 16:57:21 +02:00
|
|
|
|
2005-12-07 17:01:17 +03: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;
|
Fix for Bug#56934 (mysql_stmt_fetch() incorrectly fills MYSQL_TIME
structure buffer).
This is a follow-up for WL#4435. The bug actually existed not only
MYSQL_TYPE_DATETIME type. The problem was that Item_param::set_value()
was written in an assumption that it's working with expressions, i.e.
with basic data types.
There are two different quick fixes here:
a) Change Item_param::make_field() -- remove setting of
Send_field::length, Send_field::charsetnr, Send_field::flags and
Send_field::type.
That would lead to marshalling all data using basic types to the client
(MYSQL_TYPE_LONGLONG, MYSQL_TYPE_DOUBLE, MYSQL_TYPE_STRING and
MYSQL_TYPE_NEWDECIMAL). In particular, that means, DATETIME would be
sent as MYSQL_TYPE_STRING, TINYINT -- as MYSQL_TYPE_LONGLONG, etc.
That could be Ok for the client, because the client library does
reverse conversion automatically (the client program would see DATETIME
as MYSQL_TIME object). However, there is a problem with metadata --
the metadata would be wrong (misleading): it would say that DATETIME is
marshaled as MYSQL_TYPE_DATETIME, not as MYSQL_TYPE_STRING.
b) Set Item_param::param_type properly to actual underlying field type.
That would lead to double conversion inside the server: for example,
MYSQL_TIME-object would be converted into STRING-object
(in Item_param::set_value()), and then converted back to MYSQL_TIME-object
(in Item_param::send()).
The data however would be marshalled more properly, and also metadata would
be correct.
This patch implements b).
There is also a possibility to avoid double conversion either by clonning
the data field, or by storing a reference to it and using it on Item::send()
time. That requires more work and might be done later.
2010-11-13 18:05:02 +03:00
|
|
|
|
2007-07-30 17:14:34 +04: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 03:18:29 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
SQL conditions caught by each handler.
|
|
|
|
This is an array indexed by handler index.
|
|
|
|
*/
|
2012-10-04 16:15:13 +02:00
|
|
|
Sql_condition_info *m_raised_conditions;
|
2009-09-10 03:18:29 -06:00
|
|
|
|
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 03:18:29 -06: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 17:01:17 +03: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 23:44:48 +04: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 02:11:21 +04: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 02:11:21 +04:00
|
|
|
uint field_count;
|
|
|
|
public:
|
2006-02-25 17:46:30 +02:00
|
|
|
Select_fetch_into_spvars() {} /* Remove gcc warning */
|
2005-09-22 02:11:21 +04: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 02:11:21 +04: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 16:35:28 +03:00
|
|
|
sp_lex_keeper *
|
2005-09-22 02:11:21 +04: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 02:11:21 +04: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 02:11:21 +04:00
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
private:
|
|
|
|
|
2005-09-22 02:11:21 +04:00
|
|
|
Select_fetch_into_spvars result;
|
2005-03-04 16:35:28 +03:00
|
|
|
sp_lex_keeper *m_lex_keeper;
|
2005-09-22 02:11:21 +04: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_ */
|