Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tanzeel Khan <[email protected]>
  • Loading branch information
tanscorpio7 committed Jan 21, 2025
1 parent 76046ee commit 9872e71
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ GO

-- Basic temp table create/insert/select using tsql dialect

-- tsql
CREATE TABLE #local_tempt(col int);
GO

Expand Down Expand Up @@ -281,8 +282,48 @@ go
drop table #tt_1637
go

-- cleanup
-- BABEL-5569
CREATE LOGIN babel_5569_l1 WITH PASSWORD = '12345678'
GO
CREATE USER babel_5569_l1
GO
ALTER ROLE db_ddladmin ADD MEMBER babel_5569_l1
GO

-- tsql user=babel_5569_l1 password=12345678
CREATE TABLE babel_5569_table(a INT)
GO
CREATE TABLE #babel_5569_temp_table (a INT)
GO

-- psql
CREATE OR REPLACE FUNCTION drop_orphaned_temp_schemas() RETURNS void AS $$
DECLARE
schema_record RECORD;
BEGIN
FOR schema_record IN
SELECT nspname
FROM pg_namespace
WHERE nspname LIKE 'pg_temp%'
OR nspname LIKE 'pg_toast_temp%'
LOOP
EXECUTE 'DROP SCHEMA IF EXISTS ' || quote_ident(schema_record.nspname) || ' CASCADE';
END LOOP;
END;
$$ LANGUAGE plpgsql;
GO
SELECT drop_orphaned_temp_schemas();
GO
DROP FUNCTION drop_orphaned_temp_schemas();
GO

-- tsql user=babel_5569_l1 password=12345678
SELECT * INTO #babel_5569_temp_table2 FROM babel_5569_table
GO
-- terminate-tsql-conn user=babel_5569_l1 password=12345678

-- cleanup
-- tsql
DROP PROCEDURE temp_table_sp;
GO
DROP PROCEDURE babel903;
Expand All @@ -303,3 +344,9 @@ DROP PROCEDURE sp_babel1637
GO
DROP TABLE tt_test_t1;
GO
DROP TABLE babel_5569_table;
GO
DROP USER babel_5569_l1
GO
DROP LOGIN babel_5569_l1
GO
56 changes: 56 additions & 0 deletions test/JDBC/sql_expected/temp-tables.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ GO



-- tsql
--
-- Tests for T-SQL style temp tables
--
Expand Down Expand Up @@ -409,7 +410,56 @@ int
drop table #tt_1637
go

-- BABEL-5569
CREATE LOGIN babel_5569_l1 WITH PASSWORD = '12345678'
GO
CREATE USER babel_5569_l1
GO
ALTER ROLE db_ddladmin ADD MEMBER babel_5569_l1
GO

-- tsql user=babel_5569_l1 password=12345678
CREATE TABLE babel_5569_table(a INT)
GO
CREATE TABLE #babel_5569_temp_table (a INT)
GO

-- psql
CREATE OR REPLACE FUNCTION drop_orphaned_temp_schemas() RETURNS void AS $$
DECLARE
schema_record RECORD;
BEGIN
FOR schema_record IN
SELECT nspname
FROM pg_namespace
WHERE nspname LIKE 'pg_temp%'
OR nspname LIKE 'pg_toast_temp%'
LOOP
EXECUTE 'DROP SCHEMA IF EXISTS ' || quote_ident(schema_record.nspname) || ' CASCADE';
END LOOP;
END;
$$ LANGUAGE plpgsql;
GO
SELECT drop_orphaned_temp_schemas();
GO
~~START~~
void

~~END~~

DROP FUNCTION drop_orphaned_temp_schemas();
GO

-- tsql user=babel_5569_l1 password=12345678
SELECT * INTO #babel_5569_temp_table2 FROM babel_5569_table
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: permission denied for table babel_5569_table)~~

-- terminate-tsql-conn user=babel_5569_l1 password=12345678

-- tsql
-- cleanup
DROP PROCEDURE temp_table_sp;
GO
Expand All @@ -431,3 +481,9 @@ DROP PROCEDURE sp_babel1637
GO
DROP TABLE tt_test_t1;
GO
DROP TABLE babel_5569_table;
GO
DROP USER babel_5569_l1
GO
DROP LOGIN babel_5569_l1
GO

0 comments on commit 9872e71

Please sign in to comment.