This is an automated email from the git hooks/post-receive script. ebourg-guest pushed a commit to tag REL9_0_802 in repository libpostgresql-jdbc-java.
commit 638f8601fa720e1a78f8aa4d0eb39bd94a15b71c Author: Kris Jurka <[email protected]> Date: Sat Apr 2 07:31:43 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 aeed2f8..dbf5339 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.118 2010/07/23 19:55:36 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.118.2.1 2011/03/20 00:58:37 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -452,7 +452,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(); @@ -463,12 +463,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; @@ -776,22 +788,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; } @@ -2685,8 +2686,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]; @@ -2700,21 +2700,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 _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

