summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/org/postgresql/jdbc1
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/jdbc1')
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java5
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java13
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java404
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/CallableStatement.java322
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java24
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1CallableStatement.java14
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1Connection.java12
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1ResultSet.java11
8 files changed, 440 insertions, 365 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
index 98aa33e5c9..f6d3807bb9 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
@@ -13,7 +13,7 @@ import org.postgresql.largeobject.LargeObjectManager;
import org.postgresql.util.*;
-/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.1 2002/07/23 03:59:55 barry Exp $
+/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.2 2002/07/25 22:45:27 barry Exp $
* This class defines methods of the jdbc1 specification. This class is
* extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds the jdbc2
* methods. The real Connection class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Connection
@@ -359,8 +359,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
// are common to all implementations (JDBC1 or 2), they are placed here.
// This should make it easy to maintain the two specifications.
-//BJL TODO this method shouldn't need to take a Connection since this can be used.
- public abstract java.sql.ResultSet getResultSet(java.sql.Statement stat, org.postgresql.Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException;
+ public abstract java.sql.ResultSet getResultSet(Statement statement, org.postgresql.Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException;
/*
* This adds a warning to the warning chain.
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
index 5aa4f90298..3bb278a8e9 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
@@ -13,15 +13,15 @@ import org.postgresql.largeobject.*;
import org.postgresql.util.PGbytea;
import org.postgresql.util.PSQLException;
-/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.1 2002/07/23 03:59:55 barry Exp $
+/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.2 2002/07/25 22:45:27 barry Exp $
* This class defines methods of the jdbc1 specification. This class is
* extended by org.postgresql.jdbc2.AbstractJdbc2ResultSet which adds the jdbc2
* methods. The real ResultSet class (for jdbc1) is org.postgresql.jdbc1.Jdbc1ResultSet
*/
public abstract class AbstractJdbc1ResultSet
{
-
protected Vector rows; // The results
+ protected Statement statement;
protected Field fields[]; // The field descriptions
protected String status; // Status of the result
protected boolean binaryCursor = false; // is the data binary or Strings
@@ -33,7 +33,7 @@ public abstract class AbstractJdbc1ResultSet
protected SQLWarning warnings = null; // The warning chain
protected boolean wasNullFlag = false; // the flag for wasNull()
- // We can chain multiple resultSets together - this points to
+ // We can chain multiple resultSets together - this points to
// next resultSet in the chain.
protected ResultSet next = null;
@@ -41,9 +41,10 @@ public abstract class AbstractJdbc1ResultSet
public byte[][] rowBuffer=null;
- public AbstractJdbc1ResultSet(org.postgresql.PGConnection conn, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
+ public AbstractJdbc1ResultSet(org.postgresql.PGConnection conn, Statement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
{
this.connection = conn;
+ this.statement = statement;
this.fields = fields;
this.rows = tuples;
this.status = status;
@@ -116,7 +117,7 @@ public abstract class AbstractJdbc1ResultSet
throw new PSQLException("postgresql.res.badbyte", s);
}
}
- return 0; // SQL NULL
+ return 0; // SQL NULL
}
public short getShort(int columnIndex) throws SQLException
@@ -134,7 +135,7 @@ public abstract class AbstractJdbc1ResultSet
throw new PSQLException("postgresql.res.badshort", s);
}
}
- return 0; // SQL NULL
+ return 0; // SQL NULL
}
public int getInt(int columnIndex) throws SQLException
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
index 6b06cc873e..96a50efa8f 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
@@ -8,7 +8,7 @@ import java.util.Vector;
import org.postgresql.largeobject.*;
import org.postgresql.util.*;
-/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.2 2002/07/24 22:08:39 barry Exp $
+/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.3 2002/07/25 22:45:27 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
@@ -47,6 +47,20 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
protected String[] templateStrings;
protected String[] inStrings;
+ //Used by the callablestatement style methods
+ private static final String JDBC_SYNTAX = "{[? =] call <some_function> ([? [,?]*]) }";
+ private static final String RESULT_COLUMN = "result";
+ private String originalSql = "";
+ private boolean isFunction;
+ // functionReturnType contains the user supplied value to check
+ // testReturn contains a modified version to make it easier to
+ // check the getXXX methods..
+ private int functionReturnType;
+ private int testReturn;
+ // returnTypeSet is true when a proper call to registerOutParameter has been made
+ private boolean returnTypeSet;
+ protected Object callResult;
+
public AbstractJdbc1Statement (AbstractJdbc1Connection connection)
@@ -62,6 +76,10 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
}
protected void parseSqlStmt () throws SQLException {
+ if (this instanceof CallableStatement) {
+ modifyJdbcCall();
+ }
+
Vector v = new Vector();
boolean inQuotes = false;
int lastParmEnd = 0, i;
@@ -179,7 +197,23 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
// New in 7.1, pass Statement so that ExecSQL can customise to it
result = ((AbstractJdbc1Connection)connection).ExecSQL(sql, (java.sql.Statement)this);
- return (result != null && ((AbstractJdbc1ResultSet)result).reallyResultSet());
+ //If we are executing a callable statement function set the return data
+ if (isFunction) {
+ if (!((AbstractJdbc1ResultSet)result).reallyResultSet())
+ throw new PSQLException("postgresql.call.noreturnval");
+ if (!result.next ())
+ throw new PSQLException ("postgresql.call.noreturnval");
+ callResult = result.getObject(1);
+ int columnType = result.getMetaData().getColumnType(1);
+ if (columnType != functionReturnType)
+ throw new PSQLException ("postgresql.call.wrongrtntype",
+ new Object[]{
+ "java.sql.Types=" + columnType, "java.sql.Types="+functionReturnType });
+ result.close ();
+ return true;
+ } else {
+ return (result != null && ((AbstractJdbc1ResultSet)result).reallyResultSet());
+ }
}
/*
@@ -233,6 +267,8 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
{
if (result == null)
return -1;
+ if (isFunction)
+ return 1;
if (((AbstractJdbc1ResultSet)result).reallyResultSet())
return -1;
return ((AbstractJdbc1ResultSet)result).getResultCount();
@@ -253,14 +289,6 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
-
-
-
-
-
-
-
-
/*
* Returns the status message from the current Result.<p>
* This is used internally by the driver.
@@ -1215,6 +1243,291 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
}
/*
+ * Before executing a stored procedure call you must explicitly
+ * call registerOutParameter to register the java.sql.Type of each
+ * out parameter.
+ *
+ * <p>Note: When reading the value of an out parameter, you must use
+ * the getXXX method whose Java type XXX corresponds to the
+ * parameter's registered SQL type.
+ *
+ * ONLY 1 RETURN PARAMETER if {?= call ..} syntax is used
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @param sqlType SQL type code defined by java.sql.Types; for
+ * parameters of type Numeric or Decimal use the version of
+ * registerOutParameter that accepts a scale value
+ * @exception SQLException if a database-access error occurs.
+ */
+ public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException
+ {
+ if (parameterIndex != 1)
+ throw new PSQLException ("postgresql.call.noinout");
+ if (!isFunction)
+ throw new PSQLException ("postgresql.call.procasfunc", originalSql);
+
+ // functionReturnType contains the user supplied value to check
+ // testReturn contains a modified version to make it easier to
+ // check the getXXX methods..
+ functionReturnType = sqlType;
+ testReturn = sqlType;
+ if (functionReturnType == Types.CHAR ||
+ functionReturnType == Types.LONGVARCHAR)
+ testReturn = Types.VARCHAR;
+ else if (functionReturnType == Types.FLOAT)
+ testReturn = Types.REAL; // changes to streamline later error checking
+ returnTypeSet = true;
+ }
+
+ /*
+ * You must also specify the scale for numeric/decimal types:
+ *
+ * <p>Note: When reading the value of an out parameter, you must use
+ * the getXXX method whose Java type XXX corresponds to the
+ * parameter's registered SQL type.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @param sqlType use either java.sql.Type.NUMERIC or java.sql.Type.DECIMAL
+ * @param scale a value greater than or equal to zero representing the
+ * desired number of digits to the right of the decimal point
+ * @exception SQLException if a database-access error occurs.
+ */
+ public void registerOutParameter(int parameterIndex, int sqlType,
+ int scale) throws SQLException
+ {
+ registerOutParameter (parameterIndex, sqlType); // ignore for now..
+ }
+
+ /*
+ * An OUT parameter may have the value of SQL NULL; wasNull
+ * reports whether the last value read has this special value.
+ *
+ * <p>Note: You must first call getXXX on a parameter to read its
+ * value and then call wasNull() to see if the value was SQL NULL.
+ * @return true if the last parameter read was SQL NULL
+ * @exception SQLException if a database-access error occurs.
+ */
+ public boolean wasNull() throws SQLException
+ {
+ // check to see if the last access threw an exception
+ return (callResult == null);
+ }
+
+ /*
+ * Get the value of a CHAR, VARCHAR, or LONGVARCHAR parameter as a
+ * Java String.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return the parameter value; if the value is SQL NULL, the result is null
+ * @exception SQLException if a database-access error occurs.
+ */
+ public String getString(int parameterIndex) throws SQLException
+ {
+ checkIndex (parameterIndex, Types.VARCHAR, "String");
+ return (String)callResult;
+ }
+
+
+ /*
+ * Get the value of a BIT parameter as a Java boolean.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return the parameter value; if the value is SQL NULL, the result is false
+ * @exception SQLException if a database-access error occurs.
+ */
+ public boolean getBoolean(int parameterIndex) throws SQLException
+ {
+ checkIndex (parameterIndex, Types.BIT, "Boolean");
+ if (callResult == null) return false;
+ return ((Boolean)callResult).booleanValue ();
+ }
+
+ /*
+ * Get the value of a TINYINT parameter as a Java byte.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return the parameter value; if the value is SQL NULL, the result is 0
+ * @exception SQLException if a database-access error occurs.
+ */
+ public byte getByte(int parameterIndex) throws SQLException
+ {
+ checkIndex (parameterIndex, Types.TINYINT, "Byte");
+ if (callResult == null) return 0;
+ return (byte)((Integer)callResult).intValue ();
+ }
+
+ /*
+ * Get the value of a SMALLINT parameter as a Java short.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return the parameter value; if the value is SQL NULL, the result is 0
+ * @exception SQLException if a database-access error occurs.
+ */
+ public short getShort(int parameterIndex) throws SQLException
+ {
+ checkIndex (parameterIndex, Types.SMALLINT, "Short");
+ if (callResult == null) return 0;
+ return (short)((Integer)callResult).intValue ();
+ }
+
+
+ /*
+ * Get the value of an INTEGER parameter as a Java int.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return the parameter value; if the value is SQL NULL, the result is 0
+ * @exception SQLException if a database-access error occurs.
+ */
+ public int getInt(int parameterIndex) throws SQLException
+ {
+ checkIndex (parameterIndex, Types.INTEGER, "Int");
+ if (callResult == null) return 0;
+ return ((Integer)callResult).intValue ();
+ }
+
+ /*
+ * Get the value of a BIGINT parameter as a Java long.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return the parameter value; if the value is SQL NULL, the result is 0
+ * @exception SQLException if a database-access error occurs.
+ */
+ public long getLong(int parameterIndex) throws SQLException
+ {
+ checkIndex (parameterIndex, Types.BIGINT, "Long");
+ if (callResult == null) return 0;
+ return ((Long)callResult).longValue ();
+ }
+
+ /*
+ * Get the value of a FLOAT parameter as a Java float.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return the parameter value; if the value is SQL NULL, the result is 0
+ * @exception SQLException if a database-access error occurs.
+ */
+ public float getFloat(int parameterIndex) throws SQLException
+ {
+ checkIndex (parameterIndex, Types.REAL, "Float");
+ if (callResult == null) return 0;
+ return ((Float)callResult).floatValue ();
+ }
+
+ /*
+ * Get the value of a DOUBLE parameter as a Java double.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return the parameter value; if the value is SQL NULL, the result is 0
+ * @exception SQLException if a database-access error occurs.
+ */
+ public double getDouble(int parameterIndex) throws SQLException
+ {
+ checkIndex (parameterIndex, Types.DOUBLE, "Double");
+ if (callResult == null) return 0;
+ return ((Double)callResult).doubleValue ();
+ }
+
+ /*
+ * Get the value of a NUMERIC parameter as a java.math.BigDecimal
+ * object.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @param scale a value greater than or equal to zero representing the
+ * desired number of digits to the right of the decimal point
+ * @return the parameter value; if the value is SQL NULL, the result is null
+ * @exception SQLException if a database-access error occurs.
+ * @deprecated in Java2.0
+ */
+ public BigDecimal getBigDecimal(int parameterIndex, int scale)
+ throws SQLException
+ {
+ checkIndex (parameterIndex, Types.NUMERIC, "BigDecimal");
+ return ((BigDecimal)callResult);
+ }
+
+ /*
+ * Get the value of a SQL BINARY or VARBINARY parameter as a Java
+ * byte[]
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return the parameter value; if the value is SQL NULL, the result is null
+ * @exception SQLException if a database-access error occurs.
+ */
+ public byte[] getBytes(int parameterIndex) throws SQLException
+ {
+ checkIndex (parameterIndex, Types.VARBINARY, "Bytes");
+ return ((byte [])callResult);
+ }
+
+
+ /*
+ * Get the value of a SQL DATE parameter as a java.sql.Date object
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return the parameter value; if the value is SQL NULL, the result is null
+ * @exception SQLException if a database-access error occurs.
+ */
+ public java.sql.Date getDate(int parameterIndex) throws SQLException
+ {
+ checkIndex (parameterIndex, Types.DATE, "Date");
+ return (java.sql.Date)callResult;
+ }
+
+ /*
+ * Get the value of a SQL TIME parameter as a java.sql.Time object.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return the parameter value; if the value is SQL NULL, the result is null
+ * @exception SQLException if a database-access error occurs.
+ */
+ public java.sql.Time getTime(int parameterIndex) throws SQLException
+ {
+ checkIndex (parameterIndex, Types.TIME, "Time");
+ return (java.sql.Time)callResult;
+ }
+
+ /*
+ * Get the value of a SQL TIMESTAMP parameter as a java.sql.Timestamp object.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return the parameter value; if the value is SQL NULL, the result is null
+ * @exception SQLException if a database-access error occurs.
+ */
+ public java.sql.Timestamp getTimestamp(int parameterIndex)
+ throws SQLException
+ {
+ checkIndex (parameterIndex, Types.TIMESTAMP, "Timestamp");
+ return (java.sql.Timestamp)callResult;
+ }
+
+ // getObject returns a Java object for the parameter.
+ // See the JDBC spec's "Dynamic Programming" chapter for details.
+ /*
+ * Get the value of a parameter as a Java object.
+ *
+ * <p>This method returns a Java object whose type coresponds to the
+ * SQL type that was registered for this parameter using
+ * registerOutParameter.
+ *
+ * <P>Note that this method may be used to read datatabase-specific,
+ * abstract data types. This is done by specifying a targetSqlType
+ * of java.sql.types.OTHER, which allows the driver to return a
+ * database-specific Java type.
+ *
+ * <p>See the JDBC spec's "Dynamic Programming" chapter for details.
+ *
+ * @param parameterIndex the first parameter is 1, the second is 2,...
+ * @return A java.lang.Object holding the OUT parameter value.
+ * @exception SQLException if a database-access error occurs.
+ */
+ public Object getObject(int parameterIndex)
+ throws SQLException
+ {
+ checkIndex (parameterIndex);
+ return callResult;
+ }
+
+ /*
* Returns the SQL statement with the current template values
* substituted.
* NB: This is identical to compileQuery() except instead of throwing
@@ -1253,6 +1566,8 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
{
if (paramIndex < 1 || paramIndex > inStrings.length)
throw new PSQLException("postgresql.prep.range");
+ if (paramIndex == 1 && isFunction) // need to registerOut instead
+ throw new PSQLException ("postgresql.call.funcover");
inStrings[paramIndex - 1] = s;
}
@@ -1267,6 +1582,13 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
sbuf.setLength(0);
int i;
+ if (isFunction && !returnTypeSet)
+ throw new PSQLException("postgresql.call.noreturntype");
+ if (isFunction) { // set entry 1 to dummy entry..
+ inStrings[0] = ""; // dummy entry which ensured that no one overrode
+ // and calls to setXXX (2,..) really went to first arg in a function call..
+ }
+
for (i = 0 ; i < inStrings.length ; ++i)
{
if (inStrings[i] == null)
@@ -1299,5 +1621,67 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
set(parameterIndex, Long.toString(x) + "::" + tablename );
}
+ /**
+ * this method will turn a string of the form
+ * {? = call <some_function> (?, [?,..]) }
+ * into the PostgreSQL format which is
+ * select <some_function> (?, [?, ...]) as result
+ *
+ */
+ private void modifyJdbcCall() throws SQLException {
+ // syntax checking is not complete only a few basics :(
+ originalSql = sql; // save for error msgs..
+ int index = sql.indexOf ("="); // is implied func or proc?
+ boolean isValid = true;
+ if (index != -1) {
+ isFunction = true;
+ isValid = sql.indexOf ("?") < index; // ? before =
+ }
+ sql = sql.trim ();
+ if (sql.startsWith ("{") && sql.endsWith ("}")) {
+ sql = sql.substring (1, sql.length() -1);
+ } else isValid = false;
+ index = sql.indexOf ("call");
+ if (index == -1 || !isValid)
+ throw new PSQLException ("postgresql.call.malformed",
+ new Object[]{sql, JDBC_SYNTAX});
+ sql = sql.replace ('{', ' '); // replace these characters
+ sql = sql.replace ('}', ' ');
+ sql = sql.replace (';', ' ');
+
+ // this removes the 'call' string and also puts a hidden '?'
+ // at the front of the line for functions, this will
+ // allow the registerOutParameter to work correctly
+ // because in the source sql there was one more ? for the return
+ // value that is not needed by the postgres syntax. But to make
+ // sure that the parameter numbers are the same as in the original
+ // sql we add a dummy parameter in this case
+ sql = (isFunction ? "?" : "") + sql.substring (index + 4);
+
+ sql = "select " + sql + " as " + RESULT_COLUMN + ";";
+ }
+
+ /** helperfunction for the getXXX calls to check isFunction and index == 1
+ */
+ protected void checkIndex (int parameterIndex, int type, String getName)
+ throws SQLException {
+ checkIndex (parameterIndex);
+ if (type != this.testReturn)
+ throw new PSQLException("postgresql.call.wrongget",
+ new Object[]{"java.sql.Types="+testReturn,
+ getName,
+ "java.sql.Types="+type});
+ }
+ /** helperfunction for the getXXX calls to check isFunction and index == 1
+ * @param parameterIndex index of getXXX (index)
+ * check to make sure is a function and index == 1
+ */
+ private void checkIndex (int parameterIndex) throws SQLException {
+ if (!isFunction)
+ throw new PSQLException("postgresql.call.noreturntype");
+ if (parameterIndex != 1)
+ throw new PSQLException("postgresql.call.noinout");
+ }
+
}
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/CallableStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/CallableStatement.java
deleted file mode 100644
index dab157f97b..0000000000
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/CallableStatement.java
+++ /dev/null
@@ -1,322 +0,0 @@
-package org.postgresql.jdbc1;
-
-// IMPORTANT NOTE: This file implements the JDBC 1 version of the driver.
-// If you make any modifications to this file, you must make sure that the
-// changes are also made (if relevent) to the related JDBC 2 class in the
-// org.postgresql.jdbc2 package.
-
-import java.sql.*;
-import java.math.*;
-
-/*
- * CallableStatement is used to execute SQL stored procedures.
- *
- * <p>JDBC provides a stored procedure SQL escape that allows stored
- * procedures to be called in a standard way for all RDBMS's. This escape
- * syntax has one form that includes a result parameter and one that does
- * not. If used, the result parameter must be registered as an OUT
- * parameter. The other parameters may be used for input, output or both.
- * Parameters are refered to sequentially, by number. The first parameter
- * is 1.
- *
- * {?= call <procedure-name>[<arg1>,<arg2>, ...]}
- * {call <procedure-name>[<arg1>,<arg2>, ...]}
- *
- *
- * <p>IN parameter values are set using the set methods inherited from
- * PreparedStatement. The type of all OUT parameters must be registered
- * prior to executing the stored procedure; their values are retrieved
- * after execution via the get methods provided here.
- *
- * <p>A Callable statement may return a ResultSet or multiple ResultSets.
- * Multiple ResultSets are handled using operations inherited from
- * Statement.
- *
- * <p>For maximum portability, a call's ResultSets and update counts should
- * be processed prior to getting the values of output parameters.
- *
- * @see Connection#prepareCall
- * @see ResultSet
- */
-
-public class CallableStatement extends Jdbc1PreparedStatement implements java.sql.CallableStatement
-{
- /*
- * @exception SQLException on failure
- */
- CallableStatement(Jdbc1Connection c, String q) throws SQLException
- {
- super(c, q);
- }
-
- /*
- * Before executing a stored procedure call you must explicitly
- * call registerOutParameter to register the java.sql.Type of each
- * out parameter.
- *
- * <p>Note: When reading the value of an out parameter, you must use
- * the getXXX method whose Java type XXX corresponds to the
- * parameter's registered SQL type.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @param sqlType SQL type code defined by java.sql.Types; for
- * parameters of type Numeric or Decimal use the version of
- * registerOutParameter that accepts a scale value
- * @exception SQLException if a database-access error occurs.
- */
- public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException
- {}
-
- /*
- * You must also specify the scale for numeric/decimal types:
- *
- * <p>Note: When reading the value of an out parameter, you must use
- * the getXXX method whose Java type XXX corresponds to the
- * parameter's registered SQL type.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @param sqlType use either java.sql.Type.NUMERIC or java.sql.Type.DECIMAL
- * @param scale a value greater than or equal to zero representing the
- * desired number of digits to the right of the decimal point
- * @exception SQLException if a database-access error occurs.
- */
- public void registerOutParameter(int parameterIndex, int sqlType,
- int scale) throws SQLException
- {}
-
- // Old api?
- //public boolean isNull(int parameterIndex) throws SQLException {
- //return true;
- //}
-
- /*
- * An OUT parameter may have the value of SQL NULL; wasNull
- * reports whether the last value read has this special value.
- *
- * <p>Note: You must first call getXXX on a parameter to read its
- * value and then call wasNull() to see if the value was SQL NULL.
- * @return true if the last parameter read was SQL NULL
- * @exception SQLException if a database-access error occurs.
- */
- public boolean wasNull() throws SQLException
- {
- // check to see if the last access threw an exception
- return false; // fake it for now
- }
-
- // Old api?
- //public String getChar(int parameterIndex) throws SQLException {
- //return null;
- //}
-
- /*
- * Get the value of a CHAR, VARCHAR, or LONGVARCHAR parameter as a
- * Java String.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return the parameter value; if the value is SQL NULL, the result is null
- * @exception SQLException if a database-access error occurs.
- */
- public String getString(int parameterIndex) throws SQLException
- {
- return null;
- }
- //public String getVarChar(int parameterIndex) throws SQLException {
- // return null;
- //}
-
- //public String getLongVarChar(int parameterIndex) throws SQLException {
- //return null;
- //}
-
- /*
- * Get the value of a BIT parameter as a Java boolean.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return the parameter value; if the value is SQL NULL, the result is false
- * @exception SQLException if a database-access error occurs.
- */
- public boolean getBoolean(int parameterIndex) throws SQLException
- {
- return false;
- }
-
- /*
- * Get the value of a TINYINT parameter as a Java byte.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return the parameter value; if the value is SQL NULL, the result is 0
- * @exception SQLException if a database-access error occurs.
- */
- public byte getByte(int parameterIndex) throws SQLException
- {
- return 0;
- }
-
- /*
- * Get the value of a SMALLINT parameter as a Java short.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return the parameter value; if the value is SQL NULL, the result is 0
- * @exception SQLException if a database-access error occurs.
- */
- public short getShort(int parameterIndex) throws SQLException
- {
- return 0;
- }
-
- /*
- * Get the value of an INTEGER parameter as a Java int.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return the parameter value; if the value is SQL NULL, the result is 0
- * @exception SQLException if a database-access error occurs.
- */
- public int getInt(int parameterIndex) throws SQLException
- {
- return 0;
- }
-
- /*
- * Get the value of a BIGINT parameter as a Java long.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return the parameter value; if the value is SQL NULL, the result is 0
- * @exception SQLException if a database-access error occurs.
- */
- public long getLong(int parameterIndex) throws SQLException
- {
- return 0;
- }
-
- /*
- * Get the value of a FLOAT parameter as a Java float.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return the parameter value; if the value is SQL NULL, the result is 0
- * @exception SQLException if a database-access error occurs.
- */
- public float getFloat(int parameterIndex) throws SQLException
- {
- return (float) 0.0;
- }
-
- /*
- * Get the value of a DOUBLE parameter as a Java double.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return the parameter value; if the value is SQL NULL, the result is 0
- * @exception SQLException if a database-access error occurs.
- */
- public double getDouble(int parameterIndex) throws SQLException
- {
- return 0.0;
- }
-
- /*
- * Get the value of a NUMERIC parameter as a java.math.BigDecimal
- * object.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @param scale a value greater than or equal to zero representing the
- * desired number of digits to the right of the decimal point
- * @return the parameter value; if the value is SQL NULL, the result is null
- * @exception SQLException if a database-access error occurs.
- */
- public BigDecimal getBigDecimal(int parameterIndex, int scale)
- throws SQLException
- {
- return null;
- }
-
- /*
- * Get the value of a SQL BINARY or VARBINARY parameter as a Java
- * byte[]
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return the parameter value; if the value is SQL NULL, the result is null
- * @exception SQLException if a database-access error occurs.
- */
- public byte[] getBytes(int parameterIndex) throws SQLException
- {
- return null;
- }
-
- // New API (JPM) (getLongVarBinary)
- //public byte[] getBinaryStream(int parameterIndex) throws SQLException {
- //return null;
- //}
-
- /*
- * Get the value of a SQL DATE parameter as a java.sql.Date object
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return the parameter value; if the value is SQL NULL, the result is null
- * @exception SQLException if a database-access error occurs.
- */
- public java.sql.Date getDate(int parameterIndex) throws SQLException
- {
- return null;
- }
-
- /*
- * Get the value of a SQL TIME parameter as a java.sql.Time object.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return the parameter value; if the value is SQL NULL, the result is null
- * @exception SQLException if a database-access error occurs.
- */
- public java.sql.Time getTime(int parameterIndex) throws SQLException
- {
- return null;
- }
-
- /*
- * Get the value of a SQL TIMESTAMP parameter as a java.sql.Timestamp object.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return the parameter value; if the value is SQL NULL, the result is null
- * @exception SQLException if a database-access error occurs.
- */
- public java.sql.Timestamp getTimestamp(int parameterIndex)
- throws SQLException
- {
- return null;
- }
-
- //----------------------------------------------------------------------
- // Advanced features:
-
- // You can obtain a ParameterMetaData object to get information
- // about the parameters to this CallableStatement.
- //public DatabaseMetaData getMetaData() {
- //return null;
- //}
-
- // getObject returns a Java object for the parameter.
- // See the JDBC spec's "Dynamic Programming" chapter for details.
- /*
- * Get the value of a parameter as a Java object.
- *
- * <p>This method returns a Java object whose type coresponds to the
- * SQL type that was registered for this parameter using
- * registerOutParameter.
- *
- * <P>Note that this method may be used to read datatabase-specific,
- * abstract data types. This is done by specifying a targetSqlType
- * of java.sql.types.OTHER, which allows the driver to return a
- * database-specific Java type.
- *
- * <p>See the JDBC spec's "Dynamic Programming" chapter for details.
- *
- * @param parameterIndex the first parameter is 1, the second is 2,...
- * @return A java.lang.Object holding the OUT parameter value.
- * @exception SQLException if a database-access error occurs.
- */
- public Object getObject(int parameterIndex)
- throws SQLException
- {
- return null;
- }
-}
-
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java
index 747ee1f1ea..bf81f78874 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java
@@ -13,7 +13,7 @@ import org.postgresql.util.PSQLException;
/*
* This class provides information about the database as a whole.
*
- * $Id: DatabaseMetaData.java,v 1.48 2002/07/23 03:59:55 barry Exp $
+ * $Id: DatabaseMetaData.java,v 1.49 2002/07/25 22:45:28 barry Exp $
*
* <p>Many of the methods here return lists of information in ResultSets. You
* can use the normal ResultSet methods such as getString and getInt to
@@ -1549,7 +1549,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
v.addElement(tuple);
}
- return new Jdbc1ResultSet(connection, f, v, "OK", 1);
+ return connection.getResultSet(null, f, v, "OK", 1);
}
/*
@@ -1627,7 +1627,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
// add query loop here
- return new Jdbc1ResultSet(connection, f, v, "OK", 1);
+ return connection.getResultSet(null, f, v, "OK", 1);
}
/*
@@ -1762,7 +1762,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
v.addElement(tuple);
}
r.close();
- return new Jdbc1ResultSet(connection, f, v, "OK", 1);
+ return connection.getResultSet(null, f, v, "OK", 1);
}
// This array contains the valid values for the types argument
@@ -1809,7 +1809,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
f[0] = new Field(connection, "TABLE_SCHEM", iVarcharOid, 32);
tuple[0] = "".getBytes();
v.addElement(tuple);
- return new Jdbc1ResultSet(connection, f, v, "OK", 1);
+ return connection.getResultSet(null, f, v, "OK", 1);
}
/*
@@ -1854,7 +1854,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
tuple[0] = getTableTypes[i][0].getBytes();
v.addElement(tuple);
}
- return new Jdbc1ResultSet(connection, f, v, "OK", 1);
+ return connection.getResultSet(null, f, v, "OK", 1);
}
/*
@@ -2050,7 +2050,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
}
r.close();
- return new Jdbc1ResultSet(connection, f, v, "OK", 1);
+ return connection.getResultSet(null, f, v, "OK", 1);
}
/*
@@ -2113,7 +2113,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
//v.addElement(tuple);
}
- return new Jdbc1ResultSet(connection, f, v, "OK", 1);
+ return connection.getResultSet(null, f, v, "OK", 1);
}
/*
@@ -2203,7 +2203,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
f[6] = new Field(connection, "DECIMAL_DIGITS", iInt2Oid, 2);
f[7] = new Field(connection, "PSEUDO_COLUMN", iInt2Oid, 2);
- return new Jdbc1ResultSet(connection, f, v, "OK", 1);
+ return connection.getResultSet(null, f, v, "OK", 1);
}
/*
@@ -2413,7 +2413,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
while (hasMore);
}
- return new Jdbc1ResultSet(connection, f, tuples, "OK", 1);
+ return connection.getResultSet(null, f, tuples, "OK", 1);
}
/*
@@ -2692,7 +2692,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
v.addElement(tuple);
}
rs.close();
- return new Jdbc1ResultSet(connection, f, v, "OK", 1);
+ return connection.getResultSet(null, f, v, "OK", 1);
}
throw new PSQLException("postgresql.metadata.unavailable");
@@ -2832,7 +2832,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
}
}
- return new Jdbc1ResultSet(connection, f, v, "OK", 1);
+ return connection.getResultSet(null, f, v, "OK", 1);
}
}
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1CallableStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1CallableStatement.java
new file mode 100644
index 0000000000..7cd69103bd
--- /dev/null
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1CallableStatement.java
@@ -0,0 +1,14 @@
+package org.postgresql.jdbc1;
+
+
+import java.sql.*;
+
+public class Jdbc1CallableStatement extends AbstractJdbc1Statement implements java.sql.CallableStatement
+{
+
+ public Jdbc1CallableStatement(Jdbc1Connection connection, String sql) throws SQLException
+ {
+ super(connection, sql);
+ }
+}
+
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1Connection.java b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1Connection.java
index 249a41049b..b67b07fde9 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1Connection.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1Connection.java
@@ -6,7 +6,7 @@ import java.sql.*;
import org.postgresql.Field;
import org.postgresql.util.PSQLException;
-/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Connection.java,v 1.2 2002/07/24 22:08:40 barry Exp $
+/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Connection.java,v 1.3 2002/07/25 22:45:28 barry Exp $
* This class implements the java.sql.Connection interface for JDBC1.
* However most of the implementation is really done in
* org.postgresql.jdbc1.AbstractJdbc1Connection
@@ -24,10 +24,9 @@ public class Jdbc1Connection extends org.postgresql.jdbc1.AbstractJdbc1Connectio
return new org.postgresql.jdbc1.Jdbc1PreparedStatement(this, sql);
}
-//BJL TODO - merge callable statement logic from jdbc2 to jdbc1
public java.sql.CallableStatement prepareCall(String sql) throws SQLException
{
- throw new PSQLException("postgresql.con.call");
+ return new org.postgresql.jdbc1.Jdbc1CallableStatement(this, sql);
}
public java.sql.DatabaseMetaData getMetaData() throws SQLException
@@ -39,7 +38,12 @@ public class Jdbc1Connection extends org.postgresql.jdbc1.AbstractJdbc1Connectio
public java.sql.ResultSet getResultSet(java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException
{
- return new Jdbc1ResultSet(this, fields, tuples, status, updateCount, insertOID, binaryCursor);
+ return new Jdbc1ResultSet(this, stat, fields, tuples, status, updateCount, insertOID, binaryCursor);
+ }
+
+ public java.sql.ResultSet getResultSet(java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount) throws SQLException
+ {
+ return new Jdbc1ResultSet(this, stat, fields, tuples, status, updateCount, 0, false);
}
}
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1ResultSet.java
index a959fef9d3..57850569ec 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/Jdbc1ResultSet.java
@@ -5,7 +5,7 @@ import java.sql.*;
import java.util.Vector;
import org.postgresql.Field;
-/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1ResultSet.java,v 1.1 2002/07/23 03:59:55 barry Exp $
+/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1ResultSet.java,v 1.2 2002/07/25 22:45:28 barry Exp $
* This class implements the java.sql.ResultSet interface for JDBC1.
* However most of the implementation is really done in
* org.postgresql.jdbc1.AbstractJdbc1ResultSet
@@ -13,14 +13,9 @@ import org.postgresql.Field;
public class Jdbc1ResultSet extends org.postgresql.jdbc1.AbstractJdbc1ResultSet implements java.sql.ResultSet
{
- public Jdbc1ResultSet(Jdbc1Connection conn, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
+ public Jdbc1ResultSet(Jdbc1Connection conn, Statement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
{
- super(conn, fields, tuples, status, updateCount, insertOID, binaryCursor);
- }
-
- public Jdbc1ResultSet(Jdbc1Connection conn, Field[] fields, Vector tuples, String status, int updateCount)
- {
- super(conn, fields, tuples, status, updateCount, 0, false);
+ super(conn, statement, fields, tuples, status, updateCount, insertOID, binaryCursor);
}
public java.sql.ResultSetMetaData getMetaData() throws SQLException