diff --git a/contrib/babelfishpg_tsql/src/tsqlIface.cpp b/contrib/babelfishpg_tsql/src/tsqlIface.cpp index 68164d0945..c1ec79ddc6 100644 --- a/contrib/babelfishpg_tsql/src/tsqlIface.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlIface.cpp @@ -1857,6 +1857,7 @@ class tsqlBuilder : public tsqlCommonMutator graft(makeSQL(ctx), peekContainer()); } + is_cross_db = false; // prepare rewriting clear_rewritten_query_fragment(); PLtsql_stmt_execsql *stmt = (PLtsql_stmt_execsql *) getPLtsql_fragment(ctx); @@ -1917,10 +1918,7 @@ class tsqlBuilder : public tsqlCommonMutator // record whether stmt is cross-db if (is_cross_db) - { stmt->is_cross_db = true; - is_cross_db = false; - } // record that the stmt is dml stmt->is_dml = true; // record if a function call diff --git a/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out b/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out index e6ce019ca7..9f7dd29e74 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out +++ b/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out @@ -1425,6 +1425,113 @@ int DROP TABLE #babel_cross_db_vu_verify_tempt; GO +-- tsql +-- Batches for testing default_database and default_schema setting +USE master; +GO + +CREATE LOGIN babel_cross_db_vu_verify_lgn1 WITH PASSWORD = '12345678'; +GO + +CREATE USER babel_cross_db_vu_verify_master_user_with_def_sch FOR login babel_cross_db_vu_verify_lgn1 WITH default_schema = babel_cross_db_vu_prepare_s1; +GO + +GRANT SELECT ON babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_t1 TO babel_cross_db_vu_verify_master_user_with_def_sch; +GO + +USE my_babel_cross_db_vu_prepare_db1; +GO + +CREATE USER babel_cross_db_vu_verify_db1_user_with_def_sch FOR LOGIN babel_cross_db_vu_verify_lgn1 WITH default_schema = babel_cross_db_vu_prepare_s2; +GO + +GRANT SELECT ON babel_cross_db_vu_prepare_s2.babel_cross_db_vu_prepare_t2 TO babel_cross_db_vu_verify_db1_user_with_def_sch; +GO + +-- tsql user=babel_cross_db_vu_verify_lgn1 password=12345678 +USE master; +GO + +-- TODO: Fix BABEL-5050 +SELECT * FROM babel_cross_db_vu_prepare_t1; SELECT * FROM my_babel_cross_db_vu_prepare_db1..babel_cross_db_vu_prepare_t2; +GO +~~START~~ +int#!#varchar +1#!#def +~~END~~ + +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: permission denied for table babel_cross_db_vu_prepare_t2)~~ + + +SELECT * FROM babel_cross_db_vu_prepare_t1; SELECT * FROM my_babel_cross_db_vu_prepare_db1.babel_cross_db_vu_prepare_s2.babel_cross_db_vu_prepare_t2; +GO +~~START~~ +int#!#varchar +1#!#def +~~END~~ + +~~START~~ +int#!#varchar +1#!#abc +~~END~~ + + +USE my_babel_cross_db_vu_prepare_db1; +GO + +-- TODO: Fix BABEL-5050 +SELECT * FROM babel_cross_db_vu_prepare_t2; SELECT * FROM master..babel_cross_db_vu_prepare_t1; +GO +~~START~~ +int#!#varchar +1#!#abc +~~END~~ + +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: relation "master_dbo.babel_cross_db_vu_prepare_t1" does not exist)~~ + + +SELECT * FROM babel_cross_db_vu_prepare_t2; SELECT * FROM master.babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_t1; +GO +~~START~~ +int#!#varchar +1#!#abc +~~END~~ + +~~START~~ +int#!#varchar +1#!#def +~~END~~ + + +-- terminate-tsql-conn user=babel_cross_db_vu_verify_lgn1 password=12345678 + +-- tsql +-- cleanup for "Batches for testing default_database and default_schema setting" +USE my_babel_cross_db_vu_prepare_db1; +GO + +REVOKE SELECT ON babel_cross_db_vu_prepare_s2.babel_cross_db_vu_prepare_t2 FROM babel_cross_db_vu_verify_db1_user_with_def_sch; +GO + +DROP USER babel_cross_db_vu_verify_db1_user_with_def_sch; +GO + +USE master; +GO + +REVOKE SELECT ON babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_t1 FROM babel_cross_db_vu_verify_master_user_with_def_sch; +GO + +DROP USER babel_cross_db_vu_verify_master_user_with_def_sch; +GO + +DROP LOGIN babel_cross_db_vu_verify_lgn1; +GO + -- tsql USE master GO 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 443c18ba8f..f8d2088445 100644 --- a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix +++ b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix @@ -612,6 +612,75 @@ GO DROP TABLE #babel_cross_db_vu_verify_tempt; GO +-- Batches for testing default_database and default_schema setting +-- tsql +USE master; +GO + +CREATE LOGIN babel_cross_db_vu_verify_lgn1 WITH PASSWORD = '12345678'; +GO + +CREATE USER babel_cross_db_vu_verify_master_user_with_def_sch FOR login babel_cross_db_vu_verify_lgn1 WITH default_schema = babel_cross_db_vu_prepare_s1; +GO + +GRANT SELECT ON babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_t1 TO babel_cross_db_vu_verify_master_user_with_def_sch; +GO + +USE my_babel_cross_db_vu_prepare_db1; +GO + +CREATE USER babel_cross_db_vu_verify_db1_user_with_def_sch FOR LOGIN babel_cross_db_vu_verify_lgn1 WITH default_schema = babel_cross_db_vu_prepare_s2; +GO + +GRANT SELECT ON babel_cross_db_vu_prepare_s2.babel_cross_db_vu_prepare_t2 TO babel_cross_db_vu_verify_db1_user_with_def_sch; +GO + +-- tsql user=babel_cross_db_vu_verify_lgn1 password=12345678 +USE master; +GO + +-- TODO: Fix BABEL-5050 +SELECT * FROM babel_cross_db_vu_prepare_t1; SELECT * FROM my_babel_cross_db_vu_prepare_db1..babel_cross_db_vu_prepare_t2; +GO + +SELECT * FROM babel_cross_db_vu_prepare_t1; SELECT * FROM my_babel_cross_db_vu_prepare_db1.babel_cross_db_vu_prepare_s2.babel_cross_db_vu_prepare_t2; +GO + +USE my_babel_cross_db_vu_prepare_db1; +GO + +-- TODO: Fix BABEL-5050 +SELECT * FROM babel_cross_db_vu_prepare_t2; SELECT * FROM master..babel_cross_db_vu_prepare_t1; +GO + +SELECT * FROM babel_cross_db_vu_prepare_t2; SELECT * FROM master.babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_t1; +GO + +-- terminate-tsql-conn user=babel_cross_db_vu_verify_lgn1 password=12345678 + +-- cleanup for "Batches for testing default_database and default_schema setting" +-- tsql +USE my_babel_cross_db_vu_prepare_db1; +GO + +REVOKE SELECT ON babel_cross_db_vu_prepare_s2.babel_cross_db_vu_prepare_t2 FROM babel_cross_db_vu_verify_db1_user_with_def_sch; +GO + +DROP USER babel_cross_db_vu_verify_db1_user_with_def_sch; +GO + +USE master; +GO + +REVOKE SELECT ON babel_cross_db_vu_prepare_s1.babel_cross_db_vu_prepare_t1 FROM babel_cross_db_vu_verify_master_user_with_def_sch; +GO + +DROP USER babel_cross_db_vu_verify_master_user_with_def_sch; +GO + +DROP LOGIN babel_cross_db_vu_verify_lgn1; +GO + -- tsql USE master GO