[libpostgresql-jdbc-java] 02/08: When issuing multiple queries on one statement the driver was not clearing some intermediate state between executions. When an update, insert, or delete followed a select, the select's results were still available and would be returned instead of the non-query's affected row count.

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:19:26 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_0_318
in repository libpostgresql-jdbc-java.

commit 73296b4d99042d9e2633edc5ba4a67676e700953
Author: Kris Jurka <books at ejurka.com>
Date:   Fri Jul 7 01:12:48 2006 +0000

    When issuing multiple queries on one statement the driver was not
    clearing some intermediate state between executions.  When an
    update, insert, or delete followed a select, the select's results
    were still available and would be returned instead of the
    non-query's affected row count.
    
    Example from Gilles Rayrat.
---
 org/postgresql/core/v3/QueryExecutorImpl.java |  8 +++++++-
 org/postgresql/test/jdbc2/StatementTest.java  | 10 ++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/org/postgresql/core/v3/QueryExecutorImpl.java b/org/postgresql/core/v3/QueryExecutorImpl.java
index 75ba450..d62593e 100644
--- a/org/postgresql/core/v3/QueryExecutorImpl.java
+++ b/org/postgresql/core/v3/QueryExecutorImpl.java
@@ -4,7 +4,7 @@
 * Copyright (c) 2004, Open Cloud Limited.
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.21.2.3 2006/04/29 00:07:10 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.21.2.4 2006/04/29 13:31:28 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -1204,6 +1204,8 @@ public class QueryExecutorImpl implements QueryExecutor {
                     if (fields != null || tuples != null)
                     { // There was a resultset.
                         handler.handleResultRows(currentQuery, fields, tuples, null);
+                        fields = null;
+                        tuples = null;
                     }
                 }
                 break;
@@ -1241,6 +1243,8 @@ public class QueryExecutorImpl implements QueryExecutor {
                     if (fields != null || tuples != null)
                     { // There was a resultset.
                         handler.handleResultRows(currentQuery, fields, tuples, null);
+                        fields = null;
+                        tuples = null;
                     }
                     else
                     {
@@ -1338,6 +1342,8 @@ public class QueryExecutorImpl implements QueryExecutor {
                     if (fields != null || tuples != null)
                     { // There was a resultset.
                         handler.handleResultRows(currentQuery, fields, tuples, null);
+                        fields = null;
+                        tuples = null;
                     }
                 }
                 break;
diff --git a/org/postgresql/test/jdbc2/StatementTest.java b/org/postgresql/test/jdbc2/StatementTest.java
index 20a18fe..79e8606 100644
--- a/org/postgresql/test/jdbc2/StatementTest.java
+++ b/org/postgresql/test/jdbc2/StatementTest.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v 1.15.2.3 2005/12/15 23:29:39 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v 1.15.2.4 2006/02/01 18:52:41 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -79,18 +79,24 @@ public class StatementTest extends TestCase
     public void testMultiExecute() throws SQLException
     {
         Statement stmt = con.createStatement();
-        stmt.execute("SELECT 1; SELECT 2");
+        assertTrue(stmt.execute("SELECT 1; UPDATE test_statement SET i=1; SELECT 2"));
 
         ResultSet rs = stmt.getResultSet();
         assertTrue(rs.next());
         assertEquals(1, rs.getInt(1));
         rs.close();
 
+        assertTrue(!stmt.getMoreResults());
+        assertEquals(0, stmt.getUpdateCount());
+
         assertTrue(stmt.getMoreResults());
         rs = stmt.getResultSet();
         assertTrue(rs.next());
         assertEquals(2, rs.getInt(1));
         rs.close();
+
+        assertTrue(!stmt.getMoreResults());
+        assertEquals(-1, stmt.getUpdateCount());
         stmt.close();
     }
 

-- 
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