Commit e0fdbeba authored by unknown's avatar unknown
Browse files

Fixed BUG#9598: stored procedure call within stored procedure

                overwrites IN variable
  and added error checking of variables for [IN]OUT parameters while
  rewriting the out parameter handling.


mysql-test/r/sp-error.result:
  New test case for non-variable argument for [IN]OUT parameters.
  (And changed to qualified names in some other error messages.)
mysql-test/r/sp.result:
  New test case for BUG#9598.
mysql-test/t/sp-error.test:
  New test case for non-variable argument for [IN]OUT parameters.
mysql-test/t/sp.test:
  New test case for BUG#9598.
sql/item.h:
  Need to distinguish between SP local variable items and other items,
  for error checking and [IN]OUT parameter handling.
sql/share/errmsg.txt:
  New error message for non-variable arguments for [IN]OUT parameters in stored procedures.
sql/sp_head.cc:
  Rewrote the [IN]OUT parameter handling in procedure invokation, to make
  it work properly when using user variables in sub-calls.
  Also added error checking for non-variable arguments for such parameters
  (and changed to qualified names for wrong number of arg. errors).
sql/sp_rcontext.cc:
  No need to keep track on the out index for an [IN]OUT parameter any more.
sql/sp_rcontext.h:
  No need to keep track on the out index for an [IN]OUT parameter any more.
parent 1c2c6bba
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -125,13 +125,13 @@ set @x = x|
create function f(x int) returns int
return x+42|
call p()|
ERROR 42000: Incorrect number of arguments for PROCEDURE p; expected 1, got 0
ERROR 42000: Incorrect number of arguments for PROCEDURE test.p; expected 1, got 0
call p(1, 2)|
ERROR 42000: Incorrect number of arguments for PROCEDURE p; expected 1, got 2
ERROR 42000: Incorrect number of arguments for PROCEDURE test.p; expected 1, got 2
select f()|
ERROR 42000: Incorrect number of arguments for FUNCTION f; expected 1, got 0
ERROR 42000: Incorrect number of arguments for FUNCTION test.f; expected 1, got 0
select f(1, 2)|
ERROR 42000: Incorrect number of arguments for FUNCTION f; expected 1, got 2
ERROR 42000: Incorrect number of arguments for FUNCTION test.f; expected 1, got 2
drop procedure p|
drop function f|
create procedure p(val int, out res int)
@@ -318,6 +318,24 @@ select field from t1;
label L1;
end|
ERROR HY000: GOTO is not allowed in a stored procedure handler
drop procedure if exists p|
create procedure p(in x int, inout y int, out z int)
begin
set y = x+y;
set z = x+y;
end|
set @tmp_x = 42|
set @tmp_y = 3|
set @tmp_z = 0|
call p(@tmp_x, @tmp_y, @tmp_z)|
select @tmp_x, @tmp_y, @tmp_z|
@tmp_x	@tmp_y	@tmp_z
42	45	87
call p(42, 43, @tmp_z)|
ERROR 42000: OUT or INOUT argument 2 for routine test.p is not a variable
call p(42, @tmp_y, 43)|
ERROR 42000: OUT or INOUT argument 3 for routine test.p is not a variable
drop procedure p|
create procedure bug1965()
begin
declare c cursor for select val from t1 order by valname;
+28 −0
Original line number Diff line number Diff line
@@ -2908,4 +2908,32 @@ v/10
10.00000
drop procedure bug9674_1|
drop procedure bug9674_2|
drop procedure if exists bug9598_1|
drop procedure if exists bug9598_2|
create procedure bug9598_1(in var_1 char(16),
out var_2 integer, out var_3 integer)
begin
set var_2 = 50;
set var_3 = 60;
end|
create procedure bug9598_2(in v1 char(16),
in v2 integer,
in v3 integer,
in v4 integer,
in v5 integer)
begin
select v1,v2,v3,v4,v5;
call bug9598_1(v1,@tmp1,@tmp2);
select v1,v2,v3,v4,v5;
end|
call bug9598_2('Test',2,3,4,5)|
v1	v2	v3	v4	v5
Test	2	3	4	5
v1	v2	v3	v4	v5
Test	2	3	4	5
select @tmp1, @tmp2|
@tmp1	@tmp2
50	60
drop procedure bug9598_1|
drop procedure bug9598_2|
drop table t1,t2;
+25 −0
Original line number Diff line number Diff line
@@ -410,6 +410,31 @@ begin
  label L1;
end|

# Check in and inout arguments.
--disable_warnings
drop procedure if exists p|
--enable_warnings
create procedure p(in x int, inout y int, out z int)
begin
  set y = x+y;
  set z = x+y;
end|

set @tmp_x = 42|
set @tmp_y = 3|
set @tmp_z = 0|
# For reference: this is ok
call p(@tmp_x, @tmp_y, @tmp_z)|
select @tmp_x, @tmp_y, @tmp_z|

--error ER_SP_NOT_VAR_ARG
call p(42, 43, @tmp_z)|
--error ER_SP_NOT_VAR_ARG
call p(42, @tmp_y, 43)|

drop procedure p|


#
# BUG#1965
#
+32 −0
Original line number Diff line number Diff line
@@ -3571,6 +3571,38 @@ drop procedure bug9674_1|
drop procedure bug9674_2|


#
# BUG#9598: stored procedure call within stored procedure overwrites IN variable
#
--disable_warnings
drop procedure if exists bug9598_1|
drop procedure if exists bug9598_2|
--enable_warnings
create procedure bug9598_1(in var_1 char(16),
                           out var_2 integer, out var_3 integer)
begin
  set var_2 = 50;
  set var_3 = 60;
end|

create procedure bug9598_2(in v1 char(16),
                           in v2 integer,
                           in v3 integer,
                           in v4 integer,
                           in v5 integer)
begin
  select v1,v2,v3,v4,v5;
  call bug9598_1(v1,@tmp1,@tmp2);
  select v1,v2,v3,v4,v5;
end|

call bug9598_2('Test',2,3,4,5)|
select @tmp1, @tmp2|

drop procedure bug9598_1|
drop procedure bug9598_2|


#
# BUG#NNNN: New bug synopsis
#
+4 −0
Original line number Diff line number Diff line
@@ -545,6 +545,8 @@ class Item {
    cleanup();
    delete this;
  }

  virtual bool is_splocal() { return 0; } /* Needed for error checking */
};


@@ -564,6 +566,8 @@ class Item_splocal : public Item
    Item::maybe_null= TRUE;
  }

  bool is_splocal() { return 1; } /* Needed for error checking */

  Item *this_item();
  Item *this_const_item() const;

Loading