Skip to content

Commit

Permalink
add some more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tanzeel Khan <[email protected]>
  • Loading branch information
tanscorpio7 committed Feb 4, 2025
1 parent 212b7dd commit 90af8a7
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 6 deletions.
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/src/iterative_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,7 @@ set_search_path_for_pltsql_stmt(PLtsql_stmt *stmt)
{
PLtsql_stmt_exec *execstmt = (PLtsql_stmt_exec *)stmt;

if (execstmt->db_name != NULL && strncmp(execstmt->proc_name, "sp_", 3) == 0 &&
if (strncmp(execstmt->proc_name, "sp_", 3) == 0 &&
(execstmt->schema_name == NULL || strcmp(execstmt->schema_name, "dbo") == 0))
{
/* handled in exec_stmt_exec() */
Expand Down
6 changes: 4 additions & 2 deletions contrib/babelfishpg_tsql/src/pl_exec-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ exec_stmt_exec(PLtsql_execstate *estate, PLtsql_stmt_exec *stmt)

if (IS_TDS_CONN() && strcmp(stmt->proc_name, "sp_describe_first_result_set") != 0)
{
if (stmt->db_name != NULL && strncmp(stmt->proc_name, "sp_", 3) == 0 &&
if (strncmp(stmt->proc_name, "sp_", 3) == 0 &&
(stmt->schema_name == NULL || strcmp(stmt->schema_name, "dbo") == 0))
{

Expand All @@ -879,7 +879,9 @@ exec_stmt_exec(PLtsql_execstate *estate, PLtsql_stmt_exec *stmt)
* should match with set_search_path_for_pltsql_stmt()
*/
char *new_search_path;
set_cur_user_db_and_path(stmt->db_name, false);
if (stmt->db_name != NULL)
set_cur_user_db_and_path(stmt->db_name, false);

new_search_path = psprintf("%s, master_dbo", current_db_search_path);
SetConfigOption("search_path", new_search_path,
PGC_SUSET, PGC_S_SESSION);
Expand Down
3 changes: 3 additions & 0 deletions test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,6 @@ GO

DROP PROCEDURE babel_5448_p2, babel_5448_p1
GO

DROP PROC sp_test_babel_5448_1, sp_test_babel_5448_2
GO
38 changes: 38 additions & 0 deletions test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,41 @@ BEGIN
EXECUTE master.dbo.babel_5448_p2;
END;
GO


------------------------------------------------
--------------- sp_proc cross db ---------------
------------------------------------------------
USE master;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_1 AS
BEGIN
SELECT N'This is correct: master.dbo.sp_test_babel_5448_1'
END;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_2 AS
BEGIN
EXECUTE master..sp_test_babel_5448_1;
EXECUTE sp_test_babel_5448_1;
EXECUTE dbo.sp_test_babel_5448_1;
EXECUTE master.dbo.sp_test_babel_5448_1;
END;
GO

USE my_babel_cross_db_vu_prepare_db1;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_1 AS
BEGIN
SELECT N'This is the incorrect database: my_babel_cross_db_vu_prepare_db1.dbo.sp_test_babel_5448_1';
END;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_3 AS
BEGIN
EXECUTE master.dbo.sp_test_babel_5448_2;
END;
GO

30 changes: 30 additions & 0 deletions test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -1947,3 +1947,33 @@ varchar
This is correct datbase dbname = master
~~END~~


SELECT db_name()
GO
~~START~~
nvarchar
my_babel_cross_db_vu_prepare_db1
~~END~~

EXECUTE dbo.sp_test_babel_5448_3;
GO
~~START~~
nvarchar
This is correct: master.dbo.sp_test_babel_5448_1
~~END~~

~~START~~
nvarchar
This is correct: master.dbo.sp_test_babel_5448_1
~~END~~

~~START~~
nvarchar
This is correct: master.dbo.sp_test_babel_5448_1
~~END~~

~~START~~
nvarchar
This is correct: master.dbo.sp_test_babel_5448_1
~~END~~

62 changes: 61 additions & 1 deletion test/JDBC/expected/BABEL-CROSS-DB.out
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ GO

CREATE PROCEDURE dbo.babel_5448_p1 AS
BEGIN
SELECT 'This is the incorrect database: babel_5448_db2.dbo.sp_test_1';
SELECT 'This is the incorrect database: babel_5448_db2.dbo.sp_test_babel_5448_1';
END;
GO

Expand Down Expand Up @@ -1070,6 +1070,66 @@ This is correct: babel_5448_db1.dbo.babel_5448_p1
~~END~~



------------------------------------------------
--------------- sp_proc cross db ---------------
------------------------------------------------
USE babel_5448_db1;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_1 AS
BEGIN
SELECT N'This is correct: babel_5448_db1.dbo.sp_test_babel_5448_1'
END;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_2 AS
BEGIN
EXECUTE babel_5448_db1..sp_test_babel_5448_1;
EXECUTE sp_test_babel_5448_1;
EXECUTE dbo.sp_test_babel_5448_1;
EXECUTE babel_5448_db1.dbo.sp_test_babel_5448_1;
END;
GO

USE babel_5448_db2;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_1 AS
BEGIN
SELECT N'This is the incorrect database: babel_5448_db2.dbo.sp_test_babel_5448_1';
END;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_3 AS
BEGIN
EXECUTE babel_5448_db1.dbo.sp_test_babel_5448_2;
END;
GO

EXECUTE dbo.sp_test_babel_5448_3;
GO
~~START~~
nvarchar
This is correct: babel_5448_db1.dbo.sp_test_babel_5448_1
~~END~~

~~START~~
nvarchar
This is correct: babel_5448_db1.dbo.sp_test_babel_5448_1
~~END~~

~~START~~
nvarchar
This is correct: babel_5448_db1.dbo.sp_test_babel_5448_1
~~END~~

~~START~~
nvarchar
This is correct: babel_5448_db1.dbo.sp_test_babel_5448_1
~~END~~


USE master
GO
DROP DATABASE babel_5448_db2
Expand Down
42 changes: 41 additions & 1 deletion test/JDBC/input/BABEL-CROSS-DB.mix
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ GO

CREATE PROCEDURE dbo.babel_5448_p1 AS
BEGIN
SELECT 'This is the incorrect database: babel_5448_db2.dbo.sp_test_1';
SELECT 'This is the incorrect database: babel_5448_db2.dbo.sp_test_babel_5448_1';
END;
GO

Expand All @@ -679,6 +679,46 @@ GO
EXECUTE dbo.babel_5448_p3;
GO

------------------------------------------------
--------------- sp_proc cross db ---------------
------------------------------------------------

USE babel_5448_db1;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_1 AS
BEGIN
SELECT N'This is correct: babel_5448_db1.dbo.sp_test_babel_5448_1'
END;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_2 AS
BEGIN
EXECUTE babel_5448_db1..sp_test_babel_5448_1;
EXECUTE sp_test_babel_5448_1;
EXECUTE dbo.sp_test_babel_5448_1;
EXECUTE babel_5448_db1.dbo.sp_test_babel_5448_1;
END;
GO

USE babel_5448_db2;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_1 AS
BEGIN
SELECT N'This is the incorrect database: babel_5448_db2.dbo.sp_test_babel_5448_1';
END;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_3 AS
BEGIN
EXECUTE babel_5448_db1.dbo.sp_test_babel_5448_2;
END;
GO

EXECUTE dbo.sp_test_babel_5448_3;
GO

USE master
GO
DROP DATABASE babel_5448_db2
Expand Down
5 changes: 4 additions & 1 deletion test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,7 @@ DROP SCHEMA babel_cross_db_vu_prepare_myschema
GO

DROP PROCEDURE babel_5448_p2, babel_5448_p1
GO
GO

DROP PROC sp_test_babel_5448_1, sp_test_babel_5448_2
GO
38 changes: 38 additions & 0 deletions test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,43 @@ BEGIN
EXECUTE master.dbo.babel_5448_p2;
END;
GO

------------------------------------------------
--------------- sp_proc cross db ---------------
------------------------------------------------

USE master;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_1 AS
BEGIN
SELECT N'This is correct: master.dbo.sp_test_babel_5448_1'
END;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_2 AS
BEGIN
EXECUTE master..sp_test_babel_5448_1;
EXECUTE sp_test_babel_5448_1;
EXECUTE dbo.sp_test_babel_5448_1;
EXECUTE master.dbo.sp_test_babel_5448_1;
END;
GO

USE my_babel_cross_db_vu_prepare_db1;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_1 AS
BEGIN
SELECT N'This is the incorrect database: my_babel_cross_db_vu_prepare_db1.dbo.sp_test_babel_5448_1';
END;
GO

CREATE PROCEDURE dbo.sp_test_babel_5448_3 AS
BEGIN
EXECUTE master.dbo.sp_test_babel_5448_2;
END;
GO

----------- END OF BABEL-5448 ------------------
------------------------------------------------
5 changes: 5 additions & 0 deletions test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix
Original file line number Diff line number Diff line change
Expand Up @@ -932,3 +932,8 @@ GO

EXECUTE dbo.babel_5448_p3;
GO

SELECT db_name()
GO
EXECUTE dbo.sp_test_babel_5448_3;
GO

0 comments on commit 90af8a7

Please sign in to comment.