diff --git a/src/main/java/com/google/cloud/spanner/pgadapter/statements/IntermediateStatement.java b/src/main/java/com/google/cloud/spanner/pgadapter/statements/IntermediateStatement.java index 2f1141c99..5a7eaac29 100644 --- a/src/main/java/com/google/cloud/spanner/pgadapter/statements/IntermediateStatement.java +++ b/src/main/java/com/google/cloud/spanner/pgadapter/statements/IntermediateStatement.java @@ -411,11 +411,14 @@ private void executeSingleStatement(int index) { executionStatus = ExecutionStatus.AUTOCOMMIT; } } - try { - StatementResult result = this.connection.execute(Statement.of(statement)); - updateResultCount(index, result); - } catch (SpannerException e) { - handleExecutionExceptionAndTransactionStatus(index, e); + // Ignore empty statements. + if (!"".equals(statement)) { + try { + StatementResult result = this.connection.execute(Statement.of(statement)); + updateResultCount(index, result); + } catch (SpannerException e) { + handleExecutionExceptionAndTransactionStatus(index, e); + } } } diff --git a/src/test/java/com/google/cloud/spanner/pgadapter/JdbcSimpleModeMockServerTest.java b/src/test/java/com/google/cloud/spanner/pgadapter/JdbcSimpleModeMockServerTest.java index 170b81d82..e90f6a812 100644 --- a/src/test/java/com/google/cloud/spanner/pgadapter/JdbcSimpleModeMockServerTest.java +++ b/src/test/java/com/google/cloud/spanner/pgadapter/JdbcSimpleModeMockServerTest.java @@ -92,6 +92,18 @@ public void testQuery() throws SQLException { assertTrue(request.getTransaction().getSingleUse().hasReadOnly()); } + @Test + public void testEmptyStatement() throws SQLException { + String sql = ""; + + try (Connection connection = DriverManager.getConnection(createUrl())) { + assertFalse(connection.createStatement().execute(sql)); + } + + // An empty statement is not sent to Spanner. + assertEquals(0, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class)); + } + @Test public void testWrongDialect() { // Let the mock server respond with the Google SQL dialect instead of PostgreSQL. The