Skip to content

Commit

Permalink
Add more test cases in a view/function/procedure
Browse files Browse the repository at this point in the history
Signed-off-by: Chenxiao Wang <[email protected]>
  • Loading branch information
Chenxiao Wang committed Nov 12, 2024
1 parent 2f9c5f0 commit c6851f9
Show file tree
Hide file tree
Showing 2 changed files with 244 additions and 0 deletions.
137 changes: 137 additions & 0 deletions test/JDBC/expected/BABEL-2961.out
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,140 @@ GO

DROP DATABASE TestDB2961
GO

USE master
GO

IF OBJECT_ID('dbo.NonExistentTable', 'U') IS NOT NULL
DROP TABLE dbo.NonExistentTable
GO

-- Create a view that attempts to select from a non-existent table
CREATE VIEW dbo.NonExistentTableView AS
SELECT * FROM dbo.NonExistentTable
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: relation "dbo.nonexistenttable" does not exist)~~


IF OBJECT_ID('dbo.NonExistentTableView', 'V') IS NOT NULL
DROP VIEW dbo.NonExistentTableView
GO

-- Create a function that attempts to select from a non-existent table
CREATE FUNCTION dbo.NonExistentTableFunc()
RETURNS TABLE
AS
RETURN
(
SELECT * FROM dbo.NonExistentTable
)
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: relation "dbo.nonexistenttable" does not exist)~~


IF OBJECT_ID('dbo.NonExistentTableFunc', 'IF') IS NOT NULL
DROP FUNCTION dbo.NonExistentTableFunc
GO

IF OBJECT_ID('dbo.CallNonExistentProc', 'P') IS NOT NULL
DROP PROCEDURE dbo.CallNonExistentProc
GO

-- Create a procedure that attempts to execute a non-existent procedure
CREATE PROCEDURE dbo.CallNonExistentProc
AS
BEGIN
EXEC dbo.NonExistentProc
END
GO
EXEC dbo.CallNonExistentProc
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: procedure dbo.nonexistentproc() does not exist)~~


IF OBJECT_ID('dbo.DropNonExistentUser', 'P') IS NOT NULL
DROP PROCEDURE dbo.DropNonExistentUser
GO

IF OBJECT_ID('dbo.NonExistentProc', 'P') IS NOT NULL
DROP PROCEDURE dbo.NonExistentProc
GO


-- Create a function that attempts to use a non-existent schema
CREATE FUNCTION nonexistent_schema.TestFunc()
RETURNS INT
AS
BEGIN
RETURN 1
END
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: schema "nonexistent_schema" does not exist)~~


IF OBJECT_ID('nonexistent_schema.TestFunc', 'FN') IS NOT NULL
DROP FUNCTION nonexistent_schema.TestFunc
GO


-- Create a procedure that attempts to drop a non-existent user
CREATE PROCEDURE dbo.DropNonExistentUser
AS
BEGIN
DROP USER NonExistentUser
END
GO

EXEC dbo.DropNonExistentUser
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: Cannot drop the user 'nonexistentuser', because it does not exist or you do not have permission.)~~


IF OBJECT_ID('dbo.DropNonExistentUser', 'P') IS NOT NULL
DROP PROCEDURE dbo.DropNonExistentUser
GO

IF OBJECT_ID('dbo.NonExistentProc', 'P') IS NOT NULL
DROP PROCEDURE dbo.NonExistentProc
GO


-- Attempt multiple operations within a single transaction
BEGIN TRANSACTION
CREATE TABLE dbo.TestTable (ID INT)
INSERT INTO dbo.TestTable VALUES (1)
SELECT * FROM dbo.NonExistentTable
COMMIT
GO
~~ROW COUNT: 1~~

~~ERROR (Code: 33557097)~~

~~ERROR (Message: relation "dbo.nonexistenttable" does not exist)~~


-- Verify if the transaction rolled back correctly
SELECT * FROM dbo.TestTable
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: relation "dbo.testtable" does not exist)~~


IF OBJECT_ID('dbo.TestTable', 'U') IS NOT NULL
DROP TABLE dbo.TestTable
GO

IF OBJECT_ID('dbo.NonExistentTable', 'U') IS NOT NULL
DROP TABLE dbo.NonExistentTable
GO
107 changes: 107 additions & 0 deletions test/JDBC/input/BABEL-2961.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,111 @@ USE master
GO

DROP DATABASE TestDB2961
GO

USE master
GO

IF OBJECT_ID('dbo.NonExistentTable', 'U') IS NOT NULL
DROP TABLE dbo.NonExistentTable
GO

-- Create a view that attempts to select from a non-existent table
CREATE VIEW dbo.NonExistentTableView AS
SELECT * FROM dbo.NonExistentTable
GO

IF OBJECT_ID('dbo.NonExistentTableView', 'V') IS NOT NULL
DROP VIEW dbo.NonExistentTableView
GO

-- Create a function that attempts to select from a non-existent table
CREATE FUNCTION dbo.NonExistentTableFunc()
RETURNS TABLE
AS
RETURN
(
SELECT * FROM dbo.NonExistentTable
)
GO

IF OBJECT_ID('dbo.NonExistentTableFunc', 'IF') IS NOT NULL
DROP FUNCTION dbo.NonExistentTableFunc
GO

IF OBJECT_ID('dbo.CallNonExistentProc', 'P') IS NOT NULL
DROP PROCEDURE dbo.CallNonExistentProc
GO

-- Create a procedure that attempts to execute a non-existent procedure
CREATE PROCEDURE dbo.CallNonExistentProc
AS
BEGIN
EXEC dbo.NonExistentProc
END
GO
EXEC dbo.CallNonExistentProc
GO

IF OBJECT_ID('dbo.DropNonExistentUser', 'P') IS NOT NULL
DROP PROCEDURE dbo.DropNonExistentUser
GO

IF OBJECT_ID('dbo.NonExistentProc', 'P') IS NOT NULL
DROP PROCEDURE dbo.NonExistentProc
GO


-- Create a function that attempts to use a non-existent schema
CREATE FUNCTION nonexistent_schema.TestFunc()
RETURNS INT
AS
BEGIN
RETURN 1
END
GO

IF OBJECT_ID('nonexistent_schema.TestFunc', 'FN') IS NOT NULL
DROP FUNCTION nonexistent_schema.TestFunc
GO


-- Create a procedure that attempts to drop a non-existent user
CREATE PROCEDURE dbo.DropNonExistentUser
AS
BEGIN
DROP USER NonExistentUser
END
GO

EXEC dbo.DropNonExistentUser
GO

IF OBJECT_ID('dbo.DropNonExistentUser', 'P') IS NOT NULL
DROP PROCEDURE dbo.DropNonExistentUser
GO

IF OBJECT_ID('dbo.NonExistentProc', 'P') IS NOT NULL
DROP PROCEDURE dbo.NonExistentProc
GO


-- Attempt multiple operations within a single transaction
BEGIN TRANSACTION
CREATE TABLE dbo.TestTable (ID INT)
INSERT INTO dbo.TestTable VALUES (1)
SELECT * FROM dbo.NonExistentTable
COMMIT
GO

-- Verify if the transaction rolled back correctly
SELECT * FROM dbo.TestTable
GO

IF OBJECT_ID('dbo.TestTable', 'U') IS NOT NULL
DROP TABLE dbo.TestTable
GO

IF OBJECT_ID('dbo.NonExistentTable', 'U') IS NOT NULL
DROP TABLE dbo.NonExistentTable
GO

0 comments on commit c6851f9

Please sign in to comment.