Skip to content

Commit

Permalink
fix: Actually close unclosed results. Previously was not closing the …
Browse files Browse the repository at this point in the history
…first unclosed result fixes pgjdbc#1903
  • Loading branch information
davecramer committed Sep 30, 2020
1 parent 2c02d4e commit 6d963a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pgjdbc/src/main/java/org/postgresql/jdbc/PgStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,8 @@ public boolean executeWithFlags(int flags) throws SQLException {
private void closeUnclosedResults() throws SQLException {
synchronized (this) {
ResultWrapper resultWrapper = this.firstUnclosedResult;
ResultWrapper currentResult = this.result;
for (; resultWrapper != currentResult && resultWrapper != null;
resultWrapper = resultWrapper.getNext()) {

for (; resultWrapper != null; resultWrapper = resultWrapper.getNext()) {
PgResultSet rs = (PgResultSet) resultWrapper.getResultSet();
if (rs != null) {
rs.closeInternally();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ public void testClose() throws SQLException {
}
}

@Test
public void testResultSetClosed() throws SQLException {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select 1");
stmt.close();
assertTrue(rs.isClosed());
}
/**
* Closing a Statement twice is not an error.
*/
Expand Down

1 comment on commit 6d963a6

@danuvian
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Please sign in to comment.