Skip to content

Commit cedd167

Browse files
authored
fix: return empty catalog name (#174)
* fix: return empty catalog name The JDBC connection would return the current database name as the current catalog name, but that catalog name would not be returned in the ResultSet returned by getCatalogs(). This discrepancy causes some tools to ignore or misinterpret the catalog and schema structure of a Cloud Spanner database. Specifically, it breaks the autocomplete feature of DBeaver. * tests: fix failing test case
1 parent 7c336d0 commit cedd167

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public void setCatalog(String catalog) throws SQLException {
291291
@Override
292292
public String getCatalog() throws SQLException {
293293
checkClosed();
294-
return getConnectionOptions().getDatabaseName();
294+
return "";
295295
}
296296

297297
@Override

src/test/java/com/google/cloud/spanner/jdbc/JdbcConnectionTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,9 @@ public void testCatalog() throws SQLException {
634634
ConnectionOptions options = mock(ConnectionOptions.class);
635635
when(options.getDatabaseName()).thenReturn("test");
636636
try (JdbcConnection connection = createConnection(options)) {
637-
assertThat(connection.getCatalog()).isEqualTo("test");
637+
// The connection should always return the empty string as the current catalog, as no other
638+
// catalogs exist in the INFORMATION_SCHEMA.
639+
assertThat(connection.getCatalog()).isEqualTo("");
638640
// This should be allowed.
639641
connection.setCatalog("");
640642
try {

0 commit comments

Comments
 (0)