Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh Lunagariya <[email protected]>
  • Loading branch information
HarshLunagariya committed Dec 17, 2024
1 parent b20fa79 commit 7a6c570
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 3 deletions.
4 changes: 1 addition & 3 deletions contrib/babelfishpg_tsql/src/tsqlIface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
134 changes: 134 additions & 0 deletions test/JDBC/expected/BABEL-CROSS-DB-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
81 changes: 81 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 @@ -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;
Expand Down Expand Up @@ -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

0 comments on commit 7a6c570

Please sign in to comment.