Fix incorrect NULL values in TABLE_CATALOG returned by getSchemas() for built-in schemas.#2872
Merged
Fix incorrect NULL values in TABLE_CATALOG returned by getSchemas() for built-in schemas.#2872
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2872 +/- ##
============================================
+ Coverage 59.01% 59.06% +0.05%
- Complexity 4751 4753 +2
============================================
Files 151 151
Lines 34564 34575 +11
Branches 5769 5776 +7
============================================
+ Hits 20399 20423 +24
+ Misses 11406 11403 -3
+ Partials 2759 2749 -10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
machavan
reviewed
Jan 6, 2026
src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java
Show resolved
Hide resolved
…ns correct TABLE_CATALOG values for all schema type
machavan
approved these changes
Jan 6, 2026
divang
approved these changes
Jan 6, 2026
muskan124947
approved these changes
Jan 6, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix incorrect NULL values in TABLE_CATALOG returned by getSchemas() for built-in schemas.
Problem
DatabaseMetaData.getSchemas() was returning NULL for the TABLE_CATALOG column when querying built-in schemas such as dbo, guest, sys, INFORMATION_SCHEMA, and database roles.
According to the JDBC specification, TABLE_CATALOG should contain the name of the catalog (database) in which the schema resides and should only be NULL when the value is not applicable.
Root Cause
The issue originated from the query logic backing getSchemas(). The implementation contained a CASE statement that explicitly set TABLE_CATALOG to NULL for schemas included in an internal constSchemas list representing built-in schemas. While intended to special-case system schemas, this logic unintentionally suppressed valid catalog values. As a result, built-in schemas were returned as null.
Solution
The fix removes the special CASE handling entirely and simplifies the catalog derivation logic. Instead of conditionally nulling the catalog name, the method now always resolves the correct catalog based on the input parameters:
With this change, built-in schemas are treated consistently with user schemas, and the driver now accurately reflects catalog ownership as required by the JDBC specification.
Closes #2863