postgresql-jdbc.git / summary / log / commit / refs
commit 4fb003bdf03703d21a94bf2b37be49dbcdb4df0a
Author: Kris Jurka <books@ejurka.com>
Date: Mon Sep 13 12:19:00 2004 +0000
Fix NullPointerException when doing a multiple query execution in
one statement using the V3 protocol. For example:
Statement.exceute("SELECT 1; SELECT 2");
would not have any parameters set and try to iterate over a null
array.
Reported by airconditionedgypsy.
org/postgresql/core/v3/QueryExecutorImpl.java | 15 +++++++++++++--
org/postgresql/test/jdbc2/StatementTest.java | 18 ++++++++++++++++++
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/org/postgresql/core/v3/QueryExecutorImpl.java b/org/postgresql/core/v3/QueryExecutorImpl.java
index 279d6a21..357cba91 100644
--- a/org/postgresql/core/v3/QueryExecutorImpl.java
+++ b/org/postgresql/core/v3/QueryExecutorImpl.java
@@ -445,8 +445,19 @@ public class QueryExecutorImpl implements QueryExecutor {
if (subqueries == null) {
sendOneQuery((SimpleQuery)query, (SimpleParameterList)parameters, maxRows, fetchSize, flags);
} else {
- for (int i = 0; i < subqueries.length; ++i)
- sendOneQuery(subqueries[i], subparams[i], maxRows, fetchSize, flags);
+ for (int i = 0; i < subqueries.length; ++i) {
+ // In the situation where parameters is already
+ // NO_PARAMETERS it cannot know the correct
+ // number of array elements to return in the
+ // above call to getSubparams(), so it must
+ // return null which we check for here.
+ //
+ SimpleParameterList subparam = SimpleQuery.NO_PARAMETERS;
+ if (subparams != null) {
+ subparam = subparams[i];
+ }
+ sendOneQuery(subqueries[i], subparam, maxRows, fetchSize, flags);
+ }
}
}
diff --git a/org/postgresql/test/jdbc2/StatementTest.java b/org/postgresql/test/jdbc2/StatementTest.java
index e8807d8e..6faa39be 100644
--- a/org/postgresql/test/jdbc2/StatementTest.java
+++ b/org/postgresql/test/jdbc2/StatementTest.java
@@ -64,6 +64,24 @@ public class StatementTest extends TestCase
stmt.close();
}
+ public void testMultiExecute() throws SQLException
+ {
+ Statement stmt = con.createStatement();
+ stmt.execute("SELECT 1; SELECT 2");
+
+ ResultSet rs = stmt.getResultSet();
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+ rs.close();
+
+ assertTrue(stmt.getMoreResults());
+ rs = stmt.getResultSet();
+ assertTrue(rs.next());
+ assertEquals(2, rs.getInt(1));
+ rs.close();
+ stmt.close();
+ }
+
public void testUpdateCount() throws SQLException
{
Statement stmt = con.createStatement();
[parent: 89d9e80ec44d]