2011-06-30 17:46:53 +02:00
|
|
|
/* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
|
2003-09-16 14:26:08 +02: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.
|
2003-09-16 14:26:08 +02: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 */
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_priv.h"
|
|
|
|
#include "unireg.h"
|
2005-05-27 12:03:37 +02:00
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
2003-09-16 14:26:08 +02:00
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
#include "mysql.h"
|
|
|
|
#include "sp_head.h"
|
2005-09-22 00:11:21 +02:00
|
|
|
#include "sql_cursor.h"
|
2003-09-16 14:26:08 +02:00
|
|
|
#include "sp_rcontext.h"
|
|
|
|
#include "sp_pcontext.h"
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_select.h" // create_virtual_tmp_table
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
sp_rcontext::sp_rcontext(sp_pcontext *root_parsing_ctx,
|
|
|
|
Field *return_value_fld,
|
|
|
|
sp_rcontext *prev_runtime_ctx)
|
2009-09-10 11:18:29 +02:00
|
|
|
:end_partial_result_set(FALSE),
|
|
|
|
m_root_parsing_ctx(root_parsing_ctx),
|
2005-12-07 15:01:17 +01:00
|
|
|
m_var_table(0),
|
|
|
|
m_var_items(0),
|
|
|
|
m_return_value_fld(return_value_fld),
|
|
|
|
m_return_value_set(FALSE),
|
2007-07-30 15:14:34 +02:00
|
|
|
in_sub_stmt(FALSE),
|
2005-12-07 15:01:17 +01:00
|
|
|
m_hcount(0),
|
|
|
|
m_hsp(0),
|
|
|
|
m_ihsp(0),
|
|
|
|
m_hfound(-1),
|
|
|
|
m_ccount(0),
|
|
|
|
m_case_expr_holders(0),
|
|
|
|
m_prev_runtime_ctx(prev_runtime_ctx)
|
2003-09-16 14:26:08 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-05-23 23:43:43 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
sp_rcontext::~sp_rcontext()
|
|
|
|
{
|
|
|
|
if (m_var_table)
|
|
|
|
free_blobs(m_var_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Initialize sp_rcontext instance.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
thd Thread handle
|
|
|
|
RETURN
|
|
|
|
FALSE on success
|
|
|
|
TRUE on error
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool sp_rcontext::init(THD *thd)
|
|
|
|
{
|
2009-09-10 11:18:29 +02:00
|
|
|
uint handler_count= m_root_parsing_ctx->max_handler_index();
|
|
|
|
|
2007-07-30 15:14:34 +02:00
|
|
|
in_sub_stmt= thd->in_sub_stmt;
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
if (init_var_table(thd) || init_var_items())
|
|
|
|
return TRUE;
|
|
|
|
|
2012-10-04 16:15:13 +02:00
|
|
|
if (!(m_raised_conditions= new (thd->mem_root) Sql_condition_info[handler_count]))
|
2009-09-10 11:18:29 +02:00
|
|
|
return TRUE;
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
return
|
|
|
|
!(m_handler=
|
2009-09-10 11:18:29 +02:00
|
|
|
(sp_handler_t*)thd->alloc(handler_count * sizeof(sp_handler_t))) ||
|
2005-12-07 15:01:17 +01:00
|
|
|
!(m_hstack=
|
2009-09-10 11:18:29 +02:00
|
|
|
(uint*)thd->alloc(handler_count * sizeof(uint))) ||
|
2005-12-07 15:01:17 +01:00
|
|
|
!(m_in_handler=
|
2009-09-10 11:18:29 +02:00
|
|
|
(sp_active_handler_t*)thd->alloc(handler_count *
|
|
|
|
sizeof(sp_active_handler_t))) ||
|
2005-12-07 15:01:17 +01:00
|
|
|
!(m_cstack=
|
2006-04-07 16:53:15 +02:00
|
|
|
(sp_cursor**)thd->alloc(m_root_parsing_ctx->max_cursor_index() *
|
2005-12-07 15:01:17 +01:00
|
|
|
sizeof(sp_cursor*))) ||
|
|
|
|
!(m_case_expr_holders=
|
|
|
|
(Item_cache**)thd->calloc(m_root_parsing_ctx->get_num_case_exprs() *
|
|
|
|
sizeof (Item_cache*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Create and initialize a table to store SP-vars.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
thd Thread handler.
|
|
|
|
RETURN
|
|
|
|
FALSE on success
|
|
|
|
TRUE on error
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
|
|
|
sp_rcontext::init_var_table(THD *thd)
|
2003-10-14 12:59:28 +02:00
|
|
|
{
|
2007-06-10 12:43:57 +02:00
|
|
|
List<Create_field> field_def_lst;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
if (!m_root_parsing_ctx->max_var_index())
|
2005-12-07 15:01:17 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
m_root_parsing_ctx->retrieve_field_definitions(&field_def_lst);
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
DBUG_ASSERT(field_def_lst.elements == m_root_parsing_ctx->max_var_index());
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
if (!(m_var_table= create_virtual_tmp_table(thd, field_def_lst)))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
m_var_table->copy_blobs= TRUE;
|
|
|
|
m_var_table->alias= "";
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Create and initialize an Item-adapter (Item_field) for each SP-var field.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
FALSE on success
|
|
|
|
TRUE on error
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
|
|
|
sp_rcontext::init_var_items()
|
|
|
|
{
|
|
|
|
uint idx;
|
2006-04-07 16:53:15 +02:00
|
|
|
uint num_vars= m_root_parsing_ctx->max_var_index();
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
if (!(m_var_items= (Item**) sql_alloc(num_vars * sizeof (Item *))))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (idx = 0; idx < num_vars; ++idx)
|
2004-07-21 14:53:09 +02:00
|
|
|
{
|
2005-12-07 15:01:17 +01:00
|
|
|
if (!(m_var_items[idx]= new Item_field(m_var_table->field[idx])))
|
|
|
|
return TRUE;
|
2004-07-21 14:53:09 +02:00
|
|
|
}
|
2005-05-23 23:43:43 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
return FALSE;
|
2003-10-14 12:59:28 +02:00
|
|
|
}
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
bool
|
2006-05-15 12:01:55 +02:00
|
|
|
sp_rcontext::set_return_value(THD *thd, Item **return_value_item)
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(m_return_value_fld);
|
|
|
|
|
|
|
|
m_return_value_set = TRUE;
|
|
|
|
|
|
|
|
return sp_eval_expr(thd, m_return_value_fld, return_value_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-13 13:12:42 +01:00
|
|
|
#define IS_WARNING_CONDITION(S) ((S)[0] == '0' && (S)[1] == '1')
|
|
|
|
#define IS_NOT_FOUND_CONDITION(S) ((S)[0] == '0' && (S)[1] == '2')
|
|
|
|
#define IS_EXCEPTION_CONDITION(S) ((S)[0] != '0' || (S)[1] > '2')
|
|
|
|
|
2010-07-30 17:28:36 +02:00
|
|
|
/**
|
|
|
|
Find an SQL handler for the given error.
|
|
|
|
|
|
|
|
SQL handlers are pushed on the stack m_handler, with the latest/innermost
|
2006-02-01 16:00:11 +01:00
|
|
|
one on the top; we then search for matching handlers from the top and
|
|
|
|
down.
|
2010-07-30 17:28:36 +02:00
|
|
|
|
2006-02-01 16:00:11 +01:00
|
|
|
We search through all the handlers, looking for the most specific one
|
|
|
|
(sql_errno more specific than sqlstate more specific than the rest).
|
|
|
|
Note that mysql error code handlers is a MySQL extension, not part of
|
|
|
|
the standard.
|
|
|
|
|
2010-07-30 17:28:36 +02:00
|
|
|
SQL handlers for warnings are searched in the current scope only.
|
2006-02-01 16:00:11 +01:00
|
|
|
|
2010-07-30 17:28:36 +02:00
|
|
|
SQL handlers for errors are searched in the current and in outer scopes.
|
|
|
|
That's why finding and activation of handler must be separated: an errror
|
|
|
|
handler might be located in the outer scope, which is not active at the
|
|
|
|
moment. Before such handler can be activated, execution flow should
|
|
|
|
unwind to that scope.
|
|
|
|
|
|
|
|
Found SQL handler is remembered in m_hfound for future activation.
|
|
|
|
If no handler is found, m_hfound is -1.
|
|
|
|
|
|
|
|
@param thd Thread handle
|
|
|
|
@param sql_errno The error code
|
|
|
|
@param sqlstate The error SQL state
|
|
|
|
@param level The error level
|
|
|
|
@param msg The error message
|
|
|
|
|
|
|
|
@retval TRUE if an SQL handler was found
|
|
|
|
@retval FALSE otherwise
|
2006-02-01 16:00:11 +01:00
|
|
|
*/
|
|
|
|
|
2004-10-23 14:23:32 +02:00
|
|
|
bool
|
2009-09-10 11:18:29 +02:00
|
|
|
sp_rcontext::find_handler(THD *thd,
|
|
|
|
uint sql_errno,
|
2010-07-30 17:28:36 +02:00
|
|
|
const char *sqlstate,
|
2009-09-10 11:18:29 +02:00
|
|
|
MYSQL_ERROR::enum_warning_level level,
|
2010-07-30 17:28:36 +02:00
|
|
|
const char *msg)
|
2003-09-16 14:26:08 +02:00
|
|
|
{
|
2010-07-30 17:28:36 +02:00
|
|
|
int i= m_hcount;
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2010-07-30 17:28:36 +02:00
|
|
|
/* Reset previously found handler. */
|
|
|
|
m_hfound= -1;
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2007-07-30 15:14:34 +02:00
|
|
|
/*
|
|
|
|
If this is a fatal sub-statement error, and this runtime
|
|
|
|
context corresponds to a sub-statement, no CONTINUE/EXIT
|
|
|
|
handlers from this context are applicable: try to locate one
|
|
|
|
in the outer scope.
|
|
|
|
*/
|
|
|
|
if (thd->is_fatal_sub_stmt_error && in_sub_stmt)
|
|
|
|
i= 0;
|
|
|
|
|
2006-02-01 16:00:11 +01:00
|
|
|
/* Search handlers from the latest (innermost) to the oldest (outermost) */
|
2004-10-23 14:23:32 +02:00
|
|
|
while (i--)
|
2003-09-16 14:26:08 +02:00
|
|
|
{
|
|
|
|
sp_cond_type_t *cond= m_handler[i].cond;
|
2005-09-26 18:22:00 +02:00
|
|
|
int j= m_ihsp;
|
|
|
|
|
2006-02-01 16:00:11 +01:00
|
|
|
/* Check active handlers, to avoid invoking one recursively */
|
2005-09-26 18:22:00 +02:00
|
|
|
while (j--)
|
2009-09-10 11:18:29 +02:00
|
|
|
if (m_in_handler[j].ip == m_handler[i].handler)
|
2005-09-26 18:22:00 +02:00
|
|
|
break;
|
|
|
|
if (j >= 0)
|
|
|
|
continue; // Already executing this handler
|
2003-09-16 14:26:08 +02:00
|
|
|
|
|
|
|
switch (cond->type)
|
|
|
|
{
|
|
|
|
case sp_cond_type_t::number:
|
2006-01-25 17:19:54 +01:00
|
|
|
if (sql_errno == cond->mysqlerr &&
|
2010-07-30 17:28:36 +02:00
|
|
|
(m_hfound < 0 || m_handler[m_hfound].cond->type > sp_cond_type_t::number))
|
|
|
|
m_hfound= i; // Always the most specific
|
2003-09-16 14:26:08 +02:00
|
|
|
break;
|
|
|
|
case sp_cond_type_t::state:
|
2004-10-23 14:23:32 +02:00
|
|
|
if (strcmp(sqlstate, cond->sqlstate) == 0 &&
|
2010-07-30 17:28:36 +02:00
|
|
|
(m_hfound < 0 || m_handler[m_hfound].cond->type > sp_cond_type_t::state))
|
|
|
|
m_hfound= i;
|
2003-09-16 14:26:08 +02:00
|
|
|
break;
|
|
|
|
case sp_cond_type_t::warning:
|
2005-12-13 13:12:42 +01:00
|
|
|
if ((IS_WARNING_CONDITION(sqlstate) ||
|
|
|
|
level == MYSQL_ERROR::WARN_LEVEL_WARN) &&
|
2010-07-30 17:28:36 +02:00
|
|
|
m_hfound < 0)
|
|
|
|
m_hfound= i;
|
2003-09-16 14:26:08 +02:00
|
|
|
break;
|
|
|
|
case sp_cond_type_t::notfound:
|
2010-07-30 17:28:36 +02:00
|
|
|
if (IS_NOT_FOUND_CONDITION(sqlstate) && m_hfound < 0)
|
|
|
|
m_hfound= i;
|
2003-09-16 14:26:08 +02:00
|
|
|
break;
|
|
|
|
case sp_cond_type_t::exception:
|
2005-12-13 13:12:42 +01:00
|
|
|
if (IS_EXCEPTION_CONDITION(sqlstate) &&
|
2005-04-08 16:05:16 +02:00
|
|
|
level == MYSQL_ERROR::WARN_LEVEL_ERROR &&
|
2010-07-30 17:28:36 +02:00
|
|
|
m_hfound < 0)
|
|
|
|
m_hfound= i;
|
2003-09-16 14:26:08 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-09-10 11:18:29 +02:00
|
|
|
|
2010-07-30 17:28:36 +02:00
|
|
|
if (m_hfound >= 0)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT((uint) m_hfound < m_root_parsing_ctx->max_handler_index());
|
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
|
|
|
|
2010-07-30 17:28:36 +02:00
|
|
|
m_raised_conditions[m_hfound].clear();
|
|
|
|
m_raised_conditions[m_hfound].set(sql_errno, sqlstate, level, msg);
|
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
|
|
|
|
2010-07-30 17:28:36 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
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
|
|
|
|
2010-07-30 17:28:36 +02:00
|
|
|
/*
|
|
|
|
Only "exception conditions" are propagated to handlers in calling
|
|
|
|
contexts. If no handler is found locally for a "completion condition"
|
|
|
|
(warning or "not found") we will simply resume execution.
|
|
|
|
*/
|
|
|
|
if (m_prev_runtime_ctx && IS_EXCEPTION_CONDITION(sqlstate) &&
|
|
|
|
level == MYSQL_ERROR::WARN_LEVEL_ERROR)
|
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
|
|
|
{
|
2010-07-30 17:28:36 +02:00
|
|
|
return m_prev_runtime_ctx->find_handler(thd, sql_errno, sqlstate,
|
|
|
|
level, msg);
|
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
|
|
|
}
|
|
|
|
|
2010-07-30 17:28:36 +02:00
|
|
|
return FALSE;
|
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-10-10 16:57:21 +02:00
|
|
|
|
|
|
|
void
|
2005-06-30 18:07:06 +02:00
|
|
|
sp_rcontext::push_cursor(sp_lex_keeper *lex_keeper, sp_instr_cpush *i)
|
2003-10-10 16:57:21 +02:00
|
|
|
{
|
2008-01-23 21:26:41 +01:00
|
|
|
DBUG_ENTER("sp_rcontext::push_cursor");
|
|
|
|
DBUG_ASSERT(m_ccount < m_root_parsing_ctx->max_cursor_index());
|
2005-06-30 18:07:06 +02:00
|
|
|
m_cstack[m_ccount++]= new sp_cursor(lex_keeper, i);
|
2008-01-23 21:26:41 +01:00
|
|
|
DBUG_PRINT("info", ("m_ccount: %d", m_ccount));
|
|
|
|
DBUG_VOID_RETURN;
|
2003-10-10 16:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sp_rcontext::pop_cursors(uint count)
|
|
|
|
{
|
2008-01-23 21:26:41 +01:00
|
|
|
DBUG_ENTER("sp_rcontext::pop_cursors");
|
|
|
|
DBUG_ASSERT(m_ccount >= count);
|
2003-10-10 16:57:21 +02:00
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
delete m_cstack[--m_ccount];
|
|
|
|
}
|
2008-01-23 21:26:41 +01:00
|
|
|
DBUG_PRINT("info", ("m_ccount: %d", m_ccount));
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-10 11:18:29 +02:00
|
|
|
sp_rcontext::push_handler(struct sp_cond_type *cond, uint h, int type)
|
2008-01-23 21:26:41 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_rcontext::push_handler");
|
|
|
|
DBUG_ASSERT(m_hcount < m_root_parsing_ctx->max_handler_index());
|
|
|
|
|
|
|
|
m_handler[m_hcount].cond= cond;
|
|
|
|
m_handler[m_hcount].handler= h;
|
|
|
|
m_handler[m_hcount].type= type;
|
|
|
|
m_hcount+= 1;
|
|
|
|
|
|
|
|
DBUG_PRINT("info", ("m_hcount: %d", m_hcount));
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sp_rcontext::pop_handlers(uint count)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_rcontext::pop_handlers");
|
|
|
|
DBUG_ASSERT(m_hcount >= count);
|
2010-07-30 17:28:36 +02:00
|
|
|
|
2008-01-23 21:26:41 +01:00
|
|
|
m_hcount-= count;
|
2010-07-30 17:28:36 +02:00
|
|
|
|
2008-01-23 21:26:41 +01:00
|
|
|
DBUG_PRINT("info", ("m_hcount: %d", m_hcount));
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sp_rcontext::push_hstack(uint h)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_rcontext::push_hstack");
|
|
|
|
DBUG_ASSERT(m_hsp < m_root_parsing_ctx->max_handler_index());
|
2010-07-30 17:28:36 +02:00
|
|
|
|
2008-01-23 21:26:41 +01:00
|
|
|
m_hstack[m_hsp++]= h;
|
2010-07-30 17:28:36 +02:00
|
|
|
|
2008-01-23 21:26:41 +01:00
|
|
|
DBUG_PRINT("info", ("m_hsp: %d", m_hsp));
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint
|
|
|
|
sp_rcontext::pop_hstack()
|
|
|
|
{
|
|
|
|
uint handler;
|
|
|
|
DBUG_ENTER("sp_rcontext::pop_hstack");
|
|
|
|
DBUG_ASSERT(m_hsp);
|
2010-07-30 17:28:36 +02:00
|
|
|
|
2008-01-23 21:26:41 +01:00
|
|
|
handler= m_hstack[--m_hsp];
|
2010-07-30 17:28:36 +02:00
|
|
|
|
2008-01-23 21:26:41 +01:00
|
|
|
DBUG_PRINT("info", ("m_hsp: %d", m_hsp));
|
|
|
|
DBUG_RETURN(handler);
|
|
|
|
}
|
|
|
|
|
2010-07-30 17:28:36 +02:00
|
|
|
/**
|
|
|
|
Prepare found handler to be executed.
|
|
|
|
|
|
|
|
@retval TRUE if an SQL handler is activated (was found) and IP of the
|
|
|
|
first handler instruction.
|
|
|
|
@retval FALSE if there is no active handler
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
|
|
|
sp_rcontext::activate_handler(THD *thd,
|
|
|
|
uint *ip,
|
|
|
|
sp_instr *instr,
|
|
|
|
Query_arena *execute_arena,
|
|
|
|
Query_arena *backup_arena)
|
2008-01-23 21:26:41 +01:00
|
|
|
{
|
2010-07-30 17:28:36 +02:00
|
|
|
if (m_hfound < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (m_handler[m_hfound].type) {
|
|
|
|
case SP_HANDLER_NONE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SP_HANDLER_CONTINUE:
|
|
|
|
thd->restore_active_arena(execute_arena, backup_arena);
|
|
|
|
thd->set_n_backup_active_arena(execute_arena, backup_arena);
|
|
|
|
push_hstack(instr->get_cont_dest());
|
|
|
|
|
|
|
|
/* Fall through */
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* End aborted result set. */
|
|
|
|
|
|
|
|
if (end_partial_result_set)
|
|
|
|
thd->protocol->end_partial_result_set(thd);
|
|
|
|
|
|
|
|
/* Enter handler. */
|
|
|
|
|
|
|
|
DBUG_ASSERT(m_ihsp < m_root_parsing_ctx->max_handler_index());
|
|
|
|
DBUG_ASSERT(m_hfound >= 0);
|
|
|
|
|
|
|
|
m_in_handler[m_ihsp].ip= m_handler[m_hfound].handler;
|
|
|
|
m_in_handler[m_ihsp].index= m_hfound;
|
|
|
|
m_ihsp++;
|
|
|
|
|
|
|
|
DBUG_PRINT("info", ("Entering handler..."));
|
|
|
|
DBUG_PRINT("info", ("m_ihsp: %d", m_ihsp));
|
|
|
|
|
|
|
|
/* Reset error state. */
|
|
|
|
|
|
|
|
thd->clear_error();
|
|
|
|
thd->killed= THD::NOT_KILLED; // Some errors set thd->killed
|
|
|
|
// (e.g. "bad data").
|
|
|
|
|
|
|
|
/* Return IP of the activated SQL handler. */
|
|
|
|
*ip= m_handler[m_hfound].handler;
|
|
|
|
|
|
|
|
/* Reset found handler. */
|
|
|
|
m_hfound= -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2008-01-23 21:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sp_rcontext::exit_handler()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_rcontext::exit_handler");
|
|
|
|
DBUG_ASSERT(m_ihsp);
|
2010-07-30 17:28:36 +02:00
|
|
|
|
2009-09-10 11:18:29 +02:00
|
|
|
uint hindex= m_in_handler[m_ihsp-1].index;
|
|
|
|
m_raised_conditions[hindex].clear();
|
2008-01-23 21:26:41 +01:00
|
|
|
m_ihsp-= 1;
|
2010-07-30 17:28:36 +02:00
|
|
|
|
2008-01-23 21:26:41 +01:00
|
|
|
DBUG_PRINT("info", ("m_ihsp: %d", m_ihsp));
|
|
|
|
DBUG_VOID_RETURN;
|
2003-10-10 16:57:21 +02:00
|
|
|
}
|
|
|
|
|
2012-10-04 16:15:13 +02:00
|
|
|
Sql_condition_info* sp_rcontext::raised_condition() const
|
2009-09-10 11:18:29 +02:00
|
|
|
{
|
|
|
|
if (m_ihsp > 0)
|
|
|
|
{
|
|
|
|
uint hindex= m_in_handler[m_ihsp - 1].index;
|
2012-10-04 16:15:13 +02:00
|
|
|
Sql_condition_info *raised= & m_raised_conditions[hindex];
|
2009-09-10 11:18:29 +02:00
|
|
|
return raised;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_prev_runtime_ctx)
|
|
|
|
return m_prev_runtime_ctx->raised_condition();
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
int
|
2006-05-15 12:01:55 +02:00
|
|
|
sp_rcontext::set_variable(THD *thd, uint var_idx, Item **value)
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
|
|
|
return set_variable(thd, m_var_table->field[var_idx], value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2006-05-15 12:01:55 +02:00
|
|
|
sp_rcontext::set_variable(THD *thd, Field *field, Item **value)
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
|
|
|
if (!value)
|
|
|
|
{
|
|
|
|
field->set_null();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sp_eval_expr(thd, field, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Item *
|
|
|
|
sp_rcontext::get_item(uint var_idx)
|
|
|
|
{
|
|
|
|
return m_var_items[var_idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Item **
|
|
|
|
sp_rcontext::get_item_addr(uint var_idx)
|
|
|
|
{
|
|
|
|
return m_var_items + var_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* sp_cursor
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-06-30 18:07:06 +02:00
|
|
|
sp_cursor::sp_cursor(sp_lex_keeper *lex_keeper, sp_instr_cpush *i)
|
2005-09-22 00:11:21 +02:00
|
|
|
:m_lex_keeper(lex_keeper),
|
|
|
|
server_side_cursor(NULL),
|
2005-06-30 18:07:06 +02:00
|
|
|
m_i(i)
|
2005-06-14 21:45:48 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
currsor can't be stored in QC, so we should prevent opening QC for
|
|
|
|
try to write results which are absent.
|
|
|
|
*/
|
|
|
|
lex_keeper->disable_query_cache();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-05 16:01:20 +02:00
|
|
|
/*
|
2005-09-22 00:11:21 +02:00
|
|
|
Open an SP cursor
|
2005-06-05 16:01:20 +02:00
|
|
|
|
|
|
|
SYNOPSIS
|
2005-09-22 00:11:21 +02:00
|
|
|
open()
|
|
|
|
THD Thread handler
|
2005-06-05 16:01:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
RETURN
|
2005-09-22 00:11:21 +02:00
|
|
|
0 in case of success, -1 otherwise
|
2005-06-05 16:01:20 +02:00
|
|
|
*/
|
|
|
|
|
2005-09-22 00:11:21 +02:00
|
|
|
int
|
|
|
|
sp_cursor::open(THD *thd)
|
2003-10-10 16:57:21 +02:00
|
|
|
{
|
2005-09-22 00:11:21 +02:00
|
|
|
if (server_side_cursor)
|
2003-10-10 16:57:21 +02:00
|
|
|
{
|
2004-11-12 13:34:00 +01:00
|
|
|
my_message(ER_SP_CURSOR_ALREADY_OPEN, ER(ER_SP_CURSOR_ALREADY_OPEN),
|
|
|
|
MYF(0));
|
2005-09-22 00:11:21 +02:00
|
|
|
return -1;
|
2003-10-10 16:57:21 +02:00
|
|
|
}
|
2010-07-27 14:42:36 +02:00
|
|
|
if (mysql_open_cursor(thd, &result, &server_side_cursor))
|
2005-09-22 00:11:21 +02:00
|
|
|
return -1;
|
|
|
|
return 0;
|
2003-10-10 16:57:21 +02:00
|
|
|
}
|
|
|
|
|
2005-06-05 16:01:20 +02:00
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
int
|
|
|
|
sp_cursor::close(THD *thd)
|
|
|
|
{
|
2005-09-22 00:11:21 +02:00
|
|
|
if (! server_side_cursor)
|
2003-10-10 16:57:21 +02:00
|
|
|
{
|
2004-11-12 13:34:00 +01:00
|
|
|
my_message(ER_SP_CURSOR_NOT_OPEN, ER(ER_SP_CURSOR_NOT_OPEN), MYF(0));
|
2003-10-10 16:57:21 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
destroy();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-05 16:01:20 +02:00
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
void
|
|
|
|
sp_cursor::destroy()
|
|
|
|
{
|
2005-09-22 00:11:21 +02:00
|
|
|
delete server_side_cursor;
|
|
|
|
server_side_cursor= 0;
|
2003-10-10 16:57:21 +02:00
|
|
|
}
|
|
|
|
|
2005-09-22 00:11:21 +02:00
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
int
|
2006-04-07 16:53:15 +02:00
|
|
|
sp_cursor::fetch(THD *thd, List<struct sp_variable> *vars)
|
2003-10-10 16:57:21 +02:00
|
|
|
{
|
2005-09-22 00:11:21 +02:00
|
|
|
if (! server_side_cursor)
|
2003-10-10 16:57:21 +02:00
|
|
|
{
|
2004-11-12 13:34:00 +01:00
|
|
|
my_message(ER_SP_CURSOR_NOT_OPEN, ER(ER_SP_CURSOR_NOT_OPEN), MYF(0));
|
2003-10-10 16:57:21 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2005-09-22 00:11:21 +02:00
|
|
|
if (vars->elements != result.get_field_count())
|
2003-10-10 16:57:21 +02:00
|
|
|
{
|
2005-09-22 00:11:21 +02:00
|
|
|
my_message(ER_SP_WRONG_NO_OF_FETCH_ARGS,
|
|
|
|
ER(ER_SP_WRONG_NO_OF_FETCH_ARGS), MYF(0));
|
2003-10-10 16:57:21 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-07-30 17:28:36 +02:00
|
|
|
DBUG_EXECUTE_IF("bug23032_emit_warning",
|
|
|
|
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_UNKNOWN_ERROR,
|
|
|
|
ER(ER_UNKNOWN_ERROR)););
|
|
|
|
|
2005-09-22 00:11:21 +02:00
|
|
|
result.set_spvar_list(vars);
|
2005-05-23 23:43:43 +02:00
|
|
|
|
2005-09-22 00:11:21 +02:00
|
|
|
/* Attempt to fetch one row */
|
|
|
|
if (server_side_cursor->is_open())
|
|
|
|
server_side_cursor->fetch(1);
|
2005-05-23 23:43:43 +02:00
|
|
|
|
2005-09-22 00:11:21 +02:00
|
|
|
/*
|
|
|
|
If the cursor was pointing after the last row, the fetch will
|
|
|
|
close it instead of sending any rows.
|
|
|
|
*/
|
|
|
|
if (! server_side_cursor->is_open())
|
2003-10-10 16:57:21 +02:00
|
|
|
{
|
2005-09-22 00:11:21 +02:00
|
|
|
my_message(ER_SP_FETCH_NO_DATA, ER(ER_SP_FETCH_NO_DATA), MYF(0));
|
2003-10-10 16:57:21 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2005-09-22 00:11:21 +02:00
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2005-09-22 00:11:21 +02:00
|
|
|
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
/*
|
|
|
|
Create an instance of appropriate Item_cache class depending on the
|
|
|
|
specified type in the callers arena.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
thd thread handler
|
|
|
|
result_type type of the expression
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
Pointer to valid object on success
|
|
|
|
NULL on error
|
|
|
|
|
|
|
|
NOTE
|
|
|
|
We should create cache items in the callers arena, as they are used
|
|
|
|
between in several instructions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Item_cache *
|
2007-11-10 20:44:48 +01:00
|
|
|
sp_rcontext::create_case_expr_holder(THD *thd, const Item *item)
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
|
|
|
Item_cache *holder;
|
|
|
|
Query_arena current_arena;
|
|
|
|
|
|
|
|
thd->set_n_backup_active_arena(thd->spcont->callers_arena, ¤t_arena);
|
|
|
|
|
2007-11-10 20:44:48 +01:00
|
|
|
holder= Item_cache::get_cache(item);
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
thd->restore_active_arena(thd->spcont->callers_arena, ¤t_arena);
|
|
|
|
|
|
|
|
return holder;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Set CASE expression to the specified value.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
thd thread handler
|
|
|
|
case_expr_id identifier of the CASE expression
|
|
|
|
case_expr_item a value of the CASE expression
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
FALSE on success
|
|
|
|
TRUE on error
|
|
|
|
|
|
|
|
NOTE
|
|
|
|
The idea is to reuse Item_cache for the expression of the one CASE
|
|
|
|
statement. This optimization takes place when there is CASE statement
|
|
|
|
inside of a loop. So, in other words, we will use the same object on each
|
|
|
|
iteration instead of creating a new one for each iteration.
|
|
|
|
|
|
|
|
TODO
|
|
|
|
Hypothetically, a type of CASE expression can be different for each
|
|
|
|
iteration. For instance, this can happen if the expression contains a
|
|
|
|
session variable (something like @@VAR) and its type is changed from one
|
|
|
|
iteration to another.
|
|
|
|
|
|
|
|
In order to cope with this problem, we check type each time, when we use
|
|
|
|
already created object. If the type does not match, we re-create Item.
|
|
|
|
This also can (should?) be optimized.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2006-05-15 12:01:55 +02:00
|
|
|
sp_rcontext::set_case_expr(THD *thd, int case_expr_id, Item **case_expr_item_ptr)
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
2006-05-15 12:01:55 +02:00
|
|
|
Item *case_expr_item= sp_prepare_func_item(thd, case_expr_item_ptr);
|
|
|
|
if (!case_expr_item)
|
2005-12-07 15:01:17 +01:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!m_case_expr_holders[case_expr_id] ||
|
|
|
|
m_case_expr_holders[case_expr_id]->result_type() !=
|
|
|
|
case_expr_item->result_type())
|
|
|
|
{
|
|
|
|
m_case_expr_holders[case_expr_id]=
|
2007-11-10 20:44:48 +01:00
|
|
|
create_case_expr_holder(thd, case_expr_item);
|
2005-12-07 15:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
m_case_expr_holders[case_expr_id]->store(case_expr_item);
|
2009-11-06 20:34:25 +01:00
|
|
|
m_case_expr_holders[case_expr_id]->cache_value();
|
2005-12-07 15:01:17 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Item *
|
|
|
|
sp_rcontext::get_case_expr(int case_expr_id)
|
|
|
|
{
|
|
|
|
return m_case_expr_holders[case_expr_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Item **
|
|
|
|
sp_rcontext::get_case_expr_addr(int case_expr_id)
|
|
|
|
{
|
|
|
|
return (Item**) m_case_expr_holders + case_expr_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-22 00:11:21 +02:00
|
|
|
/***************************************************************************
|
|
|
|
Select_fetch_into_spvars
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int Select_fetch_into_spvars::prepare(List<Item> &fields, SELECT_LEX_UNIT *u)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Cache the number of columns in the result set in order to easily
|
|
|
|
return an error if column count does not match value count.
|
|
|
|
*/
|
|
|
|
field_count= fields.elements;
|
|
|
|
return select_result_interceptor::prepare(fields, u);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Select_fetch_into_spvars::send_data(List<Item> &items)
|
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
List_iterator_fast<struct sp_variable> spvar_iter(*spvar_list);
|
2005-09-22 00:11:21 +02:00
|
|
|
List_iterator_fast<Item> item_iter(items);
|
2006-04-07 16:53:15 +02:00
|
|
|
sp_variable_t *spvar;
|
2005-09-22 00:11:21 +02:00
|
|
|
Item *item;
|
|
|
|
|
|
|
|
/* Must be ensured by the caller */
|
|
|
|
DBUG_ASSERT(spvar_list->elements == items.elements);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Assign the row fetched from a server side cursor to stored
|
|
|
|
procedure variables.
|
|
|
|
*/
|
2006-04-07 16:53:15 +02:00
|
|
|
for (; spvar= spvar_iter++, item= item_iter++; )
|
2005-09-22 00:11:21 +02:00
|
|
|
{
|
2006-05-15 12:01:55 +02:00
|
|
|
if (thd->spcont->set_variable(thd, spvar->offset, &item))
|
2005-12-07 15:01:17 +01:00
|
|
|
return TRUE;
|
2005-09-22 00:11:21 +02:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|