forked from babelfish-for-postgresql/babelfish_extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with sp_tables failing for cross-database table qualifiers (b…
…abelfish-for-postgresql#2961) (babelfish-for-postgresql#2984) This change fixes an issue with the sp_tables stored procedure, which incorrectly handled three-part object names across databases, throwing an error regarding database context. The root cause was sys.db_name() returning the wrong database name based on the object qualifier. The issue affected the usability of linked servers in Babelfish, as it prevented accurate metadata retrieval, limiting compatibility with SQL Server. The fix replaced sys.db_name() with a direct SELECT sys.db_name() to fetch the correct database name before comparing it against the table_qualifier. Task: BABEL-5263 Signed-off-by: Roshan Kanwar <[email protected]>
- Loading branch information
1 parent
bcfeab7
commit 0b229b1
Showing
9 changed files
with
191 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
USE babel_5263_vu_prepare_db1; | ||
GO | ||
|
||
DROP FUNCTION IF EXISTS babel_5263_vu_prepare_f1; | ||
GO | ||
|
||
DROP PROCEDURE IF EXISTS babel_5263_vu_prepare_p1; | ||
GO | ||
|
||
DROP VIEW IF EXISTS babel_5263_vu_prepare_v1; | ||
GO | ||
|
||
DROP TABLE IF EXISTS babel_5263_vu_prepare_t1; | ||
GO | ||
|
||
USE master; | ||
GO | ||
|
||
DROP DATABASE IF EXISTS babel_5263_vu_prepare_db1; | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CREATE DATABASE babel_5263_vu_prepare_db1; | ||
GO | ||
|
||
USE babel_5263_vu_prepare_db1; | ||
GO | ||
|
||
CREATE TABLE babel_5263_vu_prepare_t1 (a INT); | ||
GO | ||
|
||
CREATE PROCEDURE babel_5263_vu_prepare_p1 AS SELECT 1; | ||
GO | ||
|
||
CREATE FUNCTION babel_5263_vu_prepare_f1() RETURNS INT AS BEGIN RETURN 1 END; | ||
GO | ||
|
||
CREATE VIEW babel_5263_vu_prepare_v1 AS SELECT 1; | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
-- Case 1: Correct Database Context | ||
USE babel_5263_vu_prepare_db1; | ||
GO | ||
|
||
-- Enumerate matching objects | ||
EXEC babel_5263_vu_prepare_db1.sys.sp_tables NULL, NULL, 'babel_5263_vu_prepare_db1', NULL, 1; | ||
GO | ||
~~START~~ | ||
varchar#!#varchar#!#varchar#!#varchar#!#varchar | ||
babel_5263_vu_prepare_db1#!#dbo#!#babel_5263_vu_prepare_t1#!#TABLE#!#<NULL> | ||
babel_5263_vu_prepare_db1#!#dbo#!#babel_5263_vu_prepare_v1#!#VIEW#!#<NULL> | ||
babel_5263_vu_prepare_db1#!#dbo#!#sysdatabases#!#VIEW#!#<NULL> | ||
~~END~~ | ||
|
||
|
||
-- Case 2: Mismatched Database Context | ||
USE master; | ||
GO | ||
|
||
-- Enumerate matching objects | ||
EXEC babel_5263_vu_prepare_db1.sys.sp_tables NULL, NULL, 'babel_5263_vu_prepare_db1', NULL, 1; | ||
GO | ||
~~START~~ | ||
varchar#!#varchar#!#varchar#!#varchar#!#varchar | ||
babel_5263_vu_prepare_db1#!#dbo#!#babel_5263_vu_prepare_t1#!#TABLE#!#<NULL> | ||
babel_5263_vu_prepare_db1#!#dbo#!#babel_5263_vu_prepare_v1#!#VIEW#!#<NULL> | ||
babel_5263_vu_prepare_db1#!#dbo#!#sysdatabases#!#VIEW#!#<NULL> | ||
~~END~~ | ||
|
||
|
||
-- Case 3: No Table Qualifier - Current Database Assumed | ||
USE babel_5263_vu_prepare_db1; | ||
GO | ||
|
||
EXEC babel_5263_vu_prepare_db1.sys.sp_tables NULL, NULL, NULL, NULL, 1; | ||
GO | ||
~~START~~ | ||
varchar#!#varchar#!#varchar#!#varchar#!#varchar | ||
babel_5263_vu_prepare_db1#!#dbo#!#babel_5263_vu_prepare_t1#!#TABLE#!#<NULL> | ||
babel_5263_vu_prepare_db1#!#dbo#!#babel_5263_vu_prepare_v1#!#VIEW#!#<NULL> | ||
babel_5263_vu_prepare_db1#!#dbo#!#sysdatabases#!#VIEW#!#<NULL> | ||
~~END~~ | ||
|
||
|
||
-- Case 4: Cross-database Access - Mismatch | ||
USE babel_5263_vu_prepare_db1; | ||
GO | ||
|
||
EXEC master.sys.sp_tables NULL, NULL, 'babel_5263_vu_prepare_db1', NULL, 1; | ||
GO | ||
~~ERROR (Code: 33557097)~~ | ||
|
||
~~ERROR (Message: The database name component of the object qualifier must be the name of the current database.)~~ | ||
|
||
|
||
-- Case 5: Case Sensitivity in Table Qualifier | ||
USE master; | ||
GO | ||
|
||
EXEC babel_5263_vu_prepare_db1.sys.sp_tables NULL, NULL, 'babel_5263_VU_prepARe_db1', NULL, 1; | ||
GO | ||
~~START~~ | ||
varchar#!#varchar#!#varchar#!#varchar#!#varchar | ||
babel_5263_vu_prepare_db1#!#dbo#!#babel_5263_vu_prepare_t1#!#TABLE#!#<NULL> | ||
babel_5263_vu_prepare_db1#!#dbo#!#babel_5263_vu_prepare_v1#!#VIEW#!#<NULL> | ||
babel_5263_vu_prepare_db1#!#dbo#!#sysdatabases#!#VIEW#!#<NULL> | ||
~~END~~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
USE babel_5263_vu_prepare_db1; | ||
GO | ||
|
||
DROP FUNCTION IF EXISTS babel_5263_vu_prepare_f1; | ||
GO | ||
|
||
DROP PROCEDURE IF EXISTS babel_5263_vu_prepare_p1; | ||
GO | ||
|
||
DROP VIEW IF EXISTS babel_5263_vu_prepare_v1; | ||
GO | ||
|
||
DROP TABLE IF EXISTS babel_5263_vu_prepare_t1; | ||
GO | ||
|
||
USE master; | ||
GO | ||
|
||
DROP DATABASE IF EXISTS babel_5263_vu_prepare_db1; | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CREATE DATABASE babel_5263_vu_prepare_db1; | ||
GO | ||
|
||
USE babel_5263_vu_prepare_db1; | ||
GO | ||
|
||
CREATE TABLE babel_5263_vu_prepare_t1 (a INT); | ||
GO | ||
|
||
CREATE PROCEDURE babel_5263_vu_prepare_p1 AS SELECT 1; | ||
GO | ||
|
||
CREATE FUNCTION babel_5263_vu_prepare_f1() RETURNS INT AS BEGIN RETURN 1 END; | ||
GO | ||
|
||
CREATE VIEW babel_5263_vu_prepare_v1 AS SELECT 1; | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-- Case 1: Correct Database Context | ||
USE babel_5263_vu_prepare_db1; | ||
GO | ||
|
||
-- Enumerate matching objects | ||
EXEC babel_5263_vu_prepare_db1.sys.sp_tables NULL, NULL, 'babel_5263_vu_prepare_db1', NULL, 1; | ||
GO | ||
|
||
-- Case 2: Mismatched Database Context | ||
USE master; | ||
GO | ||
|
||
-- Enumerate matching objects | ||
EXEC babel_5263_vu_prepare_db1.sys.sp_tables NULL, NULL, 'babel_5263_vu_prepare_db1', NULL, 1; | ||
GO | ||
|
||
-- Case 3: No Table Qualifier - Current Database Assumed | ||
USE babel_5263_vu_prepare_db1; | ||
GO | ||
|
||
EXEC babel_5263_vu_prepare_db1.sys.sp_tables NULL, NULL, NULL, NULL, 1; | ||
GO | ||
|
||
-- Case 4: Cross-database Access - Mismatch | ||
USE babel_5263_vu_prepare_db1; | ||
GO | ||
|
||
EXEC master.sys.sp_tables NULL, NULL, 'babel_5263_vu_prepare_db1', NULL, 1; | ||
GO | ||
|
||
-- Case 5: Case Sensitivity in Table Qualifier | ||
USE master; | ||
GO | ||
|
||
EXEC babel_5263_vu_prepare_db1.sys.sp_tables NULL, NULL, 'babel_5263_VU_prepARe_db1', NULL, 1; | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters