From 7a6c5703b7526894fd1b3485bb2b161c28425f3b Mon Sep 17 00:00:00 2001 From: Harsh Lunagariya Date: Tue, 17 Dec 2024 10:29:43 +0000 Subject: [PATCH] address comments Signed-off-by: Harsh Lunagariya --- contrib/babelfishpg_tsql/src/tsqlIface.cpp | 4 +- .../expected/BABEL-CROSS-DB-vu-verify.out | 134 ++++++++++++++++++ .../ownership/BABEL-CROSS-DB-vu-verify.mix | 81 +++++++++++ 3 files changed, 216 insertions(+), 3 deletions(-) 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..1d42bf13e4 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out +++ b/test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out @@ -919,6 +919,33 @@ int ~~END~~ +-- batch inside transaction +BEGIN TRAN; +GO + +SELECT DISTINCT 1 FROM my_babel_cross_db_vu_prepare_db1.dbo.sysdatabases; +SELECT DISTINCT 1 FROM babel_cross_db_vu_prepare_master_t1; +SELECT DISTINCT 1 FROM my_babel_cross_db_vu_prepare_db1.dbo.sysdatabases; +GO +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + +COMMIT; +GO + -- system objects refferred via sys schema -- for sys.databases BEGIN; SELECT DISTINCT 1 FROM my_babel_cross_db_vu_prepare_db1.sys.databases; BEGIN; SELECT DISTINCT 1 FROM babel_cross_db_vu_prepare_master_t1; END; END; @@ -1425,6 +1452,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..715cd65a26 100644 --- a/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix +++ b/test/JDBC/input/ownership/BABEL-CROSS-DB-vu-verify.mix @@ -467,6 +467,18 @@ SELECT DISTINCT 1 FROM babel_cross_db_vu_prepare_master_t1; SELECT DISTINCT 1 FROM my_babel_cross_db_vu_prepare_db1.dbo.sysdatabases; GO +-- batch inside transaction +BEGIN TRAN; +GO + +SELECT DISTINCT 1 FROM my_babel_cross_db_vu_prepare_db1.dbo.sysdatabases; +SELECT DISTINCT 1 FROM babel_cross_db_vu_prepare_master_t1; +SELECT DISTINCT 1 FROM my_babel_cross_db_vu_prepare_db1.dbo.sysdatabases; +GO + +COMMIT; +GO + -- system objects refferred via sys schema -- for sys.databases BEGIN; SELECT DISTINCT 1 FROM my_babel_cross_db_vu_prepare_db1.sys.databases; BEGIN; SELECT DISTINCT 1 FROM babel_cross_db_vu_prepare_master_t1; END; END; @@ -612,6 +624,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