From b9a4bf8cad2ab4283d3b603846d020044eac2ee0 Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Wed, 23 Apr 2003 22:31:47 +0300 Subject: [PATCH] subselect in procedure argument list (Bug #302) --- .bzrignore | 3 +++ mysql-test/r/subselect.result | 17 +++++++++++++++++ mysql-test/t/subselect.test | 20 ++++++++++++++++++++ sql/sp_head.cc | 6 ++++++ sql/sql_parse.cc | 5 +++++ 5 files changed, 51 insertions(+) diff --git a/.bzrignore b/.bzrignore index b3db91e7c59..213ebc07624 100644 --- a/.bzrignore +++ b/.bzrignore @@ -605,3 +605,6 @@ vio/viotest-ssl myisam/ftbench/var/* myisam/ftbench/data myisam/ftbench/t +libmysqld/sp_pcontext.cc +libmysqld/sp.cc +libmysqld/sp_head.cc diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 3c34e615dab..b34503c34c2 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -887,6 +887,23 @@ do (SELECT a from t1); Table 'test.t1' doesn't exist set @a:=(SELECT a from t1); 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)); HANDLER t1 OPEN; HANDLER t1 READ a=((SELECT 1)); diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 9dd4fba0bd0..3e868fd0add 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -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); drop table t1; +# +# DO & SET +# create table t1 (a int); insert into t1 values (1); do @a:=(SELECT a from t1); @@ -499,6 +502,23 @@ do (SELECT a from t1); -- error 1146 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)); HANDLER t1 OPEN; -- error 1149 diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 2d02f0262f4..ce908afb19f 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -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)); } + // Close tables opened for subselect in argument list + close_thread_tables(thd); + // The rest of the frame are local variables which are all IN. // QQ See comment in execute_procedure below. for (; i < csize ; i++) @@ -283,6 +286,9 @@ sp_head::execute_procedure(THD *thd, List *args) nctx->set_oindex(i, static_cast(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. // 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 diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index b0a183f0711..4b077f4454b 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3060,6 +3060,11 @@ mysql_execute_command(THD *thd) uint 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 // When executing substatements, they're assumed to send_error when // it happens, but not to send_ok.