Repository: googleapis/java-spanner-jdbc
Pull request #174 (2020-06-29 19:52:02)

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.

See also https://github.com/dbeaver/dbeaver/pull/9127

codecov[bot]: # [Codecov](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174?src=pr&el=h1) Report
> Merging [#174](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174?src=pr&el=desc) into [master](https://codecov.io/gh/googleapis/java-spanner-jdbc/commit/7c336d0ae1328440d38713f66ea9459ffbdc3101&el=desc) will **decrease** coverage by `0.05%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174/graphs/tree.svg?width=650&height=150&src=pr&token=ODlczvbGrj)](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174?src=pr&el=tree)

```diff
@@             Coverage Diff              @@
##             master     #174      +/-   ##
============================================
- Coverage     72.20%   72.15%   -0.06%     
+ Complexity     1095     1094       -1     
============================================
  Files            24       24              
  Lines          3292     3282      -10     
  Branches        495      490       -5     
============================================
- Hits           2377     2368       -9     
+ Misses          722      720       -2     
- Partials        193      194       +1     
```


| [Impacted Files](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174?src=pr&el=tree) | Coverage Δ | Complexity Δ | |
|---|---|---|---|
| [.../com/google/cloud/spanner/jdbc/JdbcConnection.java](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174/diff?src=pr&el=tree#diff-c3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3NwYW5uZXIvamRiYy9KZGJjQ29ubmVjdGlvbi5qYXZh) | `49.72% <100.00%> (ø)` | `42.00 <0.00> (ø)` | |
| [...gle/cloud/spanner/jdbc/AbstractJdbcConnection.java](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174/diff?src=pr&el=tree#diff-c3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3NwYW5uZXIvamRiYy9BYnN0cmFjdEpkYmNDb25uZWN0aW9uLmphdmE=) | `63.88% <0.00%> (-1.39%)` | `20.00% <0.00%> (-1.00%)` | |
| [...ud/spanner/jdbc/AbstractJdbcPreparedStatement.java](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174/diff?src=pr&el=tree#diff-c3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3NwYW5uZXIvamRiYy9BYnN0cmFjdEpkYmNQcmVwYXJlZFN0YXRlbWVudC5qYXZh) | `90.24% <0.00%> (-0.61%)` | `52.00% <0.00%> (ø%)` | |
| [...oogle/cloud/spanner/jdbc/JdbcDatabaseMetaData.java](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174/diff?src=pr&el=tree#diff-c3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3NwYW5uZXIvamRiYy9KZGJjRGF0YWJhc2VNZXRhRGF0YS5qYXZh) | `95.23% <0.00%> (-0.01%)` | `180.00% <0.00%> (ø%)` | |
| [...m/google/cloud/spanner/jdbc/JdbcTypeConverter.java](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174/diff?src=pr&el=tree#diff-c3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3NwYW5uZXIvamRiYy9KZGJjVHlwZUNvbnZlcnRlci5qYXZh) | `73.91% <0.00%> (+0.11%)` | `91.00% <0.00%> (ø%)` | |
| [...a/com/google/cloud/spanner/jdbc/JdbcResultSet.java](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174/diff?src=pr&el=tree#diff-c3JjL21haW4vamF2YS9jb20vZ29vZ2xlL2Nsb3VkL3NwYW5uZXIvamRiYy9KZGJjUmVzdWx0U2V0LmphdmE=) | `79.02% <0.00%> (+0.20%)` | `186.00% <0.00%> (ø%)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174?src=pr&el=footer). Last update [7c336d0...692d4c7](https://codecov.io/gh/googleapis/java-spanner-jdbc/pull/174?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
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 5aefd35..4e23180 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 @@ class JdbcConnection extends AbstractJdbcConnection {
   @Override
   public String getCatalog() throws SQLException {
     checkClosed();
-    return getConnectionOptions().getDatabaseName();
+    return "";
   }
 
   @Override


Test patch:
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 a80e800..82e26d0 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 class JdbcConnectionTest {
     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 {