Skip to content

Commit

Permalink
Fix output param values in stored procedures where the parameter name…
Browse files Browse the repository at this point in the history
…s are case sensitive

Currently, if the argument names in the procedure are in mixed case, the OUTPUT params are not being set properly. This changes fixes the same.

Issues Resolved
BABEL-4235

Signed-off-by: Sai Rohan Basa [email protected]
  • Loading branch information
basasairohan committed Oct 10, 2023
1 parent 8e8e212 commit f6e0e20
Show file tree
Hide file tree
Showing 3 changed files with 383 additions and 0 deletions.
24 changes: 24 additions & 0 deletions contrib/babelfishpg_tsql/src/pl_exec-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,30 @@ exec_stmt_exec(PLtsql_execstate *estate, PLtsql_stmt_exec *stmt)
(argmodes[i] == PROARGMODE_INOUT ||
argmodes[i] == PROARGMODE_OUT))
{
ListCell *paramcell;
relativeArgIndex = 0;

/*
* The order of arguments in procedure call might be different from the order of
* arguments in the funcargs.
* For each argument in funcargs, find corresponding argument in stmt->params.
*/
foreach(paramcell, stmt->params)
{
tsql_exec_param *p = (tsql_exec_param *) lfirst(paramcell);
if (argnames[i] && p->name && pg_strcasecmp(argnames[i], p->name) == 0)
break;
relativeArgIndex++;
}

/*
* If argnames[i] is not found in stmt->params, i th parameter is passed in
* 'value' format instead of '@name = value'. In this case, argnames[i] should be mapped
* to i th element in stmt->params.
*/
if (relativeArgIndex >= stmt->paramno)
relativeArgIndex = i;

if (parammodes &&
parammodes[i] != PROARGMODE_INOUT &&
parammodes[i] != PROARGMODE_OUT)
Expand Down
317 changes: 317 additions & 0 deletions test/JDBC/expected/TestStoredProcedures.out
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,320 @@ DROP PROCEDURE sp_test14
#storedproc#!#prep#!#sp_test19#!#uniqueidentifier|-|a|-|5b7c2e8d-6d90-411d-8e19-9a81067e6f6c|-|output
#storedproc#!#prep#!#sp_test19#!#uniqueidentifier|-|a|-|5b7c2e8d-6d90-411d-8e19-9a81067e6f6c|-|inputoutput
#DROP PROCEDURE sp_test19

CREATE PROCEDURE sp_test20 (@a INT, @b INT OUTPUT) AS BEGIN SET @b=100; SET @a=1000; Select @a as a, @b as b; END;
Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @b=@b OUT, @a=@a;select @a as a, @b as b;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#100
~~END~~

Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @b=@b, @a=@a OUT;select @a as a, @b as b;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#10
~~END~~

Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @b=@b OUT, @a=@a OUT;select @a as a, @b as b;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#100
~~END~~

Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @b=@b, @a=@a;select @a as a, @b as b;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#10
~~END~~

Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @a=@a, @b=@b;select @a as a, @b as b;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#10
~~END~~

Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @a=@a, @b=@b OUT;select @a as a, @b as b;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#100
~~END~~

Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @a=@a OUT, @b=@b;select @a as a, @b as b;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#10
~~END~~

Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @a=@a OUT, @b=@b OUT;select @a as a, @b as b;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#100
~~END~~

Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @a OUT, @b OUT;select @a as a, @b as b;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#100
~~END~~

storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|output
~~START~~
int#!#int
1000#!#100
~~END~~

storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|output#!#int|-|b|-|10|-|input
~~START~~
int#!#int
1000#!#100
~~END~~

storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|input
~~START~~
int#!#int
1000#!#100
~~END~~

storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|output#!#int|-|b|-|10|-|output
~~START~~
int#!#int
1000#!#100
~~END~~

storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|inputoutput#!#int|-|b|-|10|-|inputoutput
~~START~~
int#!#int
1000#!#100
~~END~~

storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|inputoutput
~~START~~
int#!#int
1000#!#100
~~END~~

storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|inputoutput#!#int|-|b|-|10|-|input
~~START~~
int#!#int
1000#!#100
~~END~~

DROP PROCEDURE sp_test20

CREATE PROCEDURE sp_test21 (@a INT, @b INT OUTPUT, @d INT, @c INT OUTPUT) AS BEGIN SET @a=100; SET @b=200; SET @c=300; SET @d=400; Select @a as a, @b as b, @c as c, @d as d; END;
Declare @a int;Declare @b int;Declare @c int;Declare @d int;Set @a=20;Set @b=10;Set @c=5;Set @d=30; exec sp_test21 @b=@b OUT, @c=@c OUT, @a=@a, @d=@d; Select @a as a, @b as b, @c as c, @d as d;
~~START~~
int#!#int#!#int#!#int
100#!#200#!#300#!#400
~~END~~

~~START~~
int#!#int#!#int#!#int
20#!#200#!#300#!#30
~~END~~

Declare @a int;Declare @b int;Declare @c int;Declare @d int;Set @a=20;Set @b=10;Set @c=5;Set @d=30; exec sp_test21 @b=@b, @c=@c, @a=@a, @d=@d; Select @a as a, @b as b, @c as c, @d as d;
~~START~~
int#!#int#!#int#!#int
100#!#200#!#300#!#400
~~END~~

~~START~~
int#!#int#!#int#!#int
20#!#10#!#5#!#30
~~END~~

Declare @a int;Declare @b int;Declare @c int;Declare @d int;Set @a=20;Set @b=10;Set @c=5;Set @d=30; exec sp_test21 @c=@c OUT, @b=@b OUT, @a=@a, @d=@d; Select @a as a, @b as b, @c as c, @d as d;
~~START~~
int#!#int#!#int#!#int
100#!#200#!#300#!#400
~~END~~

~~START~~
int#!#int#!#int#!#int
20#!#200#!#300#!#30
~~END~~

Declare @a int;Declare @b int;Declare @c int;Declare @d int;Set @a=20;Set @b=10;Set @c=5;Set @d=30; exec sp_test21 @c=@c, @b=@b, @a=@a OUT, @d=@d OUT; Select @a as a, @b as b, @c as c, @d as d;
~~START~~
int#!#int#!#int#!#int
100#!#200#!#300#!#400
~~END~~

~~START~~
int#!#int#!#int#!#int
20#!#10#!#5#!#30
~~END~~

storedproc#!#prep#!#sp_test21#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|inputoutput#!#int|-|c|-|10|-|input#!#int|-|d|-|10|-|inputoutput
~~START~~
int#!#int#!#int#!#int
100#!#200#!#300#!#400
~~END~~

storedproc#!#prep#!#sp_test21#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|output#!#int|-|c|-|10|-|input#!#int|-|d|-|10|-|output
~~START~~
int#!#int#!#int#!#int
100#!#200#!#300#!#400
~~END~~

storedproc#!#prep#!#sp_test21#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|output#!#int|-|c|-|10|-|input#!#int|-|d|-|10|-|inputoutput
~~START~~
int#!#int#!#int#!#int
100#!#200#!#300#!#400
~~END~~

storedproc#!#prep#!#sp_test21#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|inputoutput#!#int|-|c|-|10|-|input#!#int|-|d|-|10|-|output
~~START~~
int#!#int#!#int#!#int
100#!#200#!#300#!#400
~~END~~

DROP PROCEDURE sp_test21

CREATE PROCEDURE sp_test22 (@MixedCaseArg_1 INT, @MixedCaseArg_2 INT OUTPUT) AS BEGIN SET @MixedCaseArg_2=100; SET @MixedCaseArg_1=1000; Select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2; END;
Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_2=@MixedCaseArg_2 OUT, @MixedCaseArg_1=@MixedCaseArg_1;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#100
~~END~~

Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_2=@MixedCaseArg_2, @MixedCaseArg_1=@MixedCaseArg_1 OUT;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#10
~~END~~

Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_2=@MixedCaseArg_2 OUT, @MixedCaseArg_1=@MixedCaseArg_1 OUT;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#100
~~END~~

Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_2=@MixedCaseArg_2, @MixedCaseArg_1=@MixedCaseArg_1;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#10
~~END~~

Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_1=@MixedCaseArg_1, @MixedCaseArg_2=@MixedCaseArg_2;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#10
~~END~~

Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_1=@MixedCaseArg_1, @MixedCaseArg_2=@MixedCaseArg_2 OUT;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#100
~~END~~

Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_1=@MixedCaseArg_1 OUT, @MixedCaseArg_2=@MixedCaseArg_2;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#10
~~END~~

Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_1=@MixedCaseArg_1 OUT, @MixedCaseArg_2=@MixedCaseArg_2 OUT;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#100
~~END~~

Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_1 OUT, @MixedCaseArg_2 OUT;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
~~START~~
int#!#int
1000#!#100
~~END~~

~~START~~
int#!#int
20#!#100
~~END~~

DROP PROCEDURE sp_test22
42 changes: 42 additions & 0 deletions test/JDBC/input/storedProcedures/TestStoredProcedures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,45 @@ DROP PROCEDURE sp_test14
#storedproc#!#prep#!#sp_test19#!#uniqueidentifier|-|a|-|5b7c2e8d-6d90-411d-8e19-9a81067e6f6c|-|output
#storedproc#!#prep#!#sp_test19#!#uniqueidentifier|-|a|-|5b7c2e8d-6d90-411d-8e19-9a81067e6f6c|-|inputoutput
#DROP PROCEDURE sp_test19

CREATE PROCEDURE sp_test20 (@a INT, @b INT OUTPUT) AS BEGIN SET @b=100; SET @a=1000; Select @a as a, @b as b; END;
Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @b=@b OUT, @a=@a;select @a as a, @b as b;
Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @b=@b, @a=@a OUT;select @a as a, @b as b;
Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @b=@b OUT, @a=@a OUT;select @a as a, @b as b;
Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @b=@b, @a=@a;select @a as a, @b as b;
Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @a=@a, @b=@b;select @a as a, @b as b;
Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @a=@a, @b=@b OUT;select @a as a, @b as b;
Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @a=@a OUT, @b=@b;select @a as a, @b as b;
Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @a=@a OUT, @b=@b OUT;select @a as a, @b as b;
Declare @a int;Declare @b int;Set @a=20;Set @b=10; exec sp_test20 @a OUT, @b OUT;select @a as a, @b as b;
storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|output
storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|output#!#int|-|b|-|10|-|input
storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|input
storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|output#!#int|-|b|-|10|-|output
storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|inputoutput#!#int|-|b|-|10|-|inputoutput
storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|inputoutput
storedproc#!#prep#!#sp_test20#!#int|-|a|-|20|-|inputoutput#!#int|-|b|-|10|-|input
DROP PROCEDURE sp_test20

CREATE PROCEDURE sp_test21 (@a INT, @b INT OUTPUT, @d INT, @c INT OUTPUT) AS BEGIN SET @a=100; SET @b=200; SET @c=300; SET @d=400; Select @a as a, @b as b, @c as c, @d as d; END;
Declare @a int;Declare @b int;Declare @c int;Declare @d int;Set @a=20;Set @b=10;Set @c=5;Set @d=30; exec sp_test21 @b=@b OUT, @c=@c OUT, @a=@a, @d=@d; Select @a as a, @b as b, @c as c, @d as d;
Declare @a int;Declare @b int;Declare @c int;Declare @d int;Set @a=20;Set @b=10;Set @c=5;Set @d=30; exec sp_test21 @b=@b, @c=@c, @a=@a, @d=@d; Select @a as a, @b as b, @c as c, @d as d;
Declare @a int;Declare @b int;Declare @c int;Declare @d int;Set @a=20;Set @b=10;Set @c=5;Set @d=30; exec sp_test21 @c=@c OUT, @b=@b OUT, @a=@a, @d=@d; Select @a as a, @b as b, @c as c, @d as d;
Declare @a int;Declare @b int;Declare @c int;Declare @d int;Set @a=20;Set @b=10;Set @c=5;Set @d=30; exec sp_test21 @c=@c, @b=@b, @a=@a OUT, @d=@d OUT; Select @a as a, @b as b, @c as c, @d as d;
storedproc#!#prep#!#sp_test21#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|inputoutput#!#int|-|c|-|10|-|input#!#int|-|d|-|10|-|inputoutput
storedproc#!#prep#!#sp_test21#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|output#!#int|-|c|-|10|-|input#!#int|-|d|-|10|-|output
storedproc#!#prep#!#sp_test21#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|output#!#int|-|c|-|10|-|input#!#int|-|d|-|10|-|inputoutput
storedproc#!#prep#!#sp_test21#!#int|-|a|-|20|-|input#!#int|-|b|-|10|-|inputoutput#!#int|-|c|-|10|-|input#!#int|-|d|-|10|-|output
DROP PROCEDURE sp_test21

CREATE PROCEDURE sp_test22 (@MixedCaseArg_1 INT, @MixedCaseArg_2 INT OUTPUT) AS BEGIN SET @MixedCaseArg_2=100; SET @MixedCaseArg_1=1000; Select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2; END;
Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_2=@MixedCaseArg_2 OUT, @MixedCaseArg_1=@MixedCaseArg_1;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_2=@MixedCaseArg_2, @MixedCaseArg_1=@MixedCaseArg_1 OUT;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_2=@MixedCaseArg_2 OUT, @MixedCaseArg_1=@MixedCaseArg_1 OUT;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_2=@MixedCaseArg_2, @MixedCaseArg_1=@MixedCaseArg_1;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_1=@MixedCaseArg_1, @MixedCaseArg_2=@MixedCaseArg_2;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_1=@MixedCaseArg_1, @MixedCaseArg_2=@MixedCaseArg_2 OUT;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_1=@MixedCaseArg_1 OUT, @MixedCaseArg_2=@MixedCaseArg_2;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_1=@MixedCaseArg_1 OUT, @MixedCaseArg_2=@MixedCaseArg_2 OUT;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
Declare @MixedCaseArg_1 int;Declare @MixedCaseArg_2 int;Set @MixedCaseArg_1=20;Set @MixedCaseArg_2=10; exec sp_test22 @MixedCaseArg_1 OUT, @MixedCaseArg_2 OUT;select @MixedCaseArg_1 as MixedCaseArg_1, @MixedCaseArg_2 as MixedCaseArg_2;
DROP PROCEDURE sp_test22

0 comments on commit f6e0e20

Please sign in to comment.