diff --git a/contrib/babelfishpg_tsql/src/iterative_exec.c b/contrib/babelfishpg_tsql/src/iterative_exec.c index 0260442177a..d05d7e27db7 100644 --- a/contrib/babelfishpg_tsql/src/iterative_exec.c +++ b/contrib/babelfishpg_tsql/src/iterative_exec.c @@ -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() */ diff --git a/contrib/babelfishpg_tsql/src/pl_exec-2.c b/contrib/babelfishpg_tsql/src/pl_exec-2.c index d496f905780..c8b58e4ce93 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec-2.c +++ b/contrib/babelfishpg_tsql/src/pl_exec-2.c @@ -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)) { @@ -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); diff --git a/test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out b/test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out index 13cfa0725db..4e806370afc 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out +++ b/test/JDBC/expected/BABEL-CROSS-DB-vu-cleanup.out @@ -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 diff --git a/test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out b/test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out index 60a5a07ca7d..b46e0a470e9 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out +++ b/test/JDBC/expected/BABEL-CROSS-DB-vu-prepare.out @@ -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 + diff --git a/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out b/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out index 9d361d116ea..ccb67035d6a 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out +++ b/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out @@ -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~~ + diff --git a/test/JDBC/expected/BABEL-CROSS-DB.out b/test/JDBC/expected/BABEL-CROSS-DB.out index 1988f774e11..246a2659462 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB.out +++ b/test/JDBC/expected/BABEL-CROSS-DB.out @@ -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 @@ -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 diff --git a/test/JDBC/input/BABEL-CROSS-DB.mix b/test/JDBC/input/BABEL-CROSS-DB.mix index 04e329069a2..1e09ff5462f 100644 --- a/test/JDBC/input/BABEL-CROSS-DB.mix +++ b/test/JDBC/input/BABEL-CROSS-DB.mix @@ -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 @@ -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 diff --git a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix index aa424a4d5f3..4e806370afc 100644 --- a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix +++ b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-cleanup.mix @@ -142,4 +142,7 @@ DROP SCHEMA babel_cross_db_vu_prepare_myschema GO DROP PROCEDURE babel_5448_p2, babel_5448_p1 -GO \ No newline at end of file +GO + +DROP PROC sp_test_babel_5448_1, sp_test_babel_5448_2 +GO diff --git a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix index de6d3ec4adf..24f31d8ecc6 100644 --- a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix +++ b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-prepare.mix @@ -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 ------------------ ------------------------------------------------ diff --git a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix index d717758ddce..8791c20d982 100644 --- a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix +++ b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix @@ -932,3 +932,8 @@ GO EXECUTE dbo.babel_5448_p3; GO + +SELECT db_name() +GO +EXECUTE dbo.sp_test_babel_5448_3; +GO