1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
/*-------------------------------------------------------------------------
*
* Copyright (c) 2005-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgjdbc/org/postgresql/jdbc3/AbstractJdbc3ParameterMetaData.java,v 1.3 2008/04/15 04:23:58 jurka Exp $
*
*-------------------------------------------------------------------------
*/
package org.postgresql.jdbc3;
import java.sql.SQLException;
import java.sql.ParameterMetaData;
import org.postgresql.util.GT;
import org.postgresql.util.PSQLState;
import org.postgresql.util.PSQLException;
import org.postgresql.core.BaseConnection;
import org.postgresql.jdbc2.TypeInfoCache;
public abstract class AbstractJdbc3ParameterMetaData {
private final BaseConnection _connection;
private final int _oids[];
public AbstractJdbc3ParameterMetaData(BaseConnection connection, int oids[]) {
_connection = connection;
_oids = oids;
}
public String getParameterClassName(int param) throws SQLException {
checkParamIndex(param);
return _connection.getTypeInfo().getJavaClass(_oids[param-1]);
}
public int getParameterCount() {
return _oids.length;
}
// For now report all parameters as inputs. CallableStatements may
// have one output, but ignore that for now.
public int getParameterMode(int param) throws SQLException {
checkParamIndex(param);
return ParameterMetaData.parameterModeIn;
}
public int getParameterType(int param) throws SQLException {
checkParamIndex(param);
return _connection.getTypeInfo().getSQLType(_oids[param-1]);
}
public String getParameterTypeName(int param) throws SQLException {
checkParamIndex(param);
return _connection.getTypeInfo().getPGType(_oids[param-1]);
}
// we don't know this
public int getPrecision(int param) throws SQLException {
checkParamIndex(param);
return 0;
}
// we don't know this
public int getScale(int param) throws SQLException {
checkParamIndex(param);
return 0;
}
// we can't tell anything about nullability
public int isNullable(int param) throws SQLException {
checkParamIndex(param);
return ParameterMetaData.parameterNullableUnknown;
}
// pg doesn't have unsigned numbers
public boolean isSigned(int param) throws SQLException {
checkParamIndex(param);
return _connection.getTypeInfo().isSigned(_oids[param-1]);
}
private void checkParamIndex(int param) throws PSQLException {
if (param < 1 || param > _oids.length)
throw new PSQLException(GT.tr("The parameter index is out of range: {0}, number of parameters: {1}.", new Object[]{new Integer(param), new Integer(_oids.length)}), PSQLState.INVALID_PARAMETER_VALUE);
}
}
|