diff options
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/jdbc1')
6 files changed, 74 insertions, 3 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java index 99e42b5c92c..ee1db017cf9 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java @@ -9,7 +9,7 @@ * Copyright (c) 2003, PostgreSQL Global Development Group * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.11 2003/03/08 06:06:55 barry Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.12 2003/05/03 20:40:45 barry Exp $ * *------------------------------------------------------------------------- */ @@ -575,11 +575,18 @@ public abstract class AbstractJdbc1ResultSet implements BaseResultSet return getBytes(columnIndex); 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/jdbc1/AbstractJdbc1Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java index 8f39d2bb24c..c473dd240bd 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java @@ -13,7 +13,7 @@ import org.postgresql.core.QueryExecutor; import org.postgresql.largeobject.*; import org.postgresql.util.*; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.20 2003/04/17 04:37:07 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.21 2003/05/03 20:40:45 barry Exp $ * This class defines methods of the jdbc1 specification. This class is * extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2 * methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement @@ -871,6 +871,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement break; case Types.BINARY: case Types.VARBINARY: + case Types.LONGVARBINARY: l_pgType = PG_BYTEA; break; case Types.OTHER: @@ -1490,6 +1491,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement break; case Types.BINARY: case Types.VARBINARY: + case Types.LONGVARBINARY: setObject(parameterIndex, x); break; case Types.OTHER: diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1CallableStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1CallableStatement.java index bb30580c3c5..697a1869ab7 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1CallableStatement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1CallableStatement.java @@ -3,6 +3,7 @@ package org.postgresql.jdbc1; 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 Jdbc1CallableStatement extends AbstractJdbc1Statement implements ja { return new Jdbc1ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor); } + + public PGRefCursorResultSet createRefCursorResultSet (String cursorName) throws SQLException + { + return new Jdbc1RefCursorResultSet(this, cursorName); + } } diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1PreparedStatement.java index 87e64d69064..a80928ebddf 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1PreparedStatement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1PreparedStatement.java @@ -2,6 +2,7 @@ package org.postgresql.jdbc1; import java.sql.*; +import org.postgresql.PGRefCursorResultSet; import org.postgresql.core.BaseResultSet; import org.postgresql.core.Field; @@ -17,4 +18,9 @@ public class Jdbc1PreparedStatement extends AbstractJdbc1Statement implements Pr { return new Jdbc1ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor); } + + public PGRefCursorResultSet createRefCursorResultSet (String cursorName) throws SQLException + { + return new Jdbc1RefCursorResultSet(this, cursorName); + } } diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1RefCursorResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1RefCursorResultSet.java new file mode 100644 index 00000000000..7b83bf67427 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1RefCursorResultSet.java @@ -0,0 +1,44 @@ +package org.postgresql.jdbc1; + +import java.sql.SQLException; +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 Jdbc1RefCursorResultSet extends Jdbc1ResultSet + implements PGRefCursorResultSet +{ + + // The name of the cursor being used. + String refCursorHandle; + + // Indicates when the result set has activaly bound to the cursor. + boolean isInitialized = false; + + + Jdbc1RefCursorResultSet(BaseStatement statement, String refCursorName) + { + super(statement, null, null, null, -1, 0L, false); + this.refCursorHandle = refCursorName; + } + + public String getRefCursor () + { + return refCursorHandle; + } + + public boolean next () throws 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/jdbc1/Jdbc1Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1Statement.java index 67cb91b32e6..38edfd87e0d 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1Statement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1Statement.java @@ -3,10 +3,11 @@ package org.postgresql.jdbc1; 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/jdbc1/Attic/Jdbc1Statement.java,v 1.5 2003/03/07 18:39:44 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Statement.java,v 1.6 2003/05/03 20:40:45 barry Exp $ * This class implements the java.sql.Statement interface for JDBC1. * However most of the implementation is really done in * org.postgresql.jdbc1.AbstractJdbc1Statement @@ -23,4 +24,9 @@ public class Jdbc1Statement extends org.postgresql.jdbc1.AbstractJdbc1Statement { return new Jdbc1ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor); } + + public PGRefCursorResultSet createRefCursorResultSet (String cursorName) throws SQLException + { + return new Jdbc1RefCursorResultSet(this, cursorName); + } } |