use of org.jkiss.dbeaver.model.struct.DBSTypedObject in project dbeaver by serge-rider.
the class PostgreStructValueHandler method bindParameter.
@Override
protected void bindParameter(JDBCSession session, JDBCPreparedStatement statement, DBSTypedObject paramType, int paramIndex, Object value) throws DBCException, SQLException {
if (value == null) {
statement.setNull(paramIndex, Types.STRUCT);
} else if (value instanceof DBDComposite) {
DBDComposite struct = (DBDComposite) value;
if (struct.isNull()) {
statement.setNull(paramIndex, Types.STRUCT);
} else if (struct instanceof JDBCComposite) {
final Object[] values = ((JDBCComposite) struct).getValues();
final String string = PostgreUtils.generateObjectString(values);
statement.setObject(paramIndex, string, Types.OTHER);
}
} else {
throw new DBCException("Struct parameter type '" + value.getClass().getName() + "' not supported");
}
}
use of org.jkiss.dbeaver.model.struct.DBSTypedObject in project dbeaver by serge-rider.
the class JDBCNumberValueHandler method fetchColumnValue.
@Nullable
@Override
protected Object fetchColumnValue(DBCSession session, JDBCResultSet resultSet, DBSTypedObject type, int index) throws DBCException, SQLException {
Number value;
switch(type.getTypeID()) {
case Types.DOUBLE:
case Types.REAL:
value = resultSet.getDouble(index);
break;
case Types.FLOAT:
try {
// Read value with maximum precision. Some drivers reports FLOAT but means double [JDBC:SQLite]
value = resultSet.getDouble(index);
} catch (SQLException e) {
value = resultSet.getFloat(index);
}
break;
case Types.INTEGER:
try {
// Read value with maximum precision. Some drivers reports INTEGER but means long [JDBC:SQLite]
value = resultSet.getLong(index);
} catch (SQLException e) {
value = resultSet.getInt(index);
}
break;
case Types.SMALLINT:
// Read int in case of unsigned shorts
value = resultSet.getInt(index);
break;
case Types.TINYINT:
// Read short in case of unsigned byte
value = resultSet.getShort(index);
break;
case Types.BIT:
if (type.getPrecision() <= 1) {
// single bit
value = resultSet.getByte(index);
} else {
// bit string
return CommonUtils.toBinaryString(resultSet.getLong(index), type.getPrecision());
}
break;
default:
// Here may be any numeric value. BigDecimal or BigInteger for example
boolean gotValue = false;
value = null;
try {
Object objectValue = resultSet.getObject(index);
if (objectValue == null || objectValue instanceof Number) {
value = (Number) objectValue;
gotValue = true;
}
} catch (SQLException e) {
log.debug(e);
}
if (value == null && !gotValue) {
if (type.getScale() > 0) {
value = resultSet.getDouble(index);
} else {
value = resultSet.getLong(index);
}
}
break;
}
if (resultSet.wasNull()) {
return null;
} else {
return value;
}
}
Aggregations