Skip to content

Commit

Permalink
chore: discard all should reset all session state
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed May 27, 2024
1 parent 8621984 commit 4dbb033
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void executeAsync(BackendConnection backendConnection) {
SQLState.ActiveSqlTransaction)));
return;
}
backendConnection.getSessionState().resetAll();
connectionHandler.closeAllStatements();
break;
case PLANS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,22 @@ public void testDiscard() throws SQLException {
SQLState.InvalidSqlStatementName.toString(),
exception.getServerErrorMessage().getSQLState());

// Verify that DISCARD ALL resets all session state.
connection.createStatement().execute("set spanner.copy_upsert=true");
try (ResultSet resultSet =
connection.createStatement().executeQuery("show spanner.copy_upsert")) {
assertTrue(resultSet.next());
assertTrue(resultSet.getBoolean(1));
assertFalse(resultSet.next());
}
connection.createStatement().execute("discard all");
try (ResultSet resultSet =
connection.createStatement().executeQuery("show spanner.copy_upsert")) {
assertTrue(resultSet.next());
assertFalse(resultSet.getBoolean(1));
assertFalse(resultSet.next());
}

// Verify that 'discard all' is not accepted in a transaction block.
connection.setAutoCommit(false);
exception =
Expand Down

0 comments on commit 4dbb033

Please sign in to comment.