From 6a9c0a2de1207b45fc60212f77c3f8c4a5ca94da Mon Sep 17 00:00:00 2001 From: Sai Rohan Basa <108261379+basasairohan@users.noreply.github.com> Date: Thu, 1 Feb 2024 19:51:47 +0530 Subject: [PATCH] Handle empty procedure_schema case in sp_procedure_params_100_managed procedure (#2327) (#2328) Description If the procedure_schema argument in the sp_procedure_params_100_managed procedure is empty, we should return procedure metadata from the user's default schema. But, currently we return no rows in this case. This commit resolves the above issue. Issues Resolved BABEL-3254 Signed-off-by: Sai Rohan Basa bsrohan@amazon.com --- .../babelfishpg_tsql/sql/babelfishpg_tsql.sql | 2 +- .../babelfishpg_tsql--4.0.0--4.1.0.sql | 2 +- test/JDBC/expected/babel-3254-vu-verify.out | 179 ++++++++++++++++++ test/JDBC/input/babel-3254-vu-verify.mix | 63 ++++++ 4 files changed, 244 insertions(+), 2 deletions(-) diff --git a/contrib/babelfishpg_tsql/sql/babelfishpg_tsql.sql b/contrib/babelfishpg_tsql/sql/babelfishpg_tsql.sql index 87eafeb5a3..345876d7c2 100644 --- a/contrib/babelfishpg_tsql/sql/babelfishpg_tsql.sql +++ b/contrib/babelfishpg_tsql/sql/babelfishpg_tsql.sql @@ -3666,7 +3666,7 @@ CREATE OR REPLACE PROCEDURE sys.sp_procedure_params_100_managed(IN "@procedure_n IN "@parameter_name" sys.sysname DEFAULT NULL) AS $$ BEGIN - IF @procedure_schema IS NULL + IF @procedure_schema IS NULL OR @procedure_schema = '' BEGIN SELECT @procedure_schema = default_schema_name from sys.babelfish_authid_user_ext WHERE orig_username = user_name() AND database_name = db_name(); END diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.0.0--4.1.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.0.0--4.1.0.sql index 893e428b99..755e52b86a 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.0.0--4.1.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--4.0.0--4.1.0.sql @@ -2780,7 +2780,7 @@ CREATE OR REPLACE PROCEDURE sys.sp_procedure_params_100_managed(IN "@procedure_n IN "@parameter_name" sys.sysname DEFAULT NULL) AS $$ BEGIN - IF @procedure_schema IS NULL + IF @procedure_schema IS NULL OR @procedure_schema = '' BEGIN SELECT @procedure_schema = default_schema_name from sys.babelfish_authid_user_ext WHERE orig_username = user_name() AND database_name = db_name(); END diff --git a/test/JDBC/expected/babel-3254-vu-verify.out b/test/JDBC/expected/babel-3254-vu-verify.out index bc816b3f26..08fa2df41c 100644 --- a/test/JDBC/expected/babel-3254-vu-verify.out +++ b/test/JDBC/expected/babel-3254-vu-verify.out @@ -1,3 +1,182 @@ +sp_procedure_params_100_managed NULL +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed '' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed 'bABEl_3254_p1' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +@RETURN_VALUE#!#4#!#8#!##!#10#!##!##!##!#int#!##!##!##!# +@a#!#1#!#8#!##!#10#!##!##!##!#int#!##!##!##!# +@b#!#1#!#0#!##!#19#!##!##!##!#bigint#!##!##!##!# +@c#!#2#!#16#!##!#5#!##!##!##!#smallint#!##!##!##!# +@d#!#1#!#20#!##!#3#!##!##!##!#tinyint#!##!##!##!# +@e#!#1#!#2#!##!##!##!##!##!#bit#!##!##!##!# +@f#!#2#!#6#!##!#53#!##!##!##!#float#!##!##!##!# +@g#!#1#!#13#!##!#24#!##!##!##!#real#!##!##!##!# +~~END~~ + + +sp_procedure_params_100_managed 'invalid_name' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed 'babel_3254_p1 ' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +@RETURN_VALUE#!#4#!#8#!##!#10#!##!##!##!#int#!##!##!##!# +@a#!#1#!#8#!##!#10#!##!##!##!#int#!##!##!##!# +@b#!#1#!#0#!##!#19#!##!##!##!#bigint#!##!##!##!# +@c#!#2#!#16#!##!#5#!##!##!##!#smallint#!##!##!##!# +@d#!#1#!#20#!##!#3#!##!##!##!#tinyint#!##!##!##!# +@e#!#1#!#2#!##!##!##!##!##!#bit#!##!##!##!# +@f#!#2#!#6#!##!#53#!##!##!##!#float#!##!##!##!# +@g#!#1#!#13#!##!#24#!##!##!##!#real#!##!##!##!# +~~END~~ + + +sp_procedure_params_100_managed ' babel_3254_p1' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed 'babel_ 3254_p1' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema=NULL +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p1', @group_number=1, @procedure_schema='' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +@RETURN_VALUE#!#4#!#8#!##!#10#!##!##!##!#int#!##!##!##!# +@a#!#1#!#8#!##!#10#!##!##!##!#int#!##!##!##!# +@b#!#1#!#0#!##!#19#!##!##!##!#bigint#!##!##!##!# +@c#!#2#!#16#!##!#5#!##!##!##!#smallint#!##!##!##!# +@d#!#1#!#20#!##!#3#!##!##!##!#tinyint#!##!##!##!# +@e#!#1#!#2#!##!##!##!##!##!#bit#!##!##!##!# +@f#!#2#!#6#!##!#53#!##!##!##!#float#!##!##!##!# +@g#!#1#!#13#!##!#24#!##!##!##!#real#!##!##!##!# +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='invalid_schema' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema=NULL +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1 ' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +@RETURN_VALUE#!#4#!#8#!##!#10#!##!##!##!#int#!##!##!##!# +@a#!#2#!#9#!##!#19#!##!##!##!#money#!##!##!##!# +@b#!#1#!#17#!##!#10#!##!##!##!#smallmoney#!##!##!##!# +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema=' babel_3254_s1' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_ 3254_s1' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name=NULL +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +@RETURN_VALUE#!#4#!#8#!##!#10#!##!##!##!#int#!##!##!##!# +@a#!#2#!#9#!##!#19#!##!##!##!#money#!##!##!##!# +@b#!#1#!#17#!##!#10#!##!##!##!#smallmoney#!##!##!##!# +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name='' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name='@A' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +@a#!#2#!#9#!##!#19#!##!##!##!#money#!##!##!##!# +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name='@a ' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +@a#!#2#!#9#!##!#19#!##!##!##!#money#!##!##!##!# +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name=' @a' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name='@ a' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name='invalid_name' +go +~~START~~ +varchar#!#smallint#!#smallint#!#int#!#smallint#!#smallint#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#nvarchar#!#int +~~END~~ + + sp_procedure_params_100_managed 'babel_3254_p1' go ~~START~~ diff --git a/test/JDBC/input/babel-3254-vu-verify.mix b/test/JDBC/input/babel-3254-vu-verify.mix index 2a89f240c2..8bf12cffa7 100644 --- a/test/JDBC/input/babel-3254-vu-verify.mix +++ b/test/JDBC/input/babel-3254-vu-verify.mix @@ -1,3 +1,66 @@ +sp_procedure_params_100_managed NULL +go + +sp_procedure_params_100_managed '' +go + +sp_procedure_params_100_managed 'bABEl_3254_p1' +go + +sp_procedure_params_100_managed 'invalid_name' +go + +sp_procedure_params_100_managed 'babel_3254_p1 ' +go + +sp_procedure_params_100_managed ' babel_3254_p1' +go + +sp_procedure_params_100_managed 'babel_ 3254_p1' +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema=NULL +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p1', @group_number=1, @procedure_schema='' +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='invalid_schema' +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema=NULL +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1 ' +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema=' babel_3254_s1' +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_ 3254_s1' +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name=NULL +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name='' +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name='@A' +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name='@a ' +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name=' @a' +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name='@ a' +go + +sp_procedure_params_100_managed @procedure_name='babel_3254_p6', @group_number=1, @procedure_schema='babel_3254_s1', @parameter_name='invalid_name' +go + sp_procedure_params_100_managed 'babel_3254_p1' go