[libpostgresql-jdbc-java] 04/12: 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:28 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_2_507
in repository libpostgresql-jdbc-java.
commit 1baf92d290703b9f24b50964e8c68cfbdb34ed71
Author: Kris Jurka <books at ejurka.com>
Date: Mon Oct 15 08:06:39 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..1c65e54 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.9 2006/05/22 09:52:37 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 bb75d89..e303075 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.33 2006/12/01 08:53:45 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.33.2.1 2007/09/24 12:34:15 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -177,6 +177,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 6ed544c..87fa3c8 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.13 2006/05/23 23:05:21 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/core/v3/SimpleParameterList.java,v 1.13.2.1 2007/06/13 07:25:05 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -147,6 +147,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
//
@@ -171,12 +183,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