public void setFloat(int parameterIndex, float x) throws SQLException { checkClosed(); if (connection.binaryTransferSend(Oid.FLOAT4)) { byte[] val = new byte[4]; ByteConverter.float4(val, 0, x); bindBytes(parameterIndex, val, Oid.FLOAT4); return; } bindLiteral(parameterIndex, Float.toString(x), Oid.FLOAT8); }
float f = ByteConverter.float4((byte[]) paramValues[index], 0); return Float.toString(f);
/** * {@inheritDoc} */ @Override public byte[] toBinaryRepresentation(Connection connection, float[] array) { int length = 20 + (8 * array.length); final byte[] bytes = new byte[length]; // 1 dimension ByteConverter.int4(bytes, 0, 1); // no null ByteConverter.int4(bytes, 4, 0); // oid ByteConverter.int4(bytes, 8, Oid.FLOAT4); // length ByteConverter.int4(bytes, 12, array.length); int idx = 20; for (int i = 0; i < array.length; ++i) { bytes[idx + 3] = 4; ByteConverter.float4(bytes, idx + 4, array[i]); idx += 8; } return bytes; }
public float getFloat(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getFloat columnIndex: {0}", columnIndex); checkResultSet(columnIndex); if (wasNullFlag) { return 0; // SQL NULL } if (isBinary(columnIndex)) { int col = columnIndex - 1; int oid = fields[col].getOID(); if (oid == Oid.FLOAT4) { return ByteConverter.float4(this_row[col], 0); } return (float) readDoubleValue(this_row[col], oid, "float"); } return toFloat(getFixedString(columnIndex)); }
/** * Converts any numeric binary field to double value. This method does no overflow checking. * * @param bytes The bytes of the numeric field. * @param oid The oid of the field. * @param targetType The target type. Used for error reporting. * @return The value as double. * @throws PSQLException If the field type is not supported numeric type. */ private double readDoubleValue(byte[] bytes, int oid, String targetType) throws PSQLException { // currently implemented binary encoded fields switch (oid) { case Oid.INT2: return ByteConverter.int2(bytes, 0); case Oid.INT4: return ByteConverter.int4(bytes, 0); case Oid.INT8: // might not fit but there still should be no overflow checking return ByteConverter.int8(bytes, 0); case Oid.FLOAT4: return ByteConverter.float4(bytes, 0); case Oid.FLOAT8: return ByteConverter.float8(bytes, 0); } throw new PSQLException(GT.tr("Cannot convert the column of type {0} to requested type {1}.", Oid.toString(oid), targetType), PSQLState.DATA_TYPE_MISMATCH); }
break; case Oid.FLOAT4: val = (long) ByteConverter.float4(bytes, 0); break; case Oid.FLOAT8:
break; case Oid.FLOAT4: arr[i] = ByteConverter.float4(fieldBytes, pos); break; case Oid.FLOAT8: