Skip to content

Fix incorrect NULL values in TABLE_CATALOG returned by getSchemas() for built-in schemas.#2872

Merged
Ananya2 merged 2 commits intomainfrom
user/anagarg/issue#2863
Jan 6, 2026
Merged

Fix incorrect NULL values in TABLE_CATALOG returned by getSchemas() for built-in schemas.#2872
Ananya2 merged 2 commits intomainfrom
user/anagarg/issue#2863

Conversation

@Ananya2
Copy link
Contributor

@Ananya2 Ananya2 commented Jan 5, 2026

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:

  • when no catalog is specified, the current database name is returned (DB_NAME())
  • when a catalog is provided, that value is returned
  • when an empty catalog string is supplied, the catalog is treated as not applicable and NULL is returned for cross-database scenarios

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

@Ananya2 Ananya2 self-assigned this Jan 5, 2026
@Ananya2 Ananya2 added this to the 13.3.1 milestone Jan 5, 2026
@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.06%. Comparing base (0eb40a0) to head (efc38f6).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ns correct TABLE_CATALOG values for all schema type
@Ananya2 Ananya2 requested a review from machavan January 6, 2026 05:39
@Ananya2 Ananya2 merged commit 847d951 into main Jan 6, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DatabaseMetaData getSchemas returns only one "dbo" schema with a null TABLE_CATALOG

4 participants