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
|
|
|
/* 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 */
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
|
|
|
#include "sp_head.h"
|
2002-12-12 13:14:23 +01:00
|
|
|
#include "sp.h"
|
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
|
|
|
#include "sp_pcontext.h"
|
|
|
|
#include "sp_rcontext.h"
|
|
|
|
|
2003-02-26 19:22:29 +01:00
|
|
|
Item_result
|
|
|
|
sp_map_result_type(enum enum_field_types type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case MYSQL_TYPE_TINY:
|
|
|
|
case MYSQL_TYPE_SHORT:
|
|
|
|
case MYSQL_TYPE_LONG:
|
|
|
|
case MYSQL_TYPE_LONGLONG:
|
|
|
|
case MYSQL_TYPE_INT24:
|
|
|
|
return INT_RESULT;
|
|
|
|
case MYSQL_TYPE_DECIMAL:
|
|
|
|
case MYSQL_TYPE_FLOAT:
|
|
|
|
case MYSQL_TYPE_DOUBLE:
|
|
|
|
return REAL_RESULT;
|
|
|
|
default:
|
|
|
|
return STRING_RESULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/* Evaluate a (presumed) func item. Always returns an item, the parameter
|
|
|
|
** if nothing else.
|
|
|
|
*/
|
|
|
|
static Item *
|
2002-12-13 18:25:36 +01:00
|
|
|
eval_func_item(THD *thd, Item *it, enum enum_field_types 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
|
|
|
{
|
2003-03-20 11:57:05 +01:00
|
|
|
DBUG_ENTER("eval_func_item");
|
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
|
|
|
it= it->this_item();
|
2003-03-20 11:57:05 +01:00
|
|
|
DBUG_PRINT("info", ("type: %d", 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
|
|
|
|
2002-12-13 18:25:36 +01:00
|
|
|
if (it->fix_fields(thd, 0, NULL))
|
2003-03-20 11:57:05 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("fix_fields() failed"));
|
|
|
|
DBUG_RETURN(it); // Shouldn't happen?
|
|
|
|
}
|
2002-12-13 18:25:36 +01:00
|
|
|
|
2002-12-12 13:14:23 +01:00
|
|
|
/* QQ How do we do this? Is there some better way? */
|
2003-02-26 19:22:29 +01:00
|
|
|
if (type == MYSQL_TYPE_NULL)
|
|
|
|
it= new Item_null();
|
|
|
|
else
|
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-02-26 19:22:29 +01:00
|
|
|
switch (sp_map_result_type(type)) {
|
|
|
|
case INT_RESULT:
|
2003-03-20 11:57:05 +01:00
|
|
|
DBUG_PRINT("info", ("INT_RESULT: %d", it->val_int()));
|
2003-02-26 19:22:29 +01:00
|
|
|
it= new Item_int(it->val_int());
|
|
|
|
break;
|
|
|
|
case REAL_RESULT:
|
2003-03-20 11:57:05 +01:00
|
|
|
DBUG_PRINT("info", ("REAL_RESULT: %g", it->val()));
|
2003-02-26 19:22:29 +01:00
|
|
|
it= new Item_real(it->val());
|
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
|
|
|
break;
|
2003-02-26 19:22:29 +01:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
char buffer[MAX_FIELD_WIDTH];
|
2003-02-27 19:08:52 +01:00
|
|
|
String tmp(buffer, sizeof(buffer), it->charset());
|
2003-02-26 19:22:29 +01:00
|
|
|
String *s= it->val_str(&tmp);
|
|
|
|
|
2003-03-20 11:57:05 +01:00
|
|
|
DBUG_PRINT("info", ("default result: %*s", s->length(), s->c_ptr_quick()))
|
2003-02-27 19:08:52 +01:00
|
|
|
it= new Item_string(sql_strmake(s->c_ptr_quick(), s->length()),
|
|
|
|
s->length(), it->charset());
|
2003-02-26 19:22:29 +01:00
|
|
|
break;
|
|
|
|
}
|
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-20 11:57:05 +01:00
|
|
|
DBUG_RETURN(it);
|
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_head::sp_head(LEX_STRING *name, LEX *lex)
|
2003-04-02 20:42:28 +02:00
|
|
|
: Sql_alloc(), m_simple_case(FALSE)
|
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-03 20:00:52 +02:00
|
|
|
DBUG_ENTER("sp_head::sp_head");
|
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
|
|
|
const char *dstr = (const char*)lex->buf;
|
|
|
|
|
2003-04-03 20:00:52 +02:00
|
|
|
DBUG_PRINT("info", ("name: %s", name->str));
|
2003-04-03 16:00:09 +02:00
|
|
|
m_name.length= name->length;
|
|
|
|
m_name.str= name->str;
|
|
|
|
m_defstr.length= lex->end_of_query - lex->buf;
|
|
|
|
m_defstr.str= sql_strmake(dstr, m_defstr.length);
|
2003-03-02 19:17:41 +01:00
|
|
|
m_pcont= lex->spcont;
|
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
|
|
|
my_init_dynamic_array(&m_instr, sizeof(sp_instr *), 16, 8);
|
2002-12-12 13:14:23 +01:00
|
|
|
m_backpatch.empty();
|
2003-04-03 20:00:52 +02:00
|
|
|
DBUG_VOID_RETURN;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_head::create(THD *thd)
|
|
|
|
{
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_head::create");
|
2003-02-21 17:37:05 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
DBUG_PRINT("info", ("type: %d name: %s def: %s",
|
2003-04-03 16:00:09 +02:00
|
|
|
m_type, m_name.str, m_defstr.str));
|
2003-02-21 17:37:05 +01:00
|
|
|
if (m_type == TYPE_ENUM_FUNCTION)
|
|
|
|
ret= sp_create_function(thd,
|
2003-04-03 16:00:09 +02:00
|
|
|
m_name.str, m_name.length,
|
|
|
|
m_defstr.str, m_defstr.length);
|
2003-02-21 17:37:05 +01:00
|
|
|
else
|
|
|
|
ret= sp_create_procedure(thd,
|
2003-04-03 16:00:09 +02:00
|
|
|
m_name.str, m_name.length,
|
|
|
|
m_defstr.str, m_defstr.length);
|
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-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(ret);
|
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
|
|
|
void
|
|
|
|
sp_head::destroy()
|
|
|
|
{
|
2003-04-03 20:00:52 +02:00
|
|
|
DBUG_ENTER("sp_head::destroy");
|
|
|
|
DBUG_PRINT("info", ("name: %s", m_name.str));
|
2003-04-02 20:42:28 +02:00
|
|
|
delete_dynamic(&m_instr);
|
|
|
|
m_pcont->destroy();
|
2003-04-03 20:00:52 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2003-04-02 20:42:28 +02:00
|
|
|
}
|
2003-02-26 19:22:29 +01: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
|
|
|
int
|
|
|
|
sp_head::execute(THD *thd)
|
|
|
|
{
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_head::execute");
|
2003-04-02 20:42:28 +02:00
|
|
|
char olddbname[128];
|
2003-03-26 15:02:48 +01:00
|
|
|
char *olddbptr= thd->db;
|
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
|
|
|
int ret= 0;
|
2003-02-26 19:22:29 +01:00
|
|
|
uint ip= 0;
|
|
|
|
|
2003-03-26 15:02:48 +01:00
|
|
|
if (olddbptr)
|
2003-04-02 20:42:28 +02:00
|
|
|
{
|
|
|
|
uint i= 0;
|
|
|
|
char *p= olddbptr;
|
|
|
|
|
|
|
|
/* Fast inline strncpy without padding... */
|
|
|
|
while (*p && i < sizeof(olddbname))
|
|
|
|
olddbname[i++]= *p++;
|
|
|
|
if (i == sizeof(olddbname))
|
|
|
|
i-= 1; // QQ Error or warning for truncate?
|
|
|
|
olddbname[i]= '\0';
|
|
|
|
}
|
2003-03-26 15:02:48 +01:00
|
|
|
|
2003-02-26 19:22:29 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
sp_instr *i;
|
|
|
|
|
|
|
|
i = get_instr(ip); // Returns NULL when we're done.
|
|
|
|
if (i == NULL)
|
|
|
|
break;
|
|
|
|
DBUG_PRINT("execute", ("Instruction %u", ip));
|
|
|
|
ret= i->execute(thd, &ip);
|
2003-03-28 17:02:31 +01:00
|
|
|
} while (ret == 0 && !thd->killed);
|
2003-03-26 15:02:48 +01:00
|
|
|
|
2003-03-28 17:02:31 +01:00
|
|
|
DBUG_PRINT("info", ("ret=%d killed=%d", ret, thd->killed));
|
|
|
|
if (thd->killed)
|
|
|
|
ret= -1;
|
2003-03-26 15:02:48 +01:00
|
|
|
/* If the DB has changed, the pointer has changed too, but the
|
|
|
|
original thd->db will then have been freed */
|
2003-04-02 20:42:28 +02:00
|
|
|
if (olddbptr && olddbptr != thd->db)
|
2003-03-26 15:02:48 +01:00
|
|
|
{
|
|
|
|
/* QQ Maybe we should issue some special error message or warning here,
|
|
|
|
if this fails?? */
|
2003-03-28 17:02:31 +01:00
|
|
|
if (! thd->killed)
|
|
|
|
ret= mysql_change_db(thd, olddbname);
|
2003-03-26 15:02:48 +01:00
|
|
|
}
|
2003-02-26 19:22:29 +01:00
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_head::execute_function(THD *thd, Item **argp, uint argcount, Item **resp)
|
|
|
|
{
|
2003-03-02 19:17:41 +01:00
|
|
|
DBUG_ENTER("sp_head::execute_function");
|
2003-04-03 16:00:09 +02:00
|
|
|
DBUG_PRINT("info", ("function %s", m_name.str));
|
2003-03-02 19:17:41 +01:00
|
|
|
uint csize = m_pcont->max_framesize();
|
|
|
|
uint params = m_pcont->params();
|
2003-02-26 19:22:29 +01:00
|
|
|
sp_rcontext *octx = thd->spcont;
|
|
|
|
sp_rcontext *nctx = NULL;
|
|
|
|
uint i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
// QQ Should have some error checking here? (no. of args, types, etc...)
|
|
|
|
nctx= new sp_rcontext(csize);
|
|
|
|
for (i= 0 ; i < params && i < argcount ; i++)
|
|
|
|
{
|
2003-03-02 19:17:41 +01:00
|
|
|
sp_pvar_t *pvar = m_pcont->find_pvar(i);
|
2003-02-26 19:22:29 +01:00
|
|
|
|
|
|
|
nctx->push_item(eval_func_item(thd, *argp++, pvar->type));
|
|
|
|
}
|
|
|
|
// The rest of the frame are local variables which are all IN.
|
|
|
|
// QQ See comment in execute_procedure below.
|
|
|
|
for (; i < csize ; i++)
|
|
|
|
nctx->push_item(NULL);
|
|
|
|
thd->spcont= nctx;
|
|
|
|
|
|
|
|
ret= execute(thd);
|
|
|
|
if (ret == 0)
|
|
|
|
*resp= nctx->get_result();
|
|
|
|
|
|
|
|
thd->spcont= octx;
|
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_head::execute_procedure(THD *thd, List<Item> *args)
|
|
|
|
{
|
2003-03-02 19:17:41 +01:00
|
|
|
DBUG_ENTER("sp_head::execute_procedure");
|
2003-04-03 16:00:09 +02:00
|
|
|
DBUG_PRINT("info", ("procedure %s", m_name.str));
|
2003-02-26 19:22:29 +01:00
|
|
|
int ret;
|
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_instr *p;
|
2003-03-02 19:17:41 +01:00
|
|
|
uint csize = m_pcont->max_framesize();
|
|
|
|
uint params = m_pcont->params();
|
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 *octx = thd->spcont;
|
|
|
|
sp_rcontext *nctx = NULL;
|
2003-02-02 17:44:39 +01:00
|
|
|
my_bool tmp_octx = FALSE; // True if we have allocated a temporary octx
|
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
|
|
|
|
|
|
|
if (csize > 0)
|
|
|
|
{
|
|
|
|
uint i;
|
2003-02-26 19:22:29 +01:00
|
|
|
List_iterator_fast<Item> li(*args);
|
2003-02-21 17:37:05 +01:00
|
|
|
Item *it;
|
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
|
|
|
|
|
|
|
nctx = new sp_rcontext(csize);
|
2003-02-02 17:44:39 +01:00
|
|
|
if (! octx)
|
|
|
|
{ // Create a temporary old context
|
|
|
|
octx = new sp_rcontext(csize);
|
|
|
|
tmp_octx = TRUE;
|
|
|
|
}
|
2002-12-12 13:14:23 +01:00
|
|
|
// QQ: No error checking whatsoever right now. Should do type checking?
|
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
|
|
|
for (i = 0 ; (it= li++) && i < params ; i++)
|
|
|
|
{
|
2003-03-02 19:17:41 +01:00
|
|
|
sp_pvar_t *pvar = m_pcont->find_pvar(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
|
|
|
|
2002-12-11 14:24:29 +01:00
|
|
|
if (! pvar)
|
|
|
|
nctx->set_oindex(i, -1); // Shouldn't happen
|
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
|
|
|
else
|
2002-12-11 14:24:29 +01:00
|
|
|
{
|
|
|
|
if (pvar->mode == sp_param_out)
|
2003-03-20 11:57:05 +01:00
|
|
|
nctx->push_item(NULL); // OUT
|
2002-12-11 14:24:29 +01:00
|
|
|
else
|
2002-12-13 18:25:36 +01:00
|
|
|
nctx->push_item(eval_func_item(thd, it, pvar->type)); // IN or INOUT
|
2002-12-11 14:24:29 +01:00
|
|
|
// Note: If it's OUT or INOUT, it must be a variable.
|
|
|
|
// QQ: Need to handle "global" user/host variables too!!!
|
|
|
|
if (pvar->mode == sp_param_in)
|
|
|
|
nctx->set_oindex(i, -1); // IN
|
|
|
|
else // OUT or INOUT
|
|
|
|
nctx->set_oindex(i, static_cast<Item_splocal *>(it)->get_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
|
|
|
}
|
|
|
|
// The rest of the frame are local variables which are all IN.
|
|
|
|
// QQ We haven't found any hint of what the value is when unassigned,
|
|
|
|
// so we set it to NULL for now. It's an error to refer to an
|
2002-12-12 13:14:23 +01:00
|
|
|
// unassigned variable anyway (which should be detected by the parser).
|
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
|
|
|
for (; i < csize ; i++)
|
|
|
|
nctx->push_item(NULL);
|
|
|
|
thd->spcont= nctx;
|
|
|
|
}
|
|
|
|
|
2003-02-26 19:22:29 +01:00
|
|
|
ret= execute(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
|
|
|
|
|
|
|
// Don't copy back OUT values if we got an error
|
|
|
|
if (ret == 0 && csize > 0)
|
|
|
|
{
|
2003-03-02 19:17:41 +01:00
|
|
|
List_iterator_fast<Item> li(*args);
|
2003-02-21 17:37:05 +01:00
|
|
|
Item *it;
|
2003-02-02 17:44:39 +01:00
|
|
|
|
|
|
|
// Copy back all OUT or INOUT values to the previous frame, or
|
|
|
|
// set global user variables
|
|
|
|
for (uint i = 0 ; (it= li++) && i < params ; 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
|
|
|
{
|
|
|
|
int oi = nctx->get_oindex(i);
|
|
|
|
|
|
|
|
if (oi >= 0)
|
2003-02-02 17:44:39 +01:00
|
|
|
{
|
|
|
|
if (! tmp_octx)
|
|
|
|
octx->set_item(nctx->get_oindex(i), nctx->get_item(i));
|
|
|
|
else
|
|
|
|
{ // A global user variable
|
|
|
|
#if 0
|
|
|
|
// QQ This works if the parameter really is a user variable, but
|
|
|
|
// for the moment we can't assure that, so it will crash if it's
|
|
|
|
// something else. So for now, we just do nothing, to avoid a crash.
|
|
|
|
// Note: This also assumes we have a get_name() method in
|
|
|
|
// the Item_func_get_user_var class.
|
|
|
|
Item *item= nctx->get_item(i);
|
|
|
|
Item_func_set_user_var *suv;
|
|
|
|
Item_func_get_user_var *guv= static_cast<Item_func_get_user_var*>(it);
|
|
|
|
|
|
|
|
suv= new Item_func_set_user_var(guv->get_name(), item);
|
|
|
|
suv->fix_fields(thd, NULL, &item);
|
|
|
|
suv->fix_length_and_dec();
|
|
|
|
suv->update();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
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-02-02 17:44:39 +01:00
|
|
|
if (tmp_octx)
|
|
|
|
thd->spcont= NULL;
|
|
|
|
else
|
|
|
|
thd->spcont= octx;
|
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-02-12 16:17:03 +01:00
|
|
|
DBUG_RETURN(ret);
|
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-12 13:14:23 +01:00
|
|
|
// Reset lex during parsing, before we parse a sub statement.
|
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
|
|
|
void
|
|
|
|
sp_head::reset_lex(THD *thd)
|
|
|
|
{
|
|
|
|
memcpy(&m_lex, &thd->lex, sizeof(LEX)); // Save old one
|
|
|
|
/* Reset most stuff. The length arguments doesn't matter here. */
|
|
|
|
lex_start(thd, m_lex.buf, m_lex.end_of_query - m_lex.ptr);
|
|
|
|
/* We must reset ptr and end_of_query again */
|
|
|
|
thd->lex.ptr= m_lex.ptr;
|
|
|
|
thd->lex.end_of_query= m_lex.end_of_query;
|
|
|
|
/* And keep the SP stuff too */
|
|
|
|
thd->lex.sphead = m_lex.sphead;
|
|
|
|
thd->lex.spcont = m_lex.spcont;
|
2002-12-13 18:25:36 +01:00
|
|
|
/* Clear all lists. (QQ Why isn't this reset by lex_start()?).
|
|
|
|
We may be overdoing this, but we know for sure that value_list must
|
|
|
|
be cleared at least. */
|
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
|
|
|
thd->lex.col_list.empty();
|
|
|
|
thd->lex.ref_list.empty();
|
|
|
|
thd->lex.drop_list.empty();
|
|
|
|
thd->lex.alter_list.empty();
|
|
|
|
thd->lex.interval_list.empty();
|
|
|
|
thd->lex.users_list.empty();
|
|
|
|
thd->lex.columns.empty();
|
|
|
|
thd->lex.key_list.empty();
|
|
|
|
thd->lex.create_list.empty();
|
|
|
|
thd->lex.insert_list= NULL;
|
|
|
|
thd->lex.field_list.empty();
|
|
|
|
thd->lex.value_list.empty();
|
|
|
|
thd->lex.many_values.empty();
|
|
|
|
thd->lex.var_list.empty();
|
|
|
|
thd->lex.param_list.empty();
|
|
|
|
thd->lex.proc_list.empty();
|
|
|
|
thd->lex.auxilliary_table_list.empty();
|
|
|
|
}
|
|
|
|
|
2002-12-12 13:14:23 +01:00
|
|
|
// Restore lex during parsing, after we have parsed a sub statement.
|
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
|
|
|
void
|
|
|
|
sp_head::restore_lex(THD *thd)
|
|
|
|
{
|
|
|
|
// Update some state in the old one first
|
|
|
|
m_lex.ptr= thd->lex.ptr;
|
|
|
|
m_lex.next_state= thd->lex.next_state;
|
2002-12-13 18:25:36 +01:00
|
|
|
|
2002-12-19 18:43:25 +01:00
|
|
|
// Collect some data from the sub statement lex.
|
2003-03-02 19:17:41 +01:00
|
|
|
sp_merge_funs(&m_lex, &thd->lex);
|
|
|
|
#if 0
|
|
|
|
// We're not using this at the moment.
|
2002-12-13 18:25:36 +01:00
|
|
|
if (thd->lex.sql_command == SQLCOM_CALL)
|
|
|
|
{
|
2002-12-19 18:43:25 +01:00
|
|
|
// It would be slightly faster to keep the list sorted, but we need
|
|
|
|
// an "insert before" method to do that.
|
2003-02-21 17:37:05 +01:00
|
|
|
char *proc= thd->lex.udf.name.str;
|
2002-12-13 18:25:36 +01:00
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
List_iterator_fast<char *> li(m_calls);
|
|
|
|
char **it;
|
2002-12-19 18:43:25 +01:00
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
while ((it= li++))
|
2003-03-27 17:35:27 +01:00
|
|
|
if (my_strcasecmp(system_charset_info, proc, *it) == 0)
|
2002-12-13 18:25:36 +01:00
|
|
|
break;
|
|
|
|
if (! it)
|
2003-02-21 17:37:05 +01:00
|
|
|
m_calls.push_back(&proc);
|
2002-12-19 18:43:25 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
// Merge used tables
|
|
|
|
// QQ ...or just open tables in thd->open_tables?
|
|
|
|
// This is not entirerly clear at the moment, but for now, we collect
|
|
|
|
// tables here.
|
|
|
|
for (SELECT_LEX *sl= thd->lex.all_selects_list ;
|
|
|
|
sl ;
|
|
|
|
sl= sl->next_select())
|
|
|
|
{
|
|
|
|
for (TABLE_LIST *tables= sl->get_table_list() ;
|
|
|
|
tables ;
|
|
|
|
tables= tables->next)
|
|
|
|
{
|
|
|
|
List_iterator_fast<char *> li(m_tables);
|
|
|
|
char **tb;
|
|
|
|
|
|
|
|
while ((tb= li++))
|
2003-03-27 17:35:27 +01:00
|
|
|
if (my_strcasecmp(system_charset_info, tables->real_name, *tb) == 0)
|
2002-12-19 18:43:25 +01:00
|
|
|
break;
|
|
|
|
if (! tb)
|
|
|
|
m_tables.push_back(&tables->real_name);
|
|
|
|
}
|
2002-12-13 18:25:36 +01:00
|
|
|
}
|
2003-03-02 19:17:41 +01:00
|
|
|
#endif
|
2002-12-13 18:25:36 +01: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
|
|
|
memcpy(&thd->lex, &m_lex, sizeof(LEX)); // Restore lex
|
|
|
|
}
|
|
|
|
|
2002-12-11 14:24:29 +01:00
|
|
|
void
|
2002-12-16 15:40:44 +01:00
|
|
|
sp_head::push_backpatch(sp_instr *i, sp_label_t *lab)
|
2002-12-11 14:24:29 +01:00
|
|
|
{
|
2003-04-02 20:42:28 +02:00
|
|
|
bp_t *bp= (bp_t *)sql_alloc(sizeof(bp_t));
|
2002-12-16 15:40:44 +01:00
|
|
|
|
|
|
|
if (bp)
|
|
|
|
{
|
|
|
|
bp->lab= lab;
|
|
|
|
bp->instr= i;
|
|
|
|
(void)m_backpatch.push_front(bp);
|
|
|
|
}
|
2002-12-11 14:24:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-12-16 15:40:44 +01:00
|
|
|
sp_head::backpatch(sp_label_t *lab)
|
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-16 15:40:44 +01:00
|
|
|
bp_t *bp;
|
2002-12-12 13:14:23 +01:00
|
|
|
uint dest= instructions();
|
2002-12-16 15:40:44 +01:00
|
|
|
List_iterator_fast<bp_t> li(m_backpatch);
|
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-16 15:40:44 +01:00
|
|
|
while ((bp= li++))
|
|
|
|
if (bp->lab == lab)
|
|
|
|
{
|
|
|
|
sp_instr_jump *i= static_cast<sp_instr_jump *>(bp->instr);
|
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-16 15:40:44 +01:00
|
|
|
i->set_destination(dest);
|
|
|
|
}
|
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
|
|
|
// ------------------------------------------------------------------
|
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_instr_stmt
|
|
|
|
//
|
|
|
|
int
|
2002-12-11 14:24:29 +01:00
|
|
|
sp_instr_stmt::execute(THD *thd, uint *nextp)
|
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-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_instr_stmt::execute");
|
|
|
|
DBUG_PRINT("info", ("command: %d", m_lex.sql_command));
|
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
|
|
|
LEX olex; // The other lex
|
2003-01-15 15:39:36 +01:00
|
|
|
int res;
|
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
|
|
|
|
|
|
|
memcpy(&olex, &thd->lex, sizeof(LEX)); // Save the other lex
|
|
|
|
|
|
|
|
memcpy(&thd->lex, &m_lex, sizeof(LEX)); // Use my own lex
|
|
|
|
thd->lex.thd = thd;
|
|
|
|
|
2003-01-15 15:39:36 +01:00
|
|
|
res= mysql_execute_command(thd);
|
2003-02-28 15:07:14 +01:00
|
|
|
if (thd->lock || thd->open_tables || thd->derived_tables)
|
|
|
|
{
|
|
|
|
thd->proc_info="closing tables";
|
|
|
|
close_thread_tables(thd); /* Free tables */
|
|
|
|
}
|
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
|
|
|
|
|
|
|
memcpy(&thd->lex, &olex, sizeof(LEX)); // Restore the other lex
|
|
|
|
|
2002-12-11 14:24:29 +01:00
|
|
|
*nextp = m_ip+1;
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_RETURN(res);
|
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_instr_set
|
|
|
|
//
|
|
|
|
int
|
2002-12-11 14:24:29 +01:00
|
|
|
sp_instr_set::execute(THD *thd, uint *nextp)
|
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-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_instr_set::execute");
|
|
|
|
DBUG_PRINT("info", ("offset: %u", m_offset));
|
2002-12-13 18:25:36 +01:00
|
|
|
thd->spcont->set_item(m_offset, eval_func_item(thd, m_value, m_type));
|
2002-12-11 14:24:29 +01:00
|
|
|
*nextp = m_ip+1;
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_RETURN(0);
|
2002-12-11 14:24:29 +01:00
|
|
|
}
|
|
|
|
|
2003-03-05 19:45:17 +01:00
|
|
|
//
|
|
|
|
// sp_instr_jump
|
|
|
|
//
|
|
|
|
int
|
|
|
|
sp_instr_jump::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_instr_jump::execute");
|
|
|
|
DBUG_PRINT("info", ("destination: %u", m_dest));
|
|
|
|
|
|
|
|
*nextp= m_dest;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2002-12-11 14:24:29 +01:00
|
|
|
//
|
|
|
|
// sp_instr_jump_if
|
|
|
|
//
|
|
|
|
int
|
|
|
|
sp_instr_jump_if::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_instr_jump_if::execute");
|
|
|
|
DBUG_PRINT("info", ("destination: %u", m_dest));
|
2002-12-13 18:25:36 +01:00
|
|
|
Item *it= eval_func_item(thd, m_expr, MYSQL_TYPE_TINY);
|
2002-12-11 14:24:29 +01:00
|
|
|
|
|
|
|
if (it->val_int())
|
|
|
|
*nextp = m_dest;
|
|
|
|
else
|
|
|
|
*nextp = m_ip+1;
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_RETURN(0);
|
2002-12-11 14:24:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// sp_instr_jump_if_not
|
|
|
|
//
|
|
|
|
int
|
|
|
|
sp_instr_jump_if_not::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_instr_jump_if_not::execute");
|
|
|
|
DBUG_PRINT("info", ("destination: %u", m_dest));
|
2002-12-13 18:25:36 +01:00
|
|
|
Item *it= eval_func_item(thd, m_expr, MYSQL_TYPE_TINY);
|
2002-12-11 14:24:29 +01:00
|
|
|
|
|
|
|
if (! it->val_int())
|
|
|
|
*nextp = m_dest;
|
|
|
|
else
|
|
|
|
*nextp = m_ip+1;
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_RETURN(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
|
|
|
}
|
2003-02-26 19:22:29 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// sp_instr_return
|
|
|
|
//
|
|
|
|
int
|
|
|
|
sp_instr_return::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_instr_return::execute");
|
|
|
|
thd->spcont->set_result(eval_func_item(thd, m_value, m_type));
|
|
|
|
*nextp= UINT_MAX;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|