/** * Parses a double value from the byte array. * * @param bytes The byte array to parse. * @param idx The starting index of the parse in the byte array. * @return parsed double value. */ public static double float8(byte[] bytes, int idx) { return Double.longBitsToDouble(int8(bytes, idx)); }
/** * Encodes a int value to the byte array. * * @param target The byte array to encode to. * @param idx The starting index in the byte array. * @param value The value to encode. */ public static void float8(byte[] target, int idx, double value) { int8(target, idx, Double.doubleToRawLongBits(value)); } }
private void setUuid(int parameterIndex, UUID uuid) throws SQLException { if (connection.binaryTransferSend(Oid.UUID)) { byte[] val = new byte[16]; ByteConverter.int8(val, 0, uuid.getMostSignificantBits()); ByteConverter.int8(val, 8, uuid.getLeastSignificantBits()); bindBytes(parameterIndex, val, Oid.UUID); } else { bindLiteral(parameterIndex, uuid.toString(), Oid.UUID); } }
public void setLong(int parameterIndex, long x) throws SQLException { checkClosed(); if (connection.binaryTransferSend(Oid.INT8)) { byte[] val = new byte[8]; ByteConverter.int8(val, 0, x); bindBytes(parameterIndex, val, Oid.INT8); return; } bindLiteral(parameterIndex, Long.toString(x), Oid.INT8); }
/** * Send a function call to the PostgreSQL backend. * * @param fnId Function id * @param resultType True if the result is a numeric (Integer or Long) * @param args FastpathArguments to pass to fastpath * @return null if no data, Integer if an integer result, Long if a long result, or byte[] * otherwise * @throws SQLException if a database-access error occurs. * @deprecated please use {@link #fastpath(int, FastpathArg[])} */ @Deprecated public Object fastpath(int fnId, boolean resultType, FastpathArg[] args) throws SQLException { // Run it. byte[] returnValue = fastpath(fnId, args); // Interpret results. if (!resultType || returnValue == null) { return returnValue; } if (returnValue.length == 4) { return ByteConverter.int4(returnValue, 0); } else if (returnValue.length == 8) { return ByteConverter.int8(returnValue, 0); } else { throw new PSQLException( GT.tr("Fastpath call {0} - No result was returned and we expected a numeric.", fnId), PSQLState.NO_DATA); } }
long l = ByteConverter.int8((byte[]) paramValues[index], 0); return Long.toString(l);
/** * Returns the SQL Time object matching the given bytes with {@link Oid#TIME}. * * @param bytes The binary encoded time value. * @return The parsed time object. * @throws PSQLException If binary format could not be parsed. */ public LocalTime toLocalTimeBin(byte[] bytes) throws PSQLException { if (bytes.length != 8) { throw new PSQLException(GT.tr("Unsupported binary encoding of {0}.", "time"), PSQLState.BAD_DATETIME_FORMAT); } long micros; if (usesDouble) { double seconds = ByteConverter.float8(bytes, 0); micros = (long) (seconds * 1000000d); } else { micros = ByteConverter.int8(bytes, 0); } return LocalTime.ofNanoOfDay(micros * 1000); } //JCP! endif
/** * {@inheritDoc} */ @Override public byte[] toBinaryRepresentation(Connection connection, long[] array) { int length = 20 + (12 * 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.INT8); // length ByteConverter.int4(bytes, 12, array.length); int idx = 20; for (int i = 0; i < array.length; ++i) { bytes[idx + 3] = 8; ByteConverter.int8(bytes, idx + 4, array[i]); idx += 12; } return bytes; } };
/** * This convenience method assumes that the return value is a long (bigint). * * @param name Function name * @param args Function arguments * @return long result * @throws SQLException if a database-access error occurs or no result */ public long getLong(String name, FastpathArg[] args) throws SQLException { byte[] returnValue = fastpath(name, args); if (returnValue == null) { throw new PSQLException( GT.tr("Fastpath call {0} - No result was returned and we expected a long.", name), PSQLState.NO_DATA); } if (returnValue.length == 8) { return ByteConverter.int8(returnValue, 0); } else { throw new PSQLException( GT.tr("Fastpath call {0} - No result was returned or wrong size while expecting a long.", name), PSQLState.NO_DATA); } }
long time = ByteConverter.int8(bytes, 0);
public long getLong(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getLong 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.INT8) { return ByteConverter.int8(this_row[col], 0); } return readLongValue(this_row[col], oid, Long.MIN_VALUE, Long.MAX_VALUE, "long"); } Encoding encoding = connection.getEncoding(); if (encoding.hasAsciiNumbers()) { try { return getFastLong(columnIndex); } catch (NumberFormatException ex) { } } return toLong(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.INT8: val = ByteConverter.int8(bytes, 0); break; case Oid.FLOAT4:
nanos = (int) ((time - secs) * 1000000); } else { long time = ByteConverter.int8(bytes, 0);
break; case Oid.INT8: arr[i] = ByteConverter.int8(fieldBytes, pos); break; case Oid.FLOAT4: