[libpostgresql-jdbc-java] 13/15: Clear the generated keys associated with a Statement at the next execution. If the next execution doesn't want generated keys, we don't want to leave the old keys around.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:57 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_4_703
in repository libpostgresql-jdbc-java.
commit 359862612409057c469438321a10d96127197699
Author: Kris Jurka <books at ejurka.com>
Date: Sat Apr 2 07:31:49 2011 +0000
Clear the generated keys associated with a Statement at the next
execution. If the next execution doesn't want generated keys, we
don't want to leave the old keys around.
---
org/postgresql/jdbc2/AbstractJdbc2Statement.java | 47 ++++++++----------------
org/postgresql/test/jdbc3/GeneratedKeysTest.java | 12 +++++-
2 files changed, 27 insertions(+), 32 deletions(-)
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
index 2b27412..9919a47 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Statement.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.114.2.2 2010/05/01 16:08:00 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.114.2.3 2011/03/20 00:58:45 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -450,7 +450,7 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
return (result != null && result.getResultSet() != null);
}
- protected void execute(Query queryToExecute, ParameterList queryParameters, int flags) throws SQLException {
+ protected void closeForNextExecution() throws SQLException {
// Every statement execution clears any previous warnings.
clearWarnings();
@@ -461,12 +461,24 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
firstUnclosedResult.getResultSet().close();
firstUnclosedResult = firstUnclosedResult.getNext();
}
+ result = null;
if (lastSimpleQuery != null) {
lastSimpleQuery.close();
lastSimpleQuery = null;
}
+ if (generatedKeys != null) {
+ if (generatedKeys.getResultSet() != null) {
+ generatedKeys.getResultSet().close();
+ }
+ generatedKeys = null;
+ }
+ }
+
+ protected void execute(Query queryToExecute, ParameterList queryParameters, int flags) throws SQLException {
+ closeForNextExecution();
+
// Enable cursor-based resultset if possible.
if (fetchSize > 0 && !wantsScrollableResultSet() && !connection.getAutoCommit() && !wantsHoldableResultSet())
flags |= QueryExecutor.QUERY_FORWARD_CURSOR;
@@ -766,22 +778,11 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
if (isClosed)
return ;
- // Force the ResultSet(s) to close
- while (firstUnclosedResult != null)
- {
- if (firstUnclosedResult.getResultSet() != null)
- firstUnclosedResult.getResultSet().close();
- firstUnclosedResult = firstUnclosedResult.getNext();
- }
-
- if (lastSimpleQuery != null)
- lastSimpleQuery.close();
+ closeForNextExecution();
if (preparedQuery != null)
preparedQuery.close();
- // Disasociate it from us
- result = firstUnclosedResult = null;
isClosed = true;
}
@@ -2673,8 +2674,7 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
{
checkClosed();
- // Every statement execution clears any previous warnings.
- clearWarnings();
+ closeForNextExecution();
if (batchStatements == null || batchStatements.isEmpty())
return new int[0];
@@ -2688,21 +2688,6 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
batchStatements.clear();
batchParameters.clear();
- // Close any existing resultsets associated with this statement.
- while (firstUnclosedResult != null)
- {
- if (firstUnclosedResult.getResultSet() != null)
- {
- firstUnclosedResult.getResultSet().close();
- }
- firstUnclosedResult = firstUnclosedResult.getNext();
- }
-
- if (lastSimpleQuery != null) {
- lastSimpleQuery.close();
- lastSimpleQuery = null;
- }
-
int flags = QueryExecutor.QUERY_NO_RESULTS;
// Only use named statements after we hit the threshold
diff --git a/org/postgresql/test/jdbc3/GeneratedKeysTest.java b/org/postgresql/test/jdbc3/GeneratedKeysTest.java
index 3ad3631..61cfd03 100644
--- a/org/postgresql/test/jdbc3/GeneratedKeysTest.java
+++ b/org/postgresql/test/jdbc3/GeneratedKeysTest.java
@@ -3,7 +3,7 @@
* Copyright (c) 2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc3/GeneratedKeysTest.java,v 1.1 2008/11/15 17:48:53 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc3/GeneratedKeysTest.java,v 1.2 2009/01/28 09:50:21 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -203,5 +203,15 @@ public class GeneratedKeysTest extends TestCase {
assertTrue(!rs.next());
}
+ public void testGeneratedKeysCleared() throws SQLException {
+ Statement stmt = _conn.createStatement();
+ stmt.executeUpdate("INSERT INTO genkeys VALUES (1, 'a', 2); ", Statement.RETURN_GENERATED_KEYS);
+ ResultSet rs = stmt.getGeneratedKeys();
+ assertTrue(rs.next());
+ stmt.executeUpdate("INSERT INTO genkeys VALUES (2, 'b', 3)");
+ rs = stmt.getGeneratedKeys();
+ assertTrue(!rs.next());
+ }
+
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git
More information about the pkg-java-commits
mailing list