Skip to content

Commit

Permalink
fix: allow QueryMessage with empty query string (#113)
Browse files Browse the repository at this point in the history
PostgreSQL accepts QueryMessages with an empty query string. PGAdapter
now also accepts these and sends back a NoDataResponse without sending
the statement to Spanner.
  • Loading branch information
olavloite authored Apr 22, 2022
1 parent f7d05b2 commit 2a3f2eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2a3f2eb

Please sign in to comment.