Commit b9a4bf8c authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

subselect in procedure argument list (Bug #302)

parent cba91cce
...@@ -605,3 +605,6 @@ vio/viotest-ssl ...@@ -605,3 +605,6 @@ vio/viotest-ssl
myisam/ftbench/var/* myisam/ftbench/var/*
myisam/ftbench/data myisam/ftbench/data
myisam/ftbench/t myisam/ftbench/t
libmysqld/sp_pcontext.cc
libmysqld/sp.cc
libmysqld/sp_head.cc
...@@ -887,6 +887,23 @@ do (SELECT a from t1); ...@@ -887,6 +887,23 @@ do (SELECT a from t1);
Table 'test.t1' doesn't exist Table 'test.t1' doesn't exist
set @a:=(SELECT a from t1); set @a:=(SELECT a from t1);
Table 'test.t1' doesn't exist Table 'test.t1' doesn't exist
create table t1 (a int);
create table t2 (a int);
insert into t2 values (1), (2), (3);
create procedure foo1(x int)
insert into test.t1 values (x);
create function foo2(i int) returns int
return i+1;
call foo1((select max(a) from t2));
select * from t1;
a
3
select foo2((select max(a) from t2));
foo2((select max(a) from t2))
4
drop table t1, t2;
drop procedure foo1;
drop function foo2;
CREATE TABLE t1 (a int, KEY(a)); CREATE TABLE t1 (a int, KEY(a));
HANDLER t1 OPEN; HANDLER t1 OPEN;
HANDLER t1 READ a=((SELECT 1)); HANDLER t1 READ a=((SELECT 1));
......
...@@ -486,6 +486,9 @@ select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a'); ...@@ -486,6 +486,9 @@ select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2); select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
drop table t1; drop table t1;
#
# DO & SET
#
create table t1 (a int); create table t1 (a int);
insert into t1 values (1); insert into t1 values (1);
do @a:=(SELECT a from t1); do @a:=(SELECT a from t1);
...@@ -499,6 +502,23 @@ do (SELECT a from t1); ...@@ -499,6 +502,23 @@ do (SELECT a from t1);
-- error 1146 -- error 1146
set @a:=(SELECT a from t1); set @a:=(SELECT a from t1);
#
# CALL
#
create table t1 (a int);
create table t2 (a int);
insert into t2 values (1), (2), (3);
create procedure foo1(x int)
insert into test.t1 values (x);
create function foo2(i int) returns int
return i+1;
call foo1((select max(a) from t2));
select * from t1;
select foo2((select max(a) from t2));
drop table t1, t2;
drop procedure foo1;
drop function foo2;
CREATE TABLE t1 (a int, KEY(a)); CREATE TABLE t1 (a int, KEY(a));
HANDLER t1 OPEN; HANDLER t1 OPEN;
-- error 1149 -- error 1149
......
...@@ -216,6 +216,9 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, Item **resp) ...@@ -216,6 +216,9 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, Item **resp)
nctx->push_item(eval_func_item(thd, *argp++, pvar->type)); nctx->push_item(eval_func_item(thd, *argp++, pvar->type));
} }
// Close tables opened for subselect in argument list
close_thread_tables(thd);
// The rest of the frame are local variables which are all IN. // The rest of the frame are local variables which are all IN.
// QQ See comment in execute_procedure below. // QQ See comment in execute_procedure below.
for (; i < csize ; i++) for (; i < csize ; i++)
...@@ -283,6 +286,9 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) ...@@ -283,6 +286,9 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
nctx->set_oindex(i, static_cast<Item_splocal *>(it)->get_offset()); nctx->set_oindex(i, static_cast<Item_splocal *>(it)->get_offset());
} }
} }
// Close tables opened for subselect in argument list
close_thread_tables(thd);
// The rest of the frame are local variables which are all IN. // 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, // 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 // so we set it to NULL for now. It's an error to refer to an
......
...@@ -3060,6 +3060,11 @@ mysql_execute_command(THD *thd) ...@@ -3060,6 +3060,11 @@ mysql_execute_command(THD *thd)
uint smrx; uint smrx;
LINT_INIT(smrx); LINT_INIT(smrx);
if (tables && ((res= check_table_access(thd, SELECT_ACL, tables)) ||
(res= open_and_lock_tables(thd,tables))))
break;
fix_tables_pointers(lex->all_selects_list);
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
// When executing substatements, they're assumed to send_error when // When executing substatements, they're assumed to send_error when
// it happens, but not to send_ok. // it happens, but not to send_ok.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment