New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Actually close unclosed results. Previously was not closing the first unclosed result fixes #1903 #1905
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1905 +/- ##
============================================
+ Coverage 69.17% 69.19% +0.01%
- Complexity 4210 4213 +3
============================================
Files 197 197
Lines 18005 18006 +1
Branches 2919 2920 +1
============================================
+ Hits 12455 12459 +4
+ Misses 4204 4202 -2
+ Partials 1346 1345 -1 |
/* we are going to release this anyway make sure it is closed */ | ||
if ( this.result != null && this.result.getResultSet() != null ) { | ||
((PgResultSet)this.result.getResultSet()).closeInternally(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be placed in closeUnclosedResults
?
Otherwise, it sounds strange that closeUnclosedResults
leaves an unclosed resultset behind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably yes, one more Q should we include this in 42.2.19 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's include it provided it passes tests.
@vlsi so currently the testExecuteTwice test is failing due to the statement being closed. This seems to be the correct behaviour since ResultSet docs say |
pgjdbc/src/test/java/org/postgresql/test/jdbc4/jdbc41/CloseOnCompletionTest.java
Show resolved
Hide resolved
WDYT about this tests: @Test
public void testCloseOnCompletionMultipleExecutionResultSets() throws SQLException {
Statement statement = conn.createStatement();
assertFalse(statement.isCloseOnCompletion());
ResultSet rs1 = statement.executeQuery("SELECT 1");
assertFalse("rs1 should be open", rs1.isClosed());
// a call to closeOnCompletion does effect both the subsequent execution of statements,
// and statements that currently have open, dependent, result sets.
statement.closeOnCompletion();
assertTrue(statement.isCloseOnCompletion());
ResultSet rs2 = statement.executeQuery("SELECT 2");
assertTrue("rs1 should be closed by rs2", rs1.isClosed());
assertFalse("rs2 should be open", rs2.isClosed());
assertFalse("statement should be open", statement.isClosed());
rs2.close(); // Affects the statement closeOnCompletion.
assertTrue("statement should be closed", statement.isClosed());
}
@Test
public void testMultipleExecutionResultSets() throws SQLException {
Statement statement = conn.createStatement();
ResultSet rs1 = statement.executeQuery("SELECT 1");
assertFalse("rs1 should be open", rs1.isClosed());
ResultSet rs2 = statement.executeQuery("SELECT 2");
assertTrue("rs1 should be closed by rs2", rs1.isClosed());
assertFalse("rs2 should be open", rs2.isClosed());
statement.close(); // closing the statement affects the result set
assertTrue("statement should be closed", statement.isClosed());
assertTrue("rs2 should be closed", rs2.isClosed());
} |
Sure, can't have too many tests, Except
Doesn't pass as setting closeOnCompletion will close the existing statement when it closes the existing result set. |
That's what worries me, I'm not completely sure that it should close the statement.
So it should allow subsequent execution of statements, just that it close the previous Result Set, and when all the Result Sets are closed then the I can't confirm that this is the correct behavior, so we should be careful if we introduce this change of behavior and is not correct. It's really sad that the JDBC spec is really ambiguous, but if we can ask for a second opinion it would be great. |
Welcome to JDBC
So it should allow subsequent execution of statements, just that it close the previous Result Set, and when all the Result Sets are closed then the closeOnCompletion should close the statement. I actually read this as I'll see if I can get an answer. Problem is it may not be quick. |
OK, I have searched all of the JSR's and there is no mention however reading the javadocs again.
Note that the first line says "all it's dependent result sets" and the note specifically refers to dependent result sets. I'm now OK with this change in it's current form |
I sent the following to the jdbc-spec-discuss list:
and the response was Logically, yes, I think this is how it is supposed to work. If you call So I think what we have is fine. The bigger question is that since it changes behaviour slightly do we want to include it in 42.2.19 |
It only affects |
I took a peek to see what we do now and what other drivers do in this situation. Here's the result for this sample code: Statement stmt = conn.createStatement();
stmt.closeOnCompletion();
ResultSet rsOne = stmt.executeQuery("SELECT 1");
ResultSet rsTwo = stmt.executeQuery("SELECT 2");
rsTwo.next();
So MariaDB matches our old behavior and Oracle's driver matches up with the proposed new behavior. |
So it seems the JDBC spec group is aligned with this interpretation. |
No description provided.