summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/org/postgresql/jdbc2
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/jdbc2')
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java9
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java6
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java7
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2RefCursorResultSet.java43
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Statement.java8
5 files changed, 71 insertions, 2 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
index 46ebdb47cec..21514235027 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
@@ -9,7 +9,7 @@
* Copyright (c) 2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.18 2003/03/25 02:24:07 davec Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.19 2003/05/03 20:40:45 barry Exp $
*
*-------------------------------------------------------------------------
*/
@@ -148,11 +148,18 @@ public abstract class AbstractJdbc2ResultSet extends org.postgresql.jdbc1.Abstra
default:
String type = field.getPGType();
+
// if the backend doesn't know the type then coerce to String
if (type.equals("unknown"))
{
return getString(columnIndex);
}
+ // Specialized support for ref cursors is neater.
+ else if (type.equals("refcursor"))
+ {
+ String cursorName = getString(columnIndex);
+ return statement.createRefCursorResultSet(cursorName);
+ }
else
{
return connection.getObject(field.getPGType(), getString(columnIndex));
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java
index 5b8e76e122d..e10223e975c 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2CallableStatement.java
@@ -3,6 +3,7 @@ package org.postgresql.jdbc2;
import java.sql.*;
import java.util.Vector;
+import org.postgresql.PGRefCursorResultSet;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.Field;
@@ -18,5 +19,10 @@ public class Jdbc2CallableStatement extends org.postgresql.jdbc2.AbstractJdbc2St
{
return new Jdbc2ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}
+
+ public PGRefCursorResultSet createRefCursorResultSet (String cursorName) throws SQLException
+ {
+ return new Jdbc2RefCursorResultSet(this, cursorName);
+ }
}
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java
index 4eeded05fdc..83023f05f44 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2PreparedStatement.java
@@ -3,6 +3,7 @@ package org.postgresql.jdbc2;
import java.sql.*;
import java.util.Vector;
+import org.postgresql.PGRefCursorResultSet;
import org.postgresql.core.BaseResultSet;
import org.postgresql.core.Field;
@@ -18,5 +19,11 @@ public class Jdbc2PreparedStatement extends org.postgresql.jdbc2.AbstractJdbc2St
{
return new Jdbc2ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}
+
+
+ public PGRefCursorResultSet createRefCursorResultSet (String cursorName) throws SQLException
+ {
+ return new Jdbc2RefCursorResultSet(this, cursorName);
+ }
}
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2RefCursorResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2RefCursorResultSet.java
new file mode 100644
index 00000000000..08ec33d752f
--- /dev/null
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2RefCursorResultSet.java
@@ -0,0 +1,43 @@
+package org.postgresql.jdbc2;
+
+
+import org.postgresql.core.QueryExecutor;
+import org.postgresql.core.BaseStatement;
+import org.postgresql.PGRefCursorResultSet;
+
+
+/** A real result set based on a ref cursor.
+ *
+ * @author Nic Ferrier <nferrier@tapsellferrier.co.uk>
+ */
+public class Jdbc2RefCursorResultSet extends Jdbc2ResultSet
+ implements PGRefCursorResultSet
+{
+
+ String refCursorHandle;
+
+ // Indicates when the result set has activaly bound to the cursor.
+ boolean isInitialized = false;
+
+ Jdbc2RefCursorResultSet(BaseStatement statement, String refCursorName) throws java.sql.SQLException
+ {
+ super(statement, null, null, 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/jdbc2/Jdbc2Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Statement.java
index a1328dd3fba..eb78a889b36 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Statement.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/Jdbc2Statement.java
@@ -3,10 +3,11 @@ package org.postgresql.jdbc2;
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/jdbc2/Attic/Jdbc2Statement.java,v 1.5 2003/03/07 18:39:45 barry Exp $
+/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2Statement.java,v 1.6 2003/05/03 20:40:45 barry Exp $
* This class implements the java.sql.Statement interface for JDBC2.
* However most of the implementation is really done in
* org.postgresql.jdbc2.AbstractJdbc2Statement or one of it's parents
@@ -23,4 +24,9 @@ public class Jdbc2Statement extends org.postgresql.jdbc2.AbstractJdbc2Statement
{
return new Jdbc2ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
}
+
+ public PGRefCursorResultSet createRefCursorResultSet (String cursorName) throws SQLException
+ {
+ return new Jdbc2RefCursorResultSet(this, cursorName);
+ }
}