mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
pgjindent jdbc files. First time jdbc files were formatted.
This commit is contained in:
@ -19,8 +19,8 @@ import java.math.*;
|
||||
* Parameters are refered to sequentially, by number. The first parameter
|
||||
* is 1.
|
||||
*
|
||||
* {?= call <procedure-name>[<arg1>,<arg2>, ...]}
|
||||
* {call <procedure-name>[<arg1>,<arg2>, ...]}
|
||||
* {?= call <procedure-name>[<arg1>,<arg2>, ...]}
|
||||
* {call <procedure-name>[<arg1>,<arg2>, ...]}
|
||||
*
|
||||
*
|
||||
* <p>IN parameter values are set using the set methods inherited from
|
||||
@ -33,7 +33,7 @@ import java.math.*;
|
||||
* Statement.
|
||||
*
|
||||
* <p>For maximum portability, a call's ResultSets and update counts should
|
||||
* be processed prior to getting the values of output parameters.
|
||||
* be processed prior to getting the values of output parameters.
|
||||
*
|
||||
* @see Connection#prepareCall
|
||||
* @see ResultSet
|
||||
@ -41,268 +41,282 @@ import java.math.*;
|
||||
|
||||
public class CallableStatement extends PreparedStatement implements java.sql.CallableStatement
|
||||
{
|
||||
/**
|
||||
* @exception SQLException on failure
|
||||
*/
|
||||
CallableStatement(Connection 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;
|
||||
}
|
||||
/**
|
||||
* @exception SQLException on failure
|
||||
*/
|
||||
CallableStatement(Connection 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,9 @@ import org.postgresql.largeobject.*;
|
||||
import org.postgresql.util.*;
|
||||
|
||||
/**
|
||||
* $Id: Connection.java,v 1.11 2001/10/09 20:47:35 barry Exp $
|
||||
* $Id: Connection.java,v 1.12 2001/10/25 05:59:59 momjian Exp $
|
||||
*
|
||||
* A Connection represents a session with a specific database. Within the
|
||||
* A Connection represents a session with a specific database. Within the
|
||||
* context of a Connection, SQL statements are executed and results are
|
||||
* returned.
|
||||
*
|
||||
@ -29,181 +29,183 @@ import org.postgresql.util.*;
|
||||
* with the getMetaData method.
|
||||
*
|
||||
* <p><B>Note:</B> By default, the Connection automatically commits changes
|
||||
* after executing each statement. If auto-commit has been disabled, an
|
||||
* after executing each statement. If auto-commit has been disabled, an
|
||||
* explicit commit must be done or database changes will not be saved.
|
||||
*
|
||||
* @see java.sql.Connection
|
||||
*/
|
||||
public class Connection extends org.postgresql.Connection implements java.sql.Connection
|
||||
{
|
||||
// This is a cache of the DatabaseMetaData instance for this connection
|
||||
protected DatabaseMetaData metadata;
|
||||
// This is a cache of the DatabaseMetaData instance for this connection
|
||||
protected DatabaseMetaData metadata;
|
||||
|
||||
/**
|
||||
* SQL statements without parameters are normally executed using
|
||||
* Statement objects. If the same SQL statement is executed many
|
||||
* times, it is more efficient to use a PreparedStatement
|
||||
*
|
||||
* @return a new Statement object
|
||||
* @exception SQLException passed through from the constructor
|
||||
*/
|
||||
public java.sql.Statement createStatement() throws SQLException
|
||||
{
|
||||
return new Statement(this);
|
||||
}
|
||||
/**
|
||||
* SQL statements without parameters are normally executed using
|
||||
* Statement objects. If the same SQL statement is executed many
|
||||
* times, it is more efficient to use a PreparedStatement
|
||||
*
|
||||
* @return a new Statement object
|
||||
* @exception SQLException passed through from the constructor
|
||||
*/
|
||||
public java.sql.Statement createStatement() throws SQLException
|
||||
{
|
||||
return new Statement(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* A SQL statement with or without IN parameters can be pre-compiled
|
||||
* and stored in a PreparedStatement object. This object can then
|
||||
* be used to efficiently execute this statement multiple times.
|
||||
*
|
||||
* <B>Note:</B> This method is optimized for handling parametric
|
||||
* SQL statements that benefit from precompilation if the drivers
|
||||
* supports precompilation. PostgreSQL does not support precompilation.
|
||||
* In this case, the statement is not sent to the database until the
|
||||
* PreparedStatement is executed. This has no direct effect on users;
|
||||
* however it does affect which method throws certain SQLExceptions
|
||||
*
|
||||
* @param sql a SQL statement that may contain one or more '?' IN
|
||||
* parameter placeholders
|
||||
* @return a new PreparedStatement object containing the pre-compiled
|
||||
* statement.
|
||||
* @exception SQLException if a database access error occurs.
|
||||
*/
|
||||
public java.sql.PreparedStatement prepareStatement(String sql) throws SQLException
|
||||
{
|
||||
return new PreparedStatement(this, sql);
|
||||
}
|
||||
/**
|
||||
* A SQL statement with or without IN parameters can be pre-compiled
|
||||
* and stored in a PreparedStatement object. This object can then
|
||||
* be used to efficiently execute this statement multiple times.
|
||||
*
|
||||
* <B>Note:</B> This method is optimized for handling parametric
|
||||
* SQL statements that benefit from precompilation if the drivers
|
||||
* supports precompilation. PostgreSQL does not support precompilation.
|
||||
* In this case, the statement is not sent to the database until the
|
||||
* PreparedStatement is executed. This has no direct effect on users;
|
||||
* however it does affect which method throws certain SQLExceptions
|
||||
*
|
||||
* @param sql a SQL statement that may contain one or more '?' IN
|
||||
* parameter placeholders
|
||||
* @return a new PreparedStatement object containing the pre-compiled
|
||||
* statement.
|
||||
* @exception SQLException if a database access error occurs.
|
||||
*/
|
||||
public java.sql.PreparedStatement prepareStatement(String sql) throws SQLException
|
||||
{
|
||||
return new PreparedStatement(this, sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* A SQL stored procedure call statement is handled by creating a
|
||||
* CallableStatement for it. The CallableStatement provides methods
|
||||
* for setting up its IN and OUT parameters and methods for executing
|
||||
* it.
|
||||
*
|
||||
* <B>Note:</B> This method is optimised for handling stored procedure
|
||||
* call statements. Some drivers may send the call statement to the
|
||||
* database when the prepareCall is done; others may wait until the
|
||||
* CallableStatement is executed. This has no direct effect on users;
|
||||
* however, it does affect which method throws certain SQLExceptions
|
||||
*
|
||||
* @param sql a SQL statement that may contain one or more '?' parameter
|
||||
* placeholders. Typically this statement is a JDBC function call
|
||||
* escape string.
|
||||
* @return a new CallableStatement object containing the pre-compiled
|
||||
* SQL statement
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public java.sql.CallableStatement prepareCall(String sql) throws SQLException
|
||||
{
|
||||
throw new PSQLException("postgresql.con.call");
|
||||
// return new CallableStatement(this, sql);
|
||||
}
|
||||
/**
|
||||
* A SQL stored procedure call statement is handled by creating a
|
||||
* CallableStatement for it. The CallableStatement provides methods
|
||||
* for setting up its IN and OUT parameters and methods for executing
|
||||
* it.
|
||||
*
|
||||
* <B>Note:</B> This method is optimised for handling stored procedure
|
||||
* call statements. Some drivers may send the call statement to the
|
||||
* database when the prepareCall is done; others may wait until the
|
||||
* CallableStatement is executed. This has no direct effect on users;
|
||||
* however, it does affect which method throws certain SQLExceptions
|
||||
*
|
||||
* @param sql a SQL statement that may contain one or more '?' parameter
|
||||
* placeholders. Typically this statement is a JDBC function call
|
||||
* escape string.
|
||||
* @return a new CallableStatement object containing the pre-compiled
|
||||
* SQL statement
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public java.sql.CallableStatement prepareCall(String sql) throws SQLException
|
||||
{
|
||||
throw new PSQLException("postgresql.con.call");
|
||||
// return new CallableStatement(this, sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests to see if a Connection is closed
|
||||
*
|
||||
* @return the status of the connection
|
||||
* @exception SQLException (why?)
|
||||
*/
|
||||
public boolean isClosed() throws SQLException
|
||||
{
|
||||
return (pg_stream == null);
|
||||
}
|
||||
/**
|
||||
* Tests to see if a Connection is closed
|
||||
*
|
||||
* @return the status of the connection
|
||||
* @exception SQLException (why?)
|
||||
*/
|
||||
public boolean isClosed() throws SQLException
|
||||
{
|
||||
return (pg_stream == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A connection's database is able to provide information describing
|
||||
* its tables, its supported SQL grammar, its stored procedures, the
|
||||
* capabilities of this connection, etc. This information is made
|
||||
* available through a DatabaseMetaData object.
|
||||
*
|
||||
* @return a DatabaseMetaData object for this connection
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public java.sql.DatabaseMetaData getMetaData() throws SQLException
|
||||
{
|
||||
if(metadata==null)
|
||||
metadata = new DatabaseMetaData(this);
|
||||
return metadata;
|
||||
}
|
||||
/**
|
||||
* A connection's database is able to provide information describing
|
||||
* its tables, its supported SQL grammar, its stored procedures, the
|
||||
* capabilities of this connection, etc. This information is made
|
||||
* available through a DatabaseMetaData object.
|
||||
*
|
||||
* @return a DatabaseMetaData object for this connection
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public java.sql.DatabaseMetaData getMetaData() throws SQLException
|
||||
{
|
||||
if (metadata == null)
|
||||
metadata = new DatabaseMetaData(this);
|
||||
return metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* This overides the method in org.postgresql.Connection and returns a
|
||||
* ResultSet.
|
||||
*/
|
||||
public java.sql.ResultSet getResultSet(org.postgresql.Connection conn,java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount,int insertOID, boolean binaryCursor) throws SQLException
|
||||
{
|
||||
// in jdbc1 stat is ignored.
|
||||
return new org.postgresql.jdbc1.ResultSet((org.postgresql.jdbc1.Connection)conn,fields,tuples,status,updateCount,insertOID,binaryCursor);
|
||||
}
|
||||
/**
|
||||
* This overides the method in org.postgresql.Connection and returns a
|
||||
* ResultSet.
|
||||
*/
|
||||
public java.sql.ResultSet getResultSet(org.postgresql.Connection conn, java.sql.Statement stat, Field[] fields, Vector tuples, String status, int updateCount, int insertOID, boolean binaryCursor) throws SQLException
|
||||
{
|
||||
// in jdbc1 stat is ignored.
|
||||
return new org.postgresql.jdbc1.ResultSet((org.postgresql.jdbc1.Connection)conn, fields, tuples, status, updateCount, insertOID, binaryCursor);
|
||||
}
|
||||
|
||||
|
||||
/* An implementation of the abstract method in the parent class.
|
||||
* This implemetation uses the jdbc1Types array to support the jdbc1
|
||||
* datatypes. Basically jdbc1 and jdbc2 are the same, except that
|
||||
* jdbc2 adds the Array types.
|
||||
*/
|
||||
public int getSQLType(String pgTypeName)
|
||||
{
|
||||
int sqlType = Types.OTHER; // default value
|
||||
for(int i=0;i<jdbc1Types.length;i++) {
|
||||
if(pgTypeName.equals(jdbc1Types[i])) {
|
||||
sqlType=jdbc1Typei[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sqlType;
|
||||
}
|
||||
/* An implementation of the abstract method in the parent class.
|
||||
* This implemetation uses the jdbc1Types array to support the jdbc1
|
||||
* datatypes. Basically jdbc1 and jdbc2 are the same, except that
|
||||
* jdbc2 adds the Array types.
|
||||
*/
|
||||
public int getSQLType(String pgTypeName)
|
||||
{
|
||||
int sqlType = Types.OTHER; // default value
|
||||
for (int i = 0;i < jdbc1Types.length;i++)
|
||||
{
|
||||
if (pgTypeName.equals(jdbc1Types[i]))
|
||||
{
|
||||
sqlType = jdbc1Typei[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sqlType;
|
||||
}
|
||||
|
||||
/**
|
||||
* This table holds the org.postgresql names for the types supported.
|
||||
* Any types that map to Types.OTHER (eg POINT) don't go into this table.
|
||||
* They default automatically to Types.OTHER
|
||||
*
|
||||
* Note: This must be in the same order as below.
|
||||
*
|
||||
* Tip: keep these grouped together by the Types. value
|
||||
*/
|
||||
private static final String jdbc1Types[] = {
|
||||
"int2",
|
||||
"int4","oid",
|
||||
"int8",
|
||||
"cash","money",
|
||||
"numeric",
|
||||
"float4",
|
||||
"float8",
|
||||
"bpchar","char","char2","char4","char8","char16",
|
||||
"varchar","text","name","filename",
|
||||
"bytea",
|
||||
"bool",
|
||||
"date",
|
||||
"time",
|
||||
"abstime","timestamp"
|
||||
};
|
||||
/**
|
||||
* This table holds the org.postgresql names for the types supported.
|
||||
* Any types that map to Types.OTHER (eg POINT) don't go into this table.
|
||||
* They default automatically to Types.OTHER
|
||||
*
|
||||
* Note: This must be in the same order as below.
|
||||
*
|
||||
* Tip: keep these grouped together by the Types. value
|
||||
*/
|
||||
private static final String jdbc1Types[] = {
|
||||
"int2",
|
||||
"int4", "oid",
|
||||
"int8",
|
||||
"cash", "money",
|
||||
"numeric",
|
||||
"float4",
|
||||
"float8",
|
||||
"bpchar", "char", "char2", "char4", "char8", "char16",
|
||||
"varchar", "text", "name", "filename",
|
||||
"bytea",
|
||||
"bool",
|
||||
"date",
|
||||
"time",
|
||||
"abstime", "timestamp"
|
||||
};
|
||||
|
||||
/**
|
||||
* This table holds the JDBC type for each entry above.
|
||||
*
|
||||
* Note: This must be in the same order as above
|
||||
*
|
||||
* Tip: keep these grouped together by the Types. value
|
||||
*/
|
||||
private static final int jdbc1Typei[] = {
|
||||
Types.SMALLINT,
|
||||
Types.INTEGER,Types.INTEGER,
|
||||
Types.BIGINT,
|
||||
Types.DOUBLE,Types.DOUBLE,
|
||||
Types.NUMERIC,
|
||||
Types.REAL,
|
||||
Types.DOUBLE,
|
||||
Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,
|
||||
Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,
|
||||
Types.BINARY,
|
||||
Types.BIT,
|
||||
Types.DATE,
|
||||
Types.TIME,
|
||||
Types.TIMESTAMP,Types.TIMESTAMP
|
||||
};
|
||||
/**
|
||||
* This table holds the JDBC type for each entry above.
|
||||
*
|
||||
* Note: This must be in the same order as above
|
||||
*
|
||||
* Tip: keep these grouped together by the Types. value
|
||||
*/
|
||||
private static final int jdbc1Typei[] = {
|
||||
Types.SMALLINT,
|
||||
Types.INTEGER, Types.INTEGER,
|
||||
Types.BIGINT,
|
||||
Types.DOUBLE, Types.DOUBLE,
|
||||
Types.NUMERIC,
|
||||
Types.REAL,
|
||||
Types.DOUBLE,
|
||||
Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR,
|
||||
Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
|
||||
Types.BINARY,
|
||||
Types.BIT,
|
||||
Types.DATE,
|
||||
Types.TIME,
|
||||
Types.TIMESTAMP, Types.TIMESTAMP
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -23,13 +23,13 @@ import org.postgresql.util.*;
|
||||
* parameter. For instance, if the IN parameter has SQL type Integer, then
|
||||
* setInt should be used.
|
||||
*
|
||||
* <p>If arbitrary parameter type conversions are required, then the setObject
|
||||
* <p>If arbitrary parameter type conversions are required, then the setObject
|
||||
* method should be used with a target SQL type.
|
||||
*
|
||||
* @see ResultSet
|
||||
* @see java.sql.PreparedStatement
|
||||
*/
|
||||
public class PreparedStatement extends Statement implements java.sql.PreparedStatement
|
||||
public class PreparedStatement extends Statement implements java.sql.PreparedStatement
|
||||
{
|
||||
String sql;
|
||||
String[] templateStrings;
|
||||
@ -82,7 +82,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
* A Prepared SQL query is executed and its ResultSet is returned
|
||||
*
|
||||
* @return a ResultSet that contains the data produced by the
|
||||
* * query - never null
|
||||
* * query - never null
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public java.sql.ResultSet executeQuery() throws SQLException
|
||||
@ -93,12 +93,12 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
for (i = 0 ; i < inStrings.length ; ++i)
|
||||
{
|
||||
if (inStrings[i] == null)
|
||||
throw new PSQLException("postgresql.prep.param",new Integer(i + 1));
|
||||
throw new PSQLException("postgresql.prep.param", new Integer(i + 1));
|
||||
s.append (templateStrings[i]);
|
||||
s.append (inStrings[i]);
|
||||
}
|
||||
s.append(templateStrings[inStrings.length]);
|
||||
return super.executeQuery(s.toString()); // in Statement class
|
||||
return super.executeQuery(s.toString()); // in Statement class
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,7 +107,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
* be executed.
|
||||
*
|
||||
* @return either the row count for INSERT, UPDATE or DELETE; or
|
||||
* * 0 for SQL statements that return nothing.
|
||||
* * 0 for SQL statements that return nothing.
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public int executeUpdate() throws SQLException
|
||||
@ -118,13 +118,13 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
for (i = 0 ; i < inStrings.length ; ++i)
|
||||
{
|
||||
if (inStrings[i] == null)
|
||||
throw new PSQLException("postgresql.prep.param",new Integer(i + 1));
|
||||
throw new PSQLException("postgresql.prep.param", new Integer(i + 1));
|
||||
s.append (templateStrings[i]);
|
||||
s.append (inStrings[i]);
|
||||
}
|
||||
s.append(templateStrings[inStrings.length]);
|
||||
return super.executeUpdate(s.toString()); // in Statement class
|
||||
}
|
||||
return super.executeUpdate(s.toString()); // in Statement class
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a parameter to SQL NULL
|
||||
@ -220,7 +220,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a parameter to a Java double value. The driver converts this
|
||||
* Set a parameter to a Java double value. The driver converts this
|
||||
* to a SQL DOUBLE value when it sends it to the database
|
||||
*
|
||||
* @param parameterIndex the first parameter is 1...
|
||||
@ -247,7 +247,7 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a parameter to a Java String value. The driver converts this
|
||||
* Set a parameter to a Java String value. The driver converts this
|
||||
* to a SQL VARCHAR or LONGVARCHAR value (depending on the arguments
|
||||
* size relative to the driver's limits on VARCHARs) when it sends it
|
||||
* to the database.
|
||||
@ -258,59 +258,66 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
*/
|
||||
public void setString(int parameterIndex, String x) throws SQLException
|
||||
{
|
||||
// if the passed string is null, then set this column to null
|
||||
if(x==null)
|
||||
setNull(parameterIndex,Types.OTHER);
|
||||
else {
|
||||
StringBuffer b = new StringBuffer();
|
||||
int i;
|
||||
|
||||
b.append('\'');
|
||||
for (i = 0 ; i < x.length() ; ++i)
|
||||
{
|
||||
char c = x.charAt(i);
|
||||
if (c == '\\' || c == '\'')
|
||||
b.append((char)'\\');
|
||||
b.append(c);
|
||||
}
|
||||
b.append('\'');
|
||||
set(parameterIndex, b.toString());
|
||||
}
|
||||
// if the passed string is null, then set this column to null
|
||||
if (x == null)
|
||||
setNull(parameterIndex, Types.OTHER);
|
||||
else
|
||||
{
|
||||
StringBuffer b = new StringBuffer();
|
||||
int i;
|
||||
|
||||
b.append('\'');
|
||||
for (i = 0 ; i < x.length() ; ++i)
|
||||
{
|
||||
char c = x.charAt(i);
|
||||
if (c == '\\' || c == '\'')
|
||||
b.append((char)'\\');
|
||||
b.append(c);
|
||||
}
|
||||
b.append('\'');
|
||||
set(parameterIndex, b.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a parameter to a Java array of bytes. The driver converts this
|
||||
* to a SQL VARBINARY or LONGVARBINARY (depending on the argument's
|
||||
* size relative to the driver's limits on VARBINARYs) when it sends
|
||||
* it to the database.
|
||||
*
|
||||
* <p>Implementation note:
|
||||
* <br>With org.postgresql, this creates a large object, and stores the
|
||||
* objects oid in this column.
|
||||
*
|
||||
* @param parameterIndex the first parameter is 1...
|
||||
* @param x the parameter value
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public void setBytes(int parameterIndex, byte x[]) throws SQLException
|
||||
{
|
||||
if (connection.haveMinimumCompatibleVersion("7.2")) {
|
||||
//Version 7.2 supports the bytea datatype for byte arrays
|
||||
if(null == x){
|
||||
setNull(parameterIndex,Types.OTHER);
|
||||
} else {
|
||||
setString(parameterIndex, PGbytea.toPGString(x));
|
||||
}
|
||||
} else {
|
||||
//Version 7.1 and earlier support done as LargeObjects
|
||||
LargeObjectManager lom = connection.getLargeObjectAPI();
|
||||
int oid = lom.create();
|
||||
LargeObject lob = lom.open(oid);
|
||||
lob.write(x);
|
||||
lob.close();
|
||||
setInt(parameterIndex,oid);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set a parameter to a Java array of bytes. The driver converts this
|
||||
* to a SQL VARBINARY or LONGVARBINARY (depending on the argument's
|
||||
* size relative to the driver's limits on VARBINARYs) when it sends
|
||||
* it to the database.
|
||||
*
|
||||
* <p>Implementation note:
|
||||
* <br>With org.postgresql, this creates a large object, and stores the
|
||||
* objects oid in this column.
|
||||
*
|
||||
* @param parameterIndex the first parameter is 1...
|
||||
* @param x the parameter value
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public void setBytes(int parameterIndex, byte x[]) throws SQLException
|
||||
{
|
||||
if (connection.haveMinimumCompatibleVersion("7.2"))
|
||||
{
|
||||
//Version 7.2 supports the bytea datatype for byte arrays
|
||||
if (null == x)
|
||||
{
|
||||
setNull(parameterIndex, Types.OTHER);
|
||||
}
|
||||
else
|
||||
{
|
||||
setString(parameterIndex, PGbytea.toPGString(x));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Version 7.1 and earlier support done as LargeObjects
|
||||
LargeObjectManager lom = connection.getLargeObjectAPI();
|
||||
int oid = lom.create();
|
||||
LargeObject lob = lom.open(oid);
|
||||
lob.write(x);
|
||||
lob.close();
|
||||
setInt(parameterIndex, oid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a parameter to a java.sql.Date value. The driver converts this
|
||||
@ -322,24 +329,27 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
*/
|
||||
public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
|
||||
{
|
||||
if (null == x){
|
||||
setNull(parameterIndex,Types.OTHER);
|
||||
}else{
|
||||
SimpleDateFormat df = new SimpleDateFormat("''yyyy-MM-dd''");
|
||||
set(parameterIndex, df.format(x));
|
||||
}
|
||||
// The above is how the date should be handled.
|
||||
//
|
||||
// However, in JDK's prior to 1.1.6 (confirmed with the
|
||||
// Linux jdk1.1.3 and the Win95 JRE1.1.5), SimpleDateFormat seems
|
||||
// to format a date to the previous day. So the fix is to add a day
|
||||
// before formatting.
|
||||
//
|
||||
// PS: 86400000 is one day
|
||||
//
|
||||
//set(parameterIndex, df.format(new java.util.Date(x.getTime()+86400000)));
|
||||
if (null == x)
|
||||
{
|
||||
setNull(parameterIndex, Types.OTHER);
|
||||
}
|
||||
else
|
||||
{
|
||||
SimpleDateFormat df = new SimpleDateFormat("''yyyy-MM-dd''");
|
||||
set(parameterIndex, df.format(x));
|
||||
}
|
||||
// The above is how the date should be handled.
|
||||
//
|
||||
// However, in JDK's prior to 1.1.6 (confirmed with the
|
||||
// Linux jdk1.1.3 and the Win95 JRE1.1.5), SimpleDateFormat seems
|
||||
// to format a date to the previous day. So the fix is to add a day
|
||||
// before formatting.
|
||||
//
|
||||
// PS: 86400000 is one day
|
||||
//
|
||||
//set(parameterIndex, df.format(new java.util.Date(x.getTime()+86400000)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a parameter to a java.sql.Time value. The driver converts
|
||||
* this to a SQL TIME value when it sends it to the database.
|
||||
@ -350,11 +360,14 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
*/
|
||||
public void setTime(int parameterIndex, Time x) throws SQLException
|
||||
{
|
||||
if (null == x){
|
||||
setNull(parameterIndex,Types.OTHER);
|
||||
}else{
|
||||
set(parameterIndex, "'" + x.toString() + "'");
|
||||
}
|
||||
if (null == x)
|
||||
{
|
||||
setNull(parameterIndex, Types.OTHER);
|
||||
}
|
||||
else
|
||||
{
|
||||
set(parameterIndex, "'" + x.toString() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -366,16 +379,19 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
|
||||
{
|
||||
if (null == x){
|
||||
setNull(parameterIndex,Types.OTHER);
|
||||
}else{
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
StringBuffer strBuf = new StringBuffer("'");
|
||||
strBuf.append(df.format(x)).append('.').append(x.getNanos()/10000000).append("+00'");
|
||||
set(parameterIndex, strBuf.toString());
|
||||
}
|
||||
{
|
||||
if (null == x)
|
||||
{
|
||||
setNull(parameterIndex, Types.OTHER);
|
||||
}
|
||||
else
|
||||
{
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
StringBuffer strBuf = new StringBuffer("'");
|
||||
strBuf.append(df.format(x)).append('.').append(x.getNanos() / 10000000).append("+00'");
|
||||
set(parameterIndex, strBuf.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -396,29 +412,37 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
*/
|
||||
public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException
|
||||
{
|
||||
if (connection.haveMinimumCompatibleVersion("7.2")) {
|
||||
//Version 7.2 supports AsciiStream for all PG text types (char, varchar, text)
|
||||
//As the spec/javadoc for this method indicate this is to be used for
|
||||
//large String values (i.e. LONGVARCHAR) PG doesn't have a separate
|
||||
//long varchar datatype, but with toast all text datatypes are capable of
|
||||
//handling very large values. Thus the implementation ends up calling
|
||||
//setString() since there is no current way to stream the value to the server
|
||||
try {
|
||||
InputStreamReader l_inStream = new InputStreamReader(x, "ASCII");
|
||||
char[] l_chars = new char[length];
|
||||
int l_charsRead = l_inStream.read(l_chars,0,length);
|
||||
setString(parameterIndex, new String(l_chars,0,l_charsRead));
|
||||
} catch (UnsupportedEncodingException l_uee) {
|
||||
throw new PSQLException("postgresql.unusual",l_uee);
|
||||
} catch (IOException l_ioe) {
|
||||
throw new PSQLException("postgresql.unusual",l_ioe);
|
||||
}
|
||||
} else {
|
||||
//Version 7.1 supported only LargeObjects by treating everything
|
||||
//as binary data
|
||||
setBinaryStream(parameterIndex, x, length);
|
||||
if (connection.haveMinimumCompatibleVersion("7.2"))
|
||||
{
|
||||
//Version 7.2 supports AsciiStream for all PG text types (char, varchar, text)
|
||||
//As the spec/javadoc for this method indicate this is to be used for
|
||||
//large String values (i.e. LONGVARCHAR) PG doesn't have a separate
|
||||
//long varchar datatype, but with toast all text datatypes are capable of
|
||||
//handling very large values. Thus the implementation ends up calling
|
||||
//setString() since there is no current way to stream the value to the server
|
||||
try
|
||||
{
|
||||
InputStreamReader l_inStream = new InputStreamReader(x, "ASCII");
|
||||
char[] l_chars = new char[length];
|
||||
int l_charsRead = l_inStream.read(l_chars, 0, length);
|
||||
setString(parameterIndex, new String(l_chars, 0, l_charsRead));
|
||||
}
|
||||
catch (UnsupportedEncodingException l_uee)
|
||||
{
|
||||
throw new PSQLException("postgresql.unusual", l_uee);
|
||||
}
|
||||
catch (IOException l_ioe)
|
||||
{
|
||||
throw new PSQLException("postgresql.unusual", l_ioe);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Version 7.1 supported only LargeObjects by treating everything
|
||||
//as binary data
|
||||
setBinaryStream(parameterIndex, x, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When a very large Unicode value is input to a LONGVARCHAR parameter,
|
||||
@ -437,35 +461,43 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
*/
|
||||
public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException
|
||||
{
|
||||
if (connection.haveMinimumCompatibleVersion("7.2")) {
|
||||
//Version 7.2 supports AsciiStream for all PG text types (char, varchar, text)
|
||||
//As the spec/javadoc for this method indicate this is to be used for
|
||||
//large String values (i.e. LONGVARCHAR) PG doesn't have a separate
|
||||
//long varchar datatype, but with toast all text datatypes are capable of
|
||||
//handling very large values. Thus the implementation ends up calling
|
||||
//setString() since there is no current way to stream the value to the server
|
||||
try {
|
||||
InputStreamReader l_inStream = new InputStreamReader(x, "UTF-8");
|
||||
char[] l_chars = new char[length];
|
||||
int l_charsRead = l_inStream.read(l_chars,0,length);
|
||||
setString(parameterIndex, new String(l_chars,0,l_charsRead));
|
||||
} catch (UnsupportedEncodingException l_uee) {
|
||||
throw new PSQLException("postgresql.unusual",l_uee);
|
||||
} catch (IOException l_ioe) {
|
||||
throw new PSQLException("postgresql.unusual",l_ioe);
|
||||
}
|
||||
} else {
|
||||
//Version 7.1 supported only LargeObjects by treating everything
|
||||
//as binary data
|
||||
setBinaryStream(parameterIndex, x, length);
|
||||
if (connection.haveMinimumCompatibleVersion("7.2"))
|
||||
{
|
||||
//Version 7.2 supports AsciiStream for all PG text types (char, varchar, text)
|
||||
//As the spec/javadoc for this method indicate this is to be used for
|
||||
//large String values (i.e. LONGVARCHAR) PG doesn't have a separate
|
||||
//long varchar datatype, but with toast all text datatypes are capable of
|
||||
//handling very large values. Thus the implementation ends up calling
|
||||
//setString() since there is no current way to stream the value to the server
|
||||
try
|
||||
{
|
||||
InputStreamReader l_inStream = new InputStreamReader(x, "UTF-8");
|
||||
char[] l_chars = new char[length];
|
||||
int l_charsRead = l_inStream.read(l_chars, 0, length);
|
||||
setString(parameterIndex, new String(l_chars, 0, l_charsRead));
|
||||
}
|
||||
catch (UnsupportedEncodingException l_uee)
|
||||
{
|
||||
throw new PSQLException("postgresql.unusual", l_uee);
|
||||
}
|
||||
catch (IOException l_ioe)
|
||||
{
|
||||
throw new PSQLException("postgresql.unusual", l_ioe);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Version 7.1 supported only LargeObjects by treating everything
|
||||
//as binary data
|
||||
setBinaryStream(parameterIndex, x, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When a very large binary value is input to a LONGVARBINARY parameter,
|
||||
* it may be more practical to send it via a java.io.InputStream.
|
||||
* JDBC will read the data from the stream as needed, until it reaches
|
||||
* end-of-file.
|
||||
* end-of-file.
|
||||
*
|
||||
* <P><B>Note:</B> This stream object can either be a standard Java
|
||||
* stream object or your own subclass that implements the standard
|
||||
@ -477,60 +509,73 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
*/
|
||||
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException
|
||||
{
|
||||
if (connection.haveMinimumCompatibleVersion("7.2")) {
|
||||
//Version 7.2 supports BinaryStream for for the PG bytea type
|
||||
//As the spec/javadoc for this method indicate this is to be used for
|
||||
//large binary values (i.e. LONGVARBINARY) PG doesn't have a separate
|
||||
//long binary datatype, but with toast the bytea datatype is capable of
|
||||
//handling very large values. Thus the implementation ends up calling
|
||||
//setBytes() since there is no current way to stream the value to the server
|
||||
byte[] l_bytes = new byte[length];
|
||||
int l_bytesRead;
|
||||
try {
|
||||
l_bytesRead = x.read(l_bytes,0,length);
|
||||
} catch (IOException l_ioe) {
|
||||
throw new PSQLException("postgresql.unusual",l_ioe);
|
||||
}
|
||||
if (l_bytesRead == length) {
|
||||
setBytes(parameterIndex, l_bytes);
|
||||
} else {
|
||||
//the stream contained less data than they said
|
||||
byte[] l_bytes2 = new byte[l_bytesRead];
|
||||
System.arraycopy(l_bytes,0,l_bytes2,0,l_bytesRead);
|
||||
setBytes(parameterIndex, l_bytes2);
|
||||
}
|
||||
} else {
|
||||
//Version 7.1 only supported streams for LargeObjects
|
||||
//but the jdbc spec indicates that streams should be
|
||||
//available for LONGVARBINARY instead
|
||||
LargeObjectManager lom = connection.getLargeObjectAPI();
|
||||
int oid = lom.create();
|
||||
LargeObject lob = lom.open(oid);
|
||||
OutputStream los = lob.getOutputStream();
|
||||
try {
|
||||
// could be buffered, but then the OutputStream returned by LargeObject
|
||||
// is buffered internally anyhow, so there would be no performance
|
||||
// boost gained, if anything it would be worse!
|
||||
int c=x.read();
|
||||
int p=0;
|
||||
while(c>-1 && p<length) {
|
||||
los.write(c);
|
||||
c=x.read();
|
||||
p++;
|
||||
}
|
||||
los.close();
|
||||
} catch(IOException se) {
|
||||
throw new PSQLException("postgresql.unusual",se);
|
||||
}
|
||||
// lob is closed by the stream so don't call lob.close()
|
||||
setInt(parameterIndex,oid);
|
||||
}
|
||||
if (connection.haveMinimumCompatibleVersion("7.2"))
|
||||
{
|
||||
//Version 7.2 supports BinaryStream for for the PG bytea type
|
||||
//As the spec/javadoc for this method indicate this is to be used for
|
||||
//large binary values (i.e. LONGVARBINARY) PG doesn't have a separate
|
||||
//long binary datatype, but with toast the bytea datatype is capable of
|
||||
//handling very large values. Thus the implementation ends up calling
|
||||
//setBytes() since there is no current way to stream the value to the server
|
||||
byte[] l_bytes = new byte[length];
|
||||
int l_bytesRead;
|
||||
try
|
||||
{
|
||||
l_bytesRead = x.read(l_bytes, 0, length);
|
||||
}
|
||||
catch (IOException l_ioe)
|
||||
{
|
||||
throw new PSQLException("postgresql.unusual", l_ioe);
|
||||
}
|
||||
if (l_bytesRead == length)
|
||||
{
|
||||
setBytes(parameterIndex, l_bytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
//the stream contained less data than they said
|
||||
byte[] l_bytes2 = new byte[l_bytesRead];
|
||||
System.arraycopy(l_bytes, 0, l_bytes2, 0, l_bytesRead);
|
||||
setBytes(parameterIndex, l_bytes2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Version 7.1 only supported streams for LargeObjects
|
||||
//but the jdbc spec indicates that streams should be
|
||||
//available for LONGVARBINARY instead
|
||||
LargeObjectManager lom = connection.getLargeObjectAPI();
|
||||
int oid = lom.create();
|
||||
LargeObject lob = lom.open(oid);
|
||||
OutputStream los = lob.getOutputStream();
|
||||
try
|
||||
{
|
||||
// could be buffered, but then the OutputStream returned by LargeObject
|
||||
// is buffered internally anyhow, so there would be no performance
|
||||
// boost gained, if anything it would be worse!
|
||||
int c = x.read();
|
||||
int p = 0;
|
||||
while (c > -1 && p < length)
|
||||
{
|
||||
los.write(c);
|
||||
c = x.read();
|
||||
p++;
|
||||
}
|
||||
los.close();
|
||||
}
|
||||
catch (IOException se)
|
||||
{
|
||||
throw new PSQLException("postgresql.unusual", se);
|
||||
}
|
||||
// lob is closed by the stream so don't call lob.close()
|
||||
setInt(parameterIndex, oid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In general, parameter values remain in force for repeated used of a
|
||||
* Statement. Setting a parameter value automatically clears its
|
||||
* previous value. However, in coms cases, it is useful to immediately
|
||||
* previous value. However, in coms cases, it is useful to immediately
|
||||
* release the resources used by the current parameter values; this
|
||||
* can be done by calling clearParameters
|
||||
*
|
||||
@ -559,62 +604,66 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
* @param x the object containing the input parameter value
|
||||
* @param targetSqlType The SQL type to be send to the database
|
||||
* @param scale For java.sql.Types.DECIMAL or java.sql.Types.NUMERIC
|
||||
* * types this is the number of digits after the decimal. For
|
||||
* * all other types this value will be ignored.
|
||||
* * types this is the number of digits after the decimal. For
|
||||
* * all other types this value will be ignored.
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException
|
||||
{
|
||||
if (x == null){
|
||||
setNull(parameterIndex,Types.OTHER);
|
||||
return;
|
||||
if (x == null)
|
||||
{
|
||||
setNull(parameterIndex, Types.OTHER);
|
||||
return ;
|
||||
}
|
||||
switch (targetSqlType)
|
||||
{
|
||||
case Types.TINYINT:
|
||||
case Types.SMALLINT:
|
||||
case Types.INTEGER:
|
||||
case Types.BIGINT:
|
||||
case Types.REAL:
|
||||
case Types.FLOAT:
|
||||
case Types.DOUBLE:
|
||||
case Types.DECIMAL:
|
||||
case Types.NUMERIC:
|
||||
if (x instanceof Boolean)
|
||||
set(parameterIndex, ((Boolean)x).booleanValue() ? "1" : "0");
|
||||
else
|
||||
set(parameterIndex, x.toString());
|
||||
break;
|
||||
case Types.CHAR:
|
||||
case Types.VARCHAR:
|
||||
case Types.LONGVARCHAR:
|
||||
setString(parameterIndex, x.toString());
|
||||
break;
|
||||
case Types.DATE:
|
||||
setDate(parameterIndex, (java.sql.Date)x);
|
||||
break;
|
||||
case Types.TIME:
|
||||
setTime(parameterIndex, (Time)x);
|
||||
break;
|
||||
case Types.TIMESTAMP:
|
||||
setTimestamp(parameterIndex, (Timestamp)x);
|
||||
break;
|
||||
case Types.BIT:
|
||||
if (x instanceof Boolean) {
|
||||
set(parameterIndex, ((Boolean)x).booleanValue() ? "TRUE" : "FALSE");
|
||||
} else {
|
||||
throw new PSQLException("postgresql.prep.type");
|
||||
}
|
||||
break;
|
||||
case Types.BINARY:
|
||||
case Types.VARBINARY:
|
||||
setObject(parameterIndex,x);
|
||||
break;
|
||||
case Types.OTHER:
|
||||
setString(parameterIndex, ((PGobject)x).getValue());
|
||||
break;
|
||||
default:
|
||||
case Types.TINYINT:
|
||||
case Types.SMALLINT:
|
||||
case Types.INTEGER:
|
||||
case Types.BIGINT:
|
||||
case Types.REAL:
|
||||
case Types.FLOAT:
|
||||
case Types.DOUBLE:
|
||||
case Types.DECIMAL:
|
||||
case Types.NUMERIC:
|
||||
if (x instanceof Boolean)
|
||||
set(parameterIndex, ((Boolean)x).booleanValue() ? "1" : "0");
|
||||
else
|
||||
set(parameterIndex, x.toString());
|
||||
break;
|
||||
case Types.CHAR:
|
||||
case Types.VARCHAR:
|
||||
case Types.LONGVARCHAR:
|
||||
setString(parameterIndex, x.toString());
|
||||
break;
|
||||
case Types.DATE:
|
||||
setDate(parameterIndex, (java.sql.Date)x);
|
||||
break;
|
||||
case Types.TIME:
|
||||
setTime(parameterIndex, (Time)x);
|
||||
break;
|
||||
case Types.TIMESTAMP:
|
||||
setTimestamp(parameterIndex, (Timestamp)x);
|
||||
break;
|
||||
case Types.BIT:
|
||||
if (x instanceof Boolean)
|
||||
{
|
||||
set(parameterIndex, ((Boolean)x).booleanValue() ? "TRUE" : "FALSE");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PSQLException("postgresql.prep.type");
|
||||
}
|
||||
break;
|
||||
case Types.BINARY:
|
||||
case Types.VARBINARY:
|
||||
setObject(parameterIndex, x);
|
||||
break;
|
||||
case Types.OTHER:
|
||||
setString(parameterIndex, ((PGobject)x).getValue());
|
||||
break;
|
||||
default:
|
||||
throw new PSQLException("postgresql.prep.type");
|
||||
}
|
||||
}
|
||||
|
||||
@ -622,18 +671,19 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
{
|
||||
setObject(parameterIndex, x, targetSqlType, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This stores an Object into a parameter.
|
||||
* <p>New for 6.4, if the object is not recognised, but it is
|
||||
* Serializable, then the object is serialised using the
|
||||
* org.postgresql.util.Serialize class.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This stores an Object into a parameter.
|
||||
* <p>New for 6.4, if the object is not recognised, but it is
|
||||
* Serializable, then the object is serialised using the
|
||||
* org.postgresql.util.Serialize class.
|
||||
*/
|
||||
public void setObject(int parameterIndex, Object x) throws SQLException
|
||||
{
|
||||
if (x == null){
|
||||
setNull(parameterIndex,Types.OTHER);
|
||||
return;
|
||||
if (x == null)
|
||||
{
|
||||
setNull(parameterIndex, Types.OTHER);
|
||||
return ;
|
||||
}
|
||||
if (x instanceof String)
|
||||
setString(parameterIndex, (String)x);
|
||||
@ -667,11 +717,11 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
|
||||
/**
|
||||
* Some prepared statements return multiple results; the execute method
|
||||
* handles these complex statements as well as the simpler form of
|
||||
* handles these complex statements as well as the simpler form of
|
||||
* statements handled by executeQuery and executeUpdate
|
||||
*
|
||||
* @return true if the next result is a ResultSet; false if it is an
|
||||
* * update count or there are no more results
|
||||
* * update count or there are no more results
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean execute() throws SQLException
|
||||
@ -682,19 +732,20 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
for (i = 0 ; i < inStrings.length ; ++i)
|
||||
{
|
||||
if (inStrings[i] == null)
|
||||
throw new PSQLException("postgresql.prep.param",new Integer(i + 1));
|
||||
throw new PSQLException("postgresql.prep.param", new Integer(i + 1));
|
||||
s.append (templateStrings[i]);
|
||||
s.append (inStrings[i]);
|
||||
}
|
||||
s.append(templateStrings[inStrings.length]);
|
||||
return super.execute(s.toString()); // in Statement class
|
||||
return super.execute(s.toString()); // in Statement class
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL statement with the current template values
|
||||
* substituted.
|
||||
*/
|
||||
public String toString() {
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer s = new StringBuffer();
|
||||
int i;
|
||||
|
||||
@ -709,14 +760,14 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
|
||||
s.append(templateStrings[inStrings.length]);
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
|
||||
// **************************************************************
|
||||
// END OF PUBLIC INTERFACE
|
||||
// END OF PUBLIC INTERFACE
|
||||
// **************************************************************
|
||||
|
||||
|
||||
/**
|
||||
* There are a lot of setXXX classes which all basically do
|
||||
* the same thing. We need a method which actually does the
|
||||
* the same thing. We need a method which actually does the
|
||||
* set for us.
|
||||
*
|
||||
* @param paramIndex the index into the inString
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -22,442 +22,455 @@ import java.sql.Types;
|
||||
*
|
||||
* @see java.sql.ResultSetMetaData
|
||||
*/
|
||||
public class ResultSetMetaData implements java.sql.ResultSetMetaData
|
||||
public class ResultSetMetaData implements java.sql.ResultSetMetaData
|
||||
{
|
||||
Vector rows;
|
||||
Field[] fields;
|
||||
|
||||
/**
|
||||
* Initialise for a result with a tuple set and
|
||||
* a field descriptor set
|
||||
*
|
||||
* @param rows the Vector of rows returned by the ResultSet
|
||||
* @param fields the array of field descriptors
|
||||
*/
|
||||
public ResultSetMetaData(Vector rows, Field[] fields)
|
||||
{
|
||||
this.rows = rows;
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whats the number of columns in the ResultSet?
|
||||
*
|
||||
* @return the number
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public int getColumnCount() throws SQLException
|
||||
{
|
||||
return fields.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the column automatically numbered (and thus read-only)
|
||||
* I believe that PostgreSQL does not support this feature.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return true if so
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isAutoIncrement(int column) throws SQLException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a column's case matter? ASSUMPTION: Any field that is
|
||||
* not obviously case insensitive is assumed to be case sensitive
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return true if so
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isCaseSensitive(int column) throws SQLException
|
||||
{
|
||||
int sql_type = getField(column).getSQLType();
|
||||
|
||||
switch (sql_type)
|
||||
{
|
||||
case Types.SMALLINT:
|
||||
case Types.INTEGER:
|
||||
case Types.FLOAT:
|
||||
case Types.REAL:
|
||||
case Types.DOUBLE:
|
||||
case Types.DATE:
|
||||
case Types.TIME:
|
||||
case Types.TIMESTAMP:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the column be used in a WHERE clause? Basically for
|
||||
* this, I split the functions into two types: recognised
|
||||
* types (which are always useable), and OTHER types (which
|
||||
* may or may not be useable). The OTHER types, for now, I
|
||||
* will assume they are useable. We should really query the
|
||||
* catalog to see if they are useable.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return true if they can be used in a WHERE clause
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isSearchable(int column) throws SQLException
|
||||
{
|
||||
int sql_type = getField(column).getSQLType();
|
||||
|
||||
// This switch is pointless, I know - but it is a set-up
|
||||
// for further expansion.
|
||||
switch (sql_type)
|
||||
{
|
||||
case Types.OTHER:
|
||||
return true;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the column a cash value? 6.1 introduced the cash/money
|
||||
* type, which haven't been incorporated as of 970414, so I
|
||||
* just check the type name for both 'cash' and 'money'
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return true if its a cash column
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isCurrency(int column) throws SQLException
|
||||
{
|
||||
String type_name = getField(column).getPGType();
|
||||
|
||||
return type_name.equals("cash") || type_name.equals("money");
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the nullability of values in the designated column.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return one of the columnNullable values
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public int isNullable(int column) throws SQLException
|
||||
{
|
||||
/*
|
||||
* TODO This needs a real implementation, taking into account columns
|
||||
* defined with NOT NULL or PRIMARY KEY, CHECK constraints, views,
|
||||
* functions etc.
|
||||
Vector rows;
|
||||
Field[] fields;
|
||||
|
||||
/**
|
||||
* Initialise for a result with a tuple set and
|
||||
* a field descriptor set
|
||||
*
|
||||
* @param rows the Vector of rows returned by the ResultSet
|
||||
* @param fields the array of field descriptors
|
||||
*/
|
||||
return columnNullableUnknown;
|
||||
}
|
||||
public ResultSetMetaData(Vector rows, Field[] fields)
|
||||
{
|
||||
this.rows = rows;
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the column a signed number? In PostgreSQL, all numbers
|
||||
* are signed, so this is trivial. However, strings are not
|
||||
* signed (duh!)
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return true if so
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isSigned(int column) throws SQLException
|
||||
{
|
||||
int sql_type = getField(column).getSQLType();
|
||||
|
||||
switch (sql_type)
|
||||
{
|
||||
case Types.SMALLINT:
|
||||
case Types.INTEGER:
|
||||
case Types.FLOAT:
|
||||
case Types.REAL:
|
||||
case Types.DOUBLE:
|
||||
return true;
|
||||
case Types.DATE:
|
||||
case Types.TIME:
|
||||
case Types.TIMESTAMP:
|
||||
return false; // I don't know about these?
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What is the column's normal maximum width in characters?
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return the maximum width
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public int getColumnDisplaySize(int column) throws SQLException
|
||||
{
|
||||
Field f = getField(column);
|
||||
String type_name = f.getPGType();
|
||||
int sql_type = f.getSQLType();
|
||||
int typmod = f.getMod();
|
||||
/**
|
||||
* Whats the number of columns in the ResultSet?
|
||||
*
|
||||
* @return the number
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public int getColumnCount() throws SQLException
|
||||
{
|
||||
return fields.length;
|
||||
}
|
||||
|
||||
// I looked at other JDBC implementations and couldn't find a consistent
|
||||
// interpretation of the "display size" for numeric values, so this is our's
|
||||
// FIXME: currently, only types with a SQL92 or SQL3 pendant are implemented - jens@jens.de
|
||||
/**
|
||||
* Is the column automatically numbered (and thus read-only)
|
||||
* I believe that PostgreSQL does not support this feature.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return true if so
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isAutoIncrement(int column) throws SQLException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// fixed length data types
|
||||
if (type_name.equals( "int2" )) return 6; // -32768 to +32768 (5 digits and a sign)
|
||||
if (type_name.equals( "int4" )
|
||||
|| type_name.equals( "oid" )) return 11; // -2147483648 to +2147483647
|
||||
if (type_name.equals( "int8" )) return 20; // -9223372036854775808 to +9223372036854775807
|
||||
if (type_name.equals( "money" )) return 12; // MONEY = DECIMAL(9,2)
|
||||
if (type_name.equals( "float4" )) return 11; // i checked it out ans wasn't able to produce more than 11 digits
|
||||
if (type_name.equals( "float8" )) return 20; // dito, 20
|
||||
if (type_name.equals( "char" )) return 1;
|
||||
if (type_name.equals( "bool" )) return 1;
|
||||
if (type_name.equals( "date" )) return 14; // "01/01/4713 BC" - "31/12/32767 AD"
|
||||
if (type_name.equals( "time" )) return 8; // 00:00:00-23:59:59
|
||||
if (type_name.equals( "timestamp" )) return 22; // hhmmm ... the output looks like this: 1999-08-03 22:22:08+02
|
||||
/**
|
||||
* Does a column's case matter? ASSUMPTION: Any field that is
|
||||
* not obviously case insensitive is assumed to be case sensitive
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return true if so
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isCaseSensitive(int column) throws SQLException
|
||||
{
|
||||
int sql_type = getField(column).getSQLType();
|
||||
|
||||
// variable length fields
|
||||
typmod -= 4;
|
||||
if (type_name.equals( "bpchar" )
|
||||
|| type_name.equals( "varchar" )) return typmod; // VARHDRSZ=sizeof(int32)=4
|
||||
if (type_name.equals( "numeric" )) return ( (typmod >>16) & 0xffff )
|
||||
+ 1 + ( typmod & 0xffff ); // DECIMAL(p,s) = (p digits).(s digits)
|
||||
switch (sql_type)
|
||||
{
|
||||
case Types.SMALLINT:
|
||||
case Types.INTEGER:
|
||||
case Types.FLOAT:
|
||||
case Types.REAL:
|
||||
case Types.DOUBLE:
|
||||
case Types.DATE:
|
||||
case Types.TIME:
|
||||
case Types.TIMESTAMP:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// if we don't know better
|
||||
return f.getLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* What is the suggested column title for use in printouts and
|
||||
* displays? We suggest the ColumnName!
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return the column label
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public String getColumnLabel(int column) throws SQLException
|
||||
{
|
||||
return getColumnName(column);
|
||||
}
|
||||
|
||||
/**
|
||||
* What's a column's name?
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return the column name
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public String getColumnName(int column) throws SQLException
|
||||
{
|
||||
Field f = getField(column);
|
||||
if(f!=null)
|
||||
return f.getName();
|
||||
return "field"+column;
|
||||
}
|
||||
|
||||
/**
|
||||
* What is a column's table's schema? This relies on us knowing
|
||||
* the table name....which I don't know how to do as yet. The
|
||||
* JDBC specification allows us to return "" if this is not
|
||||
* applicable.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return the Schema
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public String getSchemaName(int column) throws SQLException
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* What is a column's number of decimal digits.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return the precision
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public int getPrecision(int column) throws SQLException
|
||||
{
|
||||
int sql_type = getField(column).getSQLType();
|
||||
|
||||
switch (sql_type)
|
||||
{
|
||||
case Types.SMALLINT:
|
||||
return 5;
|
||||
case Types.INTEGER:
|
||||
return 10;
|
||||
case Types.REAL:
|
||||
return 8;
|
||||
case Types.FLOAT:
|
||||
return 16;
|
||||
case Types.DOUBLE:
|
||||
return 16;
|
||||
case Types.VARCHAR:
|
||||
return 0;
|
||||
case Types.NUMERIC:
|
||||
Field f = getField(column);
|
||||
if(f != null)
|
||||
return ((0xFFFF0000)&f.getMod())>>16;
|
||||
else
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What is a column's number of digits to the right of the
|
||||
* decimal point?
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return the scale
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public int getScale(int column) throws SQLException
|
||||
{
|
||||
int sql_type = getField(column).getSQLType();
|
||||
|
||||
switch (sql_type)
|
||||
{
|
||||
case Types.SMALLINT:
|
||||
return 0;
|
||||
case Types.INTEGER:
|
||||
return 0;
|
||||
case Types.REAL:
|
||||
return 8;
|
||||
case Types.FLOAT:
|
||||
return 16;
|
||||
case Types.DOUBLE:
|
||||
return 16;
|
||||
case Types.VARCHAR:
|
||||
return 0;
|
||||
case Types.NUMERIC:
|
||||
Field f = getField(column);
|
||||
if(f != null)
|
||||
return (((0x0000FFFF)&f.getMod())-4);
|
||||
else
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whats a column's table's name? How do I find this out? Both
|
||||
* getSchemaName() and getCatalogName() rely on knowing the table
|
||||
* Name, so we need this before we can work on them.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return column name, or "" if not applicable
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public String getTableName(int column) throws SQLException
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* What's a column's table's catalog name? As with getSchemaName(),
|
||||
* we can say that if getTableName() returns n/a, then we can too -
|
||||
* otherwise, we need to work on it.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return catalog name, or "" if not applicable
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public String getCatalogName(int column) throws SQLException
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* What is a column's SQL Type? (java.sql.Type int)
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return the java.sql.Type value
|
||||
* @exception SQLException if a database access error occurs
|
||||
* @see org.postgresql.Field#getSQLType
|
||||
* @see java.sql.Types
|
||||
*/
|
||||
public int getColumnType(int column) throws SQLException
|
||||
{
|
||||
return getField(column).getSQLType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whats is the column's data source specific type name?
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return the type name
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public String getColumnTypeName(int column) throws SQLException
|
||||
{
|
||||
return getField(column).getPGType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the column definitely not writable? In reality, we would
|
||||
* have to check the GRANT/REVOKE stuff for this to be effective,
|
||||
* and I haven't really looked into that yet, so this will get
|
||||
* re-visited.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return true if so
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isReadOnly(int column) throws SQLException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible for a write on the column to succeed? Again, we
|
||||
* would in reality have to check the GRANT/REVOKE stuff, which
|
||||
* I haven't worked with as yet. However, if it isn't ReadOnly, then
|
||||
* it is obviously writable.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return true if so
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isWritable(int column) throws SQLException
|
||||
{
|
||||
return !isReadOnly(column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will a write on this column definately succeed? Hmmm...this
|
||||
* is a bad one, since the two preceding functions have not been
|
||||
* really defined. I cannot tell is the short answer. I thus
|
||||
* return isWritable() just to give us an idea.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc..
|
||||
* @return true if so
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isDefinitelyWritable(int column) throws SQLException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// ********************************************************
|
||||
// END OF PUBLIC INTERFACE
|
||||
// ********************************************************
|
||||
|
||||
/**
|
||||
* For several routines in this package, we need to convert
|
||||
* a columnIndex into a Field[] descriptor. Rather than do
|
||||
* the same code several times, here it is.
|
||||
*
|
||||
* @param columnIndex the first column is 1, the second is 2...
|
||||
* @return the Field description
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
private Field getField(int columnIndex) throws SQLException
|
||||
{
|
||||
if (columnIndex < 1 || columnIndex > fields.length)
|
||||
throw new PSQLException("postgresql.res.colrange");
|
||||
return fields[columnIndex - 1];
|
||||
}
|
||||
/**
|
||||
* Can the column be used in a WHERE clause? Basically for
|
||||
* this, I split the functions into two types: recognised
|
||||
* types (which are always useable), and OTHER types (which
|
||||
* may or may not be useable). The OTHER types, for now, I
|
||||
* will assume they are useable. We should really query the
|
||||
* catalog to see if they are useable.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return true if they can be used in a WHERE clause
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isSearchable(int column) throws SQLException
|
||||
{
|
||||
int sql_type = getField(column).getSQLType();
|
||||
|
||||
// This switch is pointless, I know - but it is a set-up
|
||||
// for further expansion.
|
||||
switch (sql_type)
|
||||
{
|
||||
case Types.OTHER:
|
||||
return true;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the column a cash value? 6.1 introduced the cash/money
|
||||
* type, which haven't been incorporated as of 970414, so I
|
||||
* just check the type name for both 'cash' and 'money'
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return true if its a cash column
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isCurrency(int column) throws SQLException
|
||||
{
|
||||
String type_name = getField(column).getPGType();
|
||||
|
||||
return type_name.equals("cash") || type_name.equals("money");
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the nullability of values in the designated column.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return one of the columnNullable values
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public int isNullable(int column) throws SQLException
|
||||
{
|
||||
/*
|
||||
* TODO This needs a real implementation, taking into account columns
|
||||
* defined with NOT NULL or PRIMARY KEY, CHECK constraints, views,
|
||||
* functions etc.
|
||||
*/
|
||||
return columnNullableUnknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the column a signed number? In PostgreSQL, all numbers
|
||||
* are signed, so this is trivial. However, strings are not
|
||||
* signed (duh!)
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return true if so
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isSigned(int column) throws SQLException
|
||||
{
|
||||
int sql_type = getField(column).getSQLType();
|
||||
|
||||
switch (sql_type)
|
||||
{
|
||||
case Types.SMALLINT:
|
||||
case Types.INTEGER:
|
||||
case Types.FLOAT:
|
||||
case Types.REAL:
|
||||
case Types.DOUBLE:
|
||||
return true;
|
||||
case Types.DATE:
|
||||
case Types.TIME:
|
||||
case Types.TIMESTAMP:
|
||||
return false; // I don't know about these?
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What is the column's normal maximum width in characters?
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return the maximum width
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public int getColumnDisplaySize(int column) throws SQLException
|
||||
{
|
||||
Field f = getField(column);
|
||||
String type_name = f.getPGType();
|
||||
int sql_type = f.getSQLType();
|
||||
int typmod = f.getMod();
|
||||
|
||||
// I looked at other JDBC implementations and couldn't find a consistent
|
||||
// interpretation of the "display size" for numeric values, so this is our's
|
||||
// FIXME: currently, only types with a SQL92 or SQL3 pendant are implemented - jens@jens.de
|
||||
|
||||
// fixed length data types
|
||||
if (type_name.equals( "int2" ))
|
||||
return 6; // -32768 to +32768 (5 digits and a sign)
|
||||
if (type_name.equals( "int4" )
|
||||
|| type_name.equals( "oid" ))
|
||||
return 11; // -2147483648 to +2147483647
|
||||
if (type_name.equals( "int8" ))
|
||||
return 20; // -9223372036854775808 to +9223372036854775807
|
||||
if (type_name.equals( "money" ))
|
||||
return 12; // MONEY = DECIMAL(9,2)
|
||||
if (type_name.equals( "float4" ))
|
||||
return 11; // i checked it out ans wasn't able to produce more than 11 digits
|
||||
if (type_name.equals( "float8" ))
|
||||
return 20; // dito, 20
|
||||
if (type_name.equals( "char" ))
|
||||
return 1;
|
||||
if (type_name.equals( "bool" ))
|
||||
return 1;
|
||||
if (type_name.equals( "date" ))
|
||||
return 14; // "01/01/4713 BC" - "31/12/32767 AD"
|
||||
if (type_name.equals( "time" ))
|
||||
return 8; // 00:00:00-23:59:59
|
||||
if (type_name.equals( "timestamp" ))
|
||||
return 22; // hhmmm ... the output looks like this: 1999-08-03 22:22:08+02
|
||||
|
||||
// variable length fields
|
||||
typmod -= 4;
|
||||
if (type_name.equals( "bpchar" )
|
||||
|| type_name.equals( "varchar" ))
|
||||
return typmod; // VARHDRSZ=sizeof(int32)=4
|
||||
if (type_name.equals( "numeric" ))
|
||||
return ( (typmod >> 16) & 0xffff )
|
||||
+ 1 + ( typmod & 0xffff ); // DECIMAL(p,s) = (p digits).(s digits)
|
||||
|
||||
// if we don't know better
|
||||
return f.getLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* What is the suggested column title for use in printouts and
|
||||
* displays? We suggest the ColumnName!
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return the column label
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public String getColumnLabel(int column) throws SQLException
|
||||
{
|
||||
return getColumnName(column);
|
||||
}
|
||||
|
||||
/**
|
||||
* What's a column's name?
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return the column name
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public String getColumnName(int column) throws SQLException
|
||||
{
|
||||
Field f = getField(column);
|
||||
if (f != null)
|
||||
return f.getName();
|
||||
return "field" + column;
|
||||
}
|
||||
|
||||
/**
|
||||
* What is a column's table's schema? This relies on us knowing
|
||||
* the table name....which I don't know how to do as yet. The
|
||||
* JDBC specification allows us to return "" if this is not
|
||||
* applicable.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return the Schema
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public String getSchemaName(int column) throws SQLException
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* What is a column's number of decimal digits.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return the precision
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public int getPrecision(int column) throws SQLException
|
||||
{
|
||||
int sql_type = getField(column).getSQLType();
|
||||
|
||||
switch (sql_type)
|
||||
{
|
||||
case Types.SMALLINT:
|
||||
return 5;
|
||||
case Types.INTEGER:
|
||||
return 10;
|
||||
case Types.REAL:
|
||||
return 8;
|
||||
case Types.FLOAT:
|
||||
return 16;
|
||||
case Types.DOUBLE:
|
||||
return 16;
|
||||
case Types.VARCHAR:
|
||||
return 0;
|
||||
case Types.NUMERIC:
|
||||
Field f = getField(column);
|
||||
if (f != null)
|
||||
return ((0xFFFF0000)&f.getMod()) >> 16;
|
||||
else
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What is a column's number of digits to the right of the
|
||||
* decimal point?
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return the scale
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public int getScale(int column) throws SQLException
|
||||
{
|
||||
int sql_type = getField(column).getSQLType();
|
||||
|
||||
switch (sql_type)
|
||||
{
|
||||
case Types.SMALLINT:
|
||||
return 0;
|
||||
case Types.INTEGER:
|
||||
return 0;
|
||||
case Types.REAL:
|
||||
return 8;
|
||||
case Types.FLOAT:
|
||||
return 16;
|
||||
case Types.DOUBLE:
|
||||
return 16;
|
||||
case Types.VARCHAR:
|
||||
return 0;
|
||||
case Types.NUMERIC:
|
||||
Field f = getField(column);
|
||||
if (f != null)
|
||||
return (((0x0000FFFF)&f.getMod()) - 4);
|
||||
else
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whats a column's table's name? How do I find this out? Both
|
||||
* getSchemaName() and getCatalogName() rely on knowing the table
|
||||
* Name, so we need this before we can work on them.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return column name, or "" if not applicable
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public String getTableName(int column) throws SQLException
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* What's a column's table's catalog name? As with getSchemaName(),
|
||||
* we can say that if getTableName() returns n/a, then we can too -
|
||||
* otherwise, we need to work on it.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2...
|
||||
* @return catalog name, or "" if not applicable
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public String getCatalogName(int column) throws SQLException
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* What is a column's SQL Type? (java.sql.Type int)
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return the java.sql.Type value
|
||||
* @exception SQLException if a database access error occurs
|
||||
* @see org.postgresql.Field#getSQLType
|
||||
* @see java.sql.Types
|
||||
*/
|
||||
public int getColumnType(int column) throws SQLException
|
||||
{
|
||||
return getField(column).getSQLType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whats is the column's data source specific type name?
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return the type name
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public String getColumnTypeName(int column) throws SQLException
|
||||
{
|
||||
return getField(column).getPGType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the column definitely not writable? In reality, we would
|
||||
* have to check the GRANT/REVOKE stuff for this to be effective,
|
||||
* and I haven't really looked into that yet, so this will get
|
||||
* re-visited.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return true if so
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isReadOnly(int column) throws SQLException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible for a write on the column to succeed? Again, we
|
||||
* would in reality have to check the GRANT/REVOKE stuff, which
|
||||
* I haven't worked with as yet. However, if it isn't ReadOnly, then
|
||||
* it is obviously writable.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc.
|
||||
* @return true if so
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isWritable(int column) throws SQLException
|
||||
{
|
||||
return !isReadOnly(column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will a write on this column definately succeed? Hmmm...this
|
||||
* is a bad one, since the two preceding functions have not been
|
||||
* really defined. I cannot tell is the short answer. I thus
|
||||
* return isWritable() just to give us an idea.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, etc..
|
||||
* @return true if so
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean isDefinitelyWritable(int column) throws SQLException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// ********************************************************
|
||||
// END OF PUBLIC INTERFACE
|
||||
// ********************************************************
|
||||
|
||||
/**
|
||||
* For several routines in this package, we need to convert
|
||||
* a columnIndex into a Field[] descriptor. Rather than do
|
||||
* the same code several times, here it is.
|
||||
*
|
||||
* @param columnIndex the first column is 1, the second is 2...
|
||||
* @return the Field description
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
private Field getField(int columnIndex) throws SQLException
|
||||
{
|
||||
if (columnIndex < 1 || columnIndex > fields.length)
|
||||
throw new PSQLException("postgresql.res.colrange");
|
||||
return fields[columnIndex - 1];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ import org.postgresql.util.PSQLException;
|
||||
* <p>Only one ResultSet per Statement can be open at any point in time.
|
||||
* Therefore, if the reading of one ResultSet is interleaved with the
|
||||
* reading of another, each must have been generated by different
|
||||
* Statements. All statement execute methods implicitly close a
|
||||
* Statements. All statement execute methods implicitly close a
|
||||
* statement's current ResultSet if an open one exists.
|
||||
*
|
||||
* @see java.sql.Statement
|
||||
@ -24,7 +24,7 @@ import org.postgresql.util.PSQLException;
|
||||
*/
|
||||
public class Statement extends org.postgresql.Statement implements java.sql.Statement
|
||||
{
|
||||
private Connection connection; // The connection who created us
|
||||
private Connection connection; // The connection who created us
|
||||
|
||||
/**
|
||||
* Constructor for a Statement. It simply sets the connection
|
||||
@ -73,7 +73,7 @@ public class Statement extends org.postgresql.Statement implements java.sql.Stat
|
||||
|
||||
/**
|
||||
* setCursorName defines the SQL cursor name that will be used by
|
||||
* subsequent execute methods. This name can then be used in SQL
|
||||
* subsequent execute methods. This name can then be used in SQL
|
||||
* positioned update/delete statements to identify the current row
|
||||
* in the ResultSet generated by this statement. If a database
|
||||
* doesn't support positioned update/delete, this method is a
|
||||
@ -81,10 +81,10 @@ public class Statement extends org.postgresql.Statement implements java.sql.Stat
|
||||
*
|
||||
* <p><B>Note:</B> By definition, positioned update/delete execution
|
||||
* must be done by a different Statement than the one which
|
||||
* generated the ResultSet being used for positioning. Also, cursor
|
||||
* generated the ResultSet being used for positioning. Also, cursor
|
||||
* names must be unique within a Connection.
|
||||
*
|
||||
* <p>We throw an additional constriction. There can only be one
|
||||
* <p>We throw an additional constriction. There can only be one
|
||||
* cursor active at any one time.
|
||||
*
|
||||
* @param name the new cursor name
|
||||
@ -98,20 +98,20 @@ public class Statement extends org.postgresql.Statement implements java.sql.Stat
|
||||
/**
|
||||
* Execute a SQL statement that may return multiple results. We
|
||||
* don't have to worry about this since we do not support multiple
|
||||
* ResultSets. You can use getResultSet or getUpdateCount to
|
||||
* ResultSets. You can use getResultSet or getUpdateCount to
|
||||
* retrieve the result.
|
||||
*
|
||||
* @param sql any SQL statement
|
||||
* @return true if the next result is a ResulSet, false if it is
|
||||
* an update count or there are no more results
|
||||
* an update count or there are no more results
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
public boolean execute(String sql) throws SQLException
|
||||
{
|
||||
if (escapeProcessing)
|
||||
sql = escapeSQL(sql);
|
||||
result = connection.ExecSQL(sql);
|
||||
return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet());
|
||||
if (escapeProcessing)
|
||||
sql = escapeSQL(sql);
|
||||
result = connection.ExecSQL(sql);
|
||||
return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,8 +124,10 @@ public class Statement extends org.postgresql.Statement implements java.sql.Stat
|
||||
*/
|
||||
public int getUpdateCount() throws SQLException
|
||||
{
|
||||
if (result == null) return -1;
|
||||
if (((org.postgresql.ResultSet)result).reallyResultSet()) return -1;
|
||||
if (result == null)
|
||||
return -1;
|
||||
if (((org.postgresql.ResultSet)result).reallyResultSet())
|
||||
return -1;
|
||||
return ((org.postgresql.ResultSet)result).getResultCount();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user