From cedd167c5973fe50e0205ae641f6580ebd627884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Tue, 30 Jun 2020 04:30:24 +0200 Subject: [PATCH] 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 --- .../java/com/google/cloud/spanner/jdbc/JdbcConnection.java | 2 +- .../com/google/cloud/spanner/jdbc/JdbcConnectionTest.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java index 5aefd35b..4e231809 100644 --- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java +++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java @@ -291,7 +291,7 @@ public void setCatalog(String catalog) throws SQLException { @Override public String getCatalog() throws SQLException { checkClosed(); - return getConnectionOptions().getDatabaseName(); + return ""; } @Override diff --git a/src/test/java/com/google/cloud/spanner/jdbc/JdbcConnectionTest.java b/src/test/java/com/google/cloud/spanner/jdbc/JdbcConnectionTest.java index a80e8009..82e26d03 100644 --- a/src/test/java/com/google/cloud/spanner/jdbc/JdbcConnectionTest.java +++ b/src/test/java/com/google/cloud/spanner/jdbc/JdbcConnectionTest.java @@ -634,7 +634,9 @@ public void testCatalog() throws SQLException { ConnectionOptions options = mock(ConnectionOptions.class); when(options.getDatabaseName()).thenReturn("test"); try (JdbcConnection connection = createConnection(options)) { - assertThat(connection.getCatalog()).isEqualTo("test"); + // The connection should always return the empty string as the current catalog, as no other + // catalogs exist in the INFORMATION_SCHEMA. + assertThat(connection.getCatalog()).isEqualTo(""); // This should be allowed. connection.setCatalog(""); try {