From 5295fffc26d9bb02fc3b51cbb4f7de744ee50046 Mon Sep 17 00:00:00 2001 From: Barry Lind Date: Sat, 3 May 2003 20:40:45 +0000 Subject: Patch to fix up LONGVARBINARY support submitted by Amit Gollapudi (agollapudi@demandsolutions.com). Also applied the RefCursor support patch by Nic Ferrier. This patch allows you too return a get a result set from a function that returns a refcursor. For example: call.registerOutParameter(1, Types.OTHER); call.execute(); ResultSet rs = (ResultSet) call.getObject(1); Modified Files: jdbc/org/postgresql/core/BaseStatement.java jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java jdbc/org/postgresql/jdbc1/Jdbc1CallableStatement.java jdbc/org/postgresql/jdbc1/Jdbc1PreparedStatement.java jdbc/org/postgresql/jdbc1/Jdbc1Statement.java jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java jdbc/org/postgresql/jdbc2/Jdbc2Statement.java jdbc/org/postgresql/jdbc3/Jdbc3CallableStatement.java jdbc/org/postgresql/jdbc3/Jdbc3PreparedStatement.java jdbc/org/postgresql/jdbc3/Jdbc3Statement.java Added Files: jdbc/org/postgresql/PGRefCursorResultSet.java jdbc/org/postgresql/jdbc1/Jdbc1RefCursorResultSet.java jdbc/org/postgresql/jdbc2/Jdbc2RefCursorResultSet.java jdbc/org/postgresql/jdbc3/Jdbc3RefCursorResultSet.java jdbc/org/postgresql/test/jdbc2/RefCursorTest.java --- .../postgresql/jdbc3/Jdbc3CallableStatement.java | 5 +++ .../postgresql/jdbc3/Jdbc3PreparedStatement.java | 10 ++++- .../postgresql/jdbc3/Jdbc3RefCursorResultSet.java | 47 ++++++++++++++++++++++ .../jdbc/org/postgresql/jdbc3/Jdbc3Statement.java | 7 +++- 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3RefCursorResultSet.java (limited to 'src/interfaces/jdbc/org/postgresql/jdbc3') diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3CallableStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3CallableStatement.java index 2b71e192cfe..0008f0e98ca 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3CallableStatement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3CallableStatement.java @@ -3,6 +3,7 @@ package org.postgresql.jdbc3; import java.sql.*; import java.util.Vector; +import org.postgresql.PGRefCursorResultSet; import org.postgresql.core.BaseResultSet; import org.postgresql.core.Field; @@ -19,5 +20,9 @@ public class Jdbc3CallableStatement extends org.postgresql.jdbc3.AbstractJdbc3St return new Jdbc3ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor); } + public PGRefCursorResultSet createRefCursorResultSet (String cursorName) throws SQLException + { + return new Jdbc3RefCursorResultSet(this, cursorName); + } } diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PreparedStatement.java index 229a4353cd4..e9e25f76b02 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PreparedStatement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3PreparedStatement.java @@ -2,7 +2,9 @@ package org.postgresql.jdbc3; import java.sql.*; +import org.postgresql.PGRefCursorResultSet; import org.postgresql.core.BaseResultSet; +import org.postgresql.core.BaseStatement; import org.postgresql.core.Field; public class Jdbc3PreparedStatement extends org.postgresql.jdbc3.AbstractJdbc3Statement implements java.sql.PreparedStatement @@ -15,8 +17,12 @@ public class Jdbc3PreparedStatement extends org.postgresql.jdbc3.AbstractJdbc3St public BaseResultSet createResultSet (Field[] fields, java.util.Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException { - return new Jdbc3ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor); + return new Jdbc3ResultSet((BaseStatement)this, fields, tuples, status, updateCount, insertOID, binaryCursor); + } + + public PGRefCursorResultSet createRefCursorResultSet (String cursorName) throws SQLException + { + return new Jdbc3RefCursorResultSet(this, cursorName); } - } diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3RefCursorResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3RefCursorResultSet.java new file mode 100644 index 00000000000..fe18672a7b3 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3RefCursorResultSet.java @@ -0,0 +1,47 @@ +package org.postgresql.jdbc3; + +import org.postgresql.core.QueryExecutor; +import org.postgresql.core.Field; +import org.postgresql.core.BaseStatement; +import java.util.Vector; +import org.postgresql.PGConnection; +import org.postgresql.PGRefCursorResultSet; + +/** A real result set based on a ref cursor. + * + * @author Nic Ferrier + */ +public class Jdbc3RefCursorResultSet extends Jdbc3ResultSet implements PGRefCursorResultSet +{ + + String refCursorHandle; + + // Indicates when the result set has activaly bound to the cursor. + boolean isInitialized = false; + + Jdbc3RefCursorResultSet(java.sql.Statement statement, String refCursorName) throws java.sql.SQLException + { + // This casting is a GCJ requirement. + super((BaseStatement)statement, + (Field[])null, + (Vector)null, + (String)null, -1, 0L, false); + this.refCursorHandle = refCursorName; + } + + public String getRefCursor () + { + return refCursorHandle; + } + + public boolean next () throws java.sql.SQLException + { + if (isInitialized) + return super.next(); + // Initialize this res set with the rows from the cursor. + String[] toExec = { "FETCH ALL IN \"" + refCursorHandle + "\";" }; + QueryExecutor.execute(toExec, new String[0], this); + isInitialized = true; + return super.next(); + } +} diff --git a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Statement.java index aa8cf00ca63..eedea2f5f05 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Statement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc3/Jdbc3Statement.java @@ -3,10 +3,11 @@ package org.postgresql.jdbc3; import java.sql.*; import java.util.Vector; +import org.postgresql.PGRefCursorResultSet; import org.postgresql.core.BaseResultSet; import org.postgresql.core.Field; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3Statement.java,v 1.4 2003/03/07 18:39:45 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3Statement.java,v 1.5 2003/05/03 20:40:45 barry Exp $ * This class implements the java.sql.Statement interface for JDBC3. * However most of the implementation is really done in * org.postgresql.jdbc3.AbstractJdbc3Statement or one of it's parents @@ -24,4 +25,8 @@ public class Jdbc3Statement extends org.postgresql.jdbc3.AbstractJdbc3Statement return new Jdbc3ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor); } + public PGRefCursorResultSet createRefCursorResultSet (String cursorName) throws SQLException + { + return new Jdbc3RefCursorResultSet(this, cursorName); + } } -- cgit v1.2.3