[libpostgresql-jdbc-java] 03/09: CallableStatements with OUT parameters that get executed more than prepareThreshold times no longer send Parse messages which invoke SimpleParameterList.getTypeOID which has side effects required to setup the parameters correctly. This bug is only exposed if the caller also uses clearParameters() which zeros out state that would otherwise be retained from previous execution. Add an explicit convertFunctionOutParameters method to do this work instead that we call in all execution paths.

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


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

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

commit 1bf9528ddab4f2fd193a4eff2aa3462311b340b5
Author: Kris Jurka <books at ejurka.com>
Date:   Mon Oct 15 08:06:48 2007 +0000

    CallableStatements with OUT parameters that get executed more than
    prepareThreshold times no longer send Parse messages which invoke
    SimpleParameterList.getTypeOID which has side effects required to
    setup the parameters correctly.  This bug is only exposed if the
    caller also uses clearParameters() which zeros out state that would
    otherwise be retained from previous execution.  Add an explicit
    convertFunctionOutParameters method to do this work instead that
    we call in all execution paths.
    
    Example from Ludovico Bianchini.
---
 org/postgresql/core/v3/CompositeParameterList.java |  8 +++++-
 org/postgresql/core/v3/QueryExecutorImpl.java      |  4 ++-
 org/postgresql/core/v3/SimpleParameterList.java    | 20 +++++++++-----
 org/postgresql/core/v3/V3ParameterList.java        |  8 +++++-
 .../test/jdbc3/Jdbc3CallableStatementTest.java     | 32 ++++++++++++++++------
 5 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/org/postgresql/core/v3/CompositeParameterList.java b/org/postgresql/core/v3/CompositeParameterList.java
index ec5d9a3..f8e4e04 100644
--- a/org/postgresql/core/v3/CompositeParameterList.java
+++ b/org/postgresql/core/v3/CompositeParameterList.java
@@ -4,7 +4,7 @@
 * Copyright (c) 2004, Open Cloud Limited.
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/CompositeParameterList.java,v 1.8 2005/07/04 18:50:29 davec Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/CompositeParameterList.java,v 1.8.2.1 2006/05/22 09:56:32 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -135,6 +135,12 @@ class CompositeParameterList implements V3ParameterList {
             subparams[sub].checkAllParametersSet();
     }
 
+    public void convertFunctionOutParameters()
+    {
+        for (int sub = 0; sub < subparams.length; ++sub)
+            subparams[sub].convertFunctionOutParameters();
+    }
+
     private final int total;
     private final SimpleParameterList[] subparams;
     private final int[] offsets;
diff --git a/org/postgresql/core/v3/QueryExecutorImpl.java b/org/postgresql/core/v3/QueryExecutorImpl.java
index 29f11e8..b13a7df 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.25.2.4 2006/07/07 01:12:34 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.25.2.5 2007/09/24 12:34:20 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -174,6 +174,8 @@ public class QueryExecutorImpl implements QueryExecutor {
 
         boolean describeOnly = (QUERY_DESCRIBE_ONLY & flags) != 0;
 
+        ((V3ParameterList)parameters).convertFunctionOutParameters();
+
         // Check parameters are all set..
         if (!describeOnly)
             ((V3ParameterList)parameters).checkAllParametersSet();
diff --git a/org/postgresql/core/v3/SimpleParameterList.java b/org/postgresql/core/v3/SimpleParameterList.java
index e7945fb..0797df5 100644
--- a/org/postgresql/core/v3/SimpleParameterList.java
+++ b/org/postgresql/core/v3/SimpleParameterList.java
@@ -4,7 +4,7 @@
 * Copyright (c) 2004, Open Cloud Limited.
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/SimpleParameterList.java,v 1.10.2.2 2006/05/23 23:05:29 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/SimpleParameterList.java,v 1.10.2.3 2007/06/13 07:25:10 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -151,6 +151,18 @@ class SimpleParameterList implements V3ParameterList {
         }
     }
 
+    public void convertFunctionOutParameters()
+    {
+        for (int i=0; i<paramTypes.length; ++i)
+        {
+            if (direction[i] == OUT)
+            {
+                paramTypes[i] = Oid.VOID;
+                paramValues[i] = "null";
+            }
+        }
+    }
+
     //
     // bytea helper
     //
@@ -175,12 +187,6 @@ class SimpleParameterList implements V3ParameterList {
     //
 
     int getTypeOID(int index) {
-        if (direction[index-1] == OUT)
-        {
-            paramTypes[index-1] = Oid.VOID;
-            paramValues[index-1] = "null";
-        }
-        	
         return paramTypes[index-1];
     }
 
diff --git a/org/postgresql/core/v3/V3ParameterList.java b/org/postgresql/core/v3/V3ParameterList.java
index 5911726..4d80a16 100644
--- a/org/postgresql/core/v3/V3ParameterList.java
+++ b/org/postgresql/core/v3/V3ParameterList.java
@@ -4,7 +4,7 @@
 * Copyright (c) 2004, Open Cloud Limited.
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/V3ParameterList.java,v 1.4 2005/01/11 08:25:44 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/V3ParameterList.java,v 1.5 2005/07/04 18:50:29 davec Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -29,6 +29,12 @@ interface V3ParameterList extends ParameterList {
     void checkAllParametersSet() throws SQLException;
 
     /**
+     * Convert any function output parameters to the correct type (void)
+     * and set an ignorable value for it.
+     */
+    void convertFunctionOutParameters();
+
+    /**
      * Return a list of the SimpleParameterList objects that
      * make up this parameter list. If this object is already a
      * SimpleParameterList, returns null (avoids an extra array
diff --git a/org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java b/org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java
index f7865a3..28f7273 100644
--- a/org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java
+++ b/org/postgresql/test/jdbc3/Jdbc3CallableStatementTest.java
@@ -1,9 +1,12 @@
-/*
- * Created on Jun 21, 2005
- *
- * TODO To change the template for this generated file go to
- * Window - Preferences - Java - Code Style - Code Templates
- */
+/*-------------------------------------------------------------------------
+*
+* Copyright (c) 2005-2007, PostgreSQL Global Development Group
+*
+* IDENTIFICATION
+*   $PostgreSQL$
+*
+*-------------------------------------------------------------------------
+*/
 package org.postgresql.test.jdbc3;
 
 import java.math.BigDecimal;
@@ -23,8 +26,6 @@ import junit.framework.TestCase;
 /**
  * @author davec
  *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
  */
 public class Jdbc3CallableStatementTest extends TestCase
 {
@@ -1100,4 +1101,19 @@ public class Jdbc3CallableStatementTest extends TestCase
             catch (Exception ex){}
         }
     }           
+
+    public void testMultipleOutExecutions() throws SQLException
+    {
+        CallableStatement cs = con.prepareCall("{call myiofunc(?, ?)}");
+        for (int i=0; i<10; i++) {
+            cs.registerOutParameter(1, Types.INTEGER);
+            cs.registerOutParameter(2, Types.INTEGER);
+            cs.setInt(1, i);
+            cs.execute();
+            assertEquals(1, cs.getInt(1));
+            assertEquals(i, cs.getInt(2));
+            cs.clearParameters();
+        }
+    }
+
 }

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