Skip to content

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

@SophiahHo

Description

@SophiahHo

Driver version

13.2.1.jre11

SQL Server version

Microsoft SQL Server 2022 (RTM-CU17) (KB5048038) - 16.0.4175.1 (X64) 
	Dec 13 2024 09:01:53 
	Copyright (C) 2022 Microsoft Corporation
	Express Edition (64-bit) on Windows Server 2016 Datacenter 10.0 <X64> (Build 14393: ) (Hypervisor)

Client Operating System

Microsoft Windows 11 Enterprise

JAVA/JVM version

17

Table schema

dbo

Problem description

When there are multiple databases/catalogs, connection.getMetaData().getSchemas(connection.getCatalog(), "dbo") and connection.getMetaData().getSchemas(null, "dbo") return only one dbo with a null TABLE_CATALOG.

String[] catalogs = new String[]{connection.getCatalog(), null};
for (String catalog: catalogs) {
	System.out.println("catalog: " + catalog + "\n");
	try (ResultSet rs = connection.getMetaData().getSchemas(catalog, "dbo")) {
		int rows = 0;
		while (rs.next()) {
			for (int col = 1; col <= rs.getMetaData().getColumnCount(); col++) {
				System.out.println(String.format("%d. %s : \"%s\"",
						col, rs.getMetaData().getColumnName(col), rs.getString(col)
				));
			}
			System.out.println();
			rows++;
		}
		System.out.println("Found " + rows + " row(s).\n");
	}
}

Expected behavior

  1. Schema dbo should have a non-empty catalog.
  2. There should be a dbo schema for every catalog.

Actual behavior

(When there are multiple databases/catalogs each with a dbo schema)

catalog: TestDb

1. TABLE_SCHEM : "dbo"
2. TABLE_CATALOG : "null"

Found 1 row(s).

catalog: null

1. TABLE_SCHEM : "dbo"
2. TABLE_CATALOG : "null"

Found 1 row(s).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions