public java.io.Reader getCharacterStream(int i) throws SQLException { checkResultSet(i); if (wasNullFlag) { return null; } // Version 7.2 supports AsciiStream for all the PG text types // As the spec/javadoc for this method indicate this is to be used for // large text values (i.e. LONGVARCHAR) PG doesn't have a separate // long string datatype, but with toast the text datatype is capable of // handling very large values. Thus the implementation ends up calling // getString() since there is no current way to stream the value from the server return new CharArrayReader(getString(i).toCharArray()); }
public InputStream getBinaryStream(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getBinaryStream columnIndex: {0}", columnIndex); checkResultSet(columnIndex); if (wasNullFlag) { return null; } // Version 7.2 supports BinaryStream for all 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 // getBytes() since there is no current way to stream the value from the server byte[] b = getBytes(columnIndex); if (b != null) { return new ByteArrayInputStream(b); } return null; }
public Blob getBlob(int i) throws SQLException { checkResultSet(i); if (wasNullFlag) { return null; } return makeBlob(getLong(i)); }
public Clob getClob(int i) throws SQLException { checkResultSet(i); if (wasNullFlag) { return null; } return makeClob(getLong(i)); }
public InputStream getAsciiStream(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getAsciiStream columnIndex: {0}", columnIndex); checkResultSet(columnIndex); if (wasNullFlag) { return null; } // Version 7.2 supports AsciiStream for all the PG text types // As the spec/javadoc for this method indicate this is to be used for // large text values (i.e. LONGVARCHAR) PG doesn't have a separate // long string datatype, but with toast the text datatype is capable of // handling very large values. Thus the implementation ends up calling // getString() since there is no current way to stream the value from the server try { return new ByteArrayInputStream(getString(columnIndex).getBytes("ASCII")); } catch (UnsupportedEncodingException l_uee) { throw new PSQLException(GT.tr("The JVM claims not to support the encoding: {0}", "ASCII"), PSQLState.UNEXPECTED_ERROR, l_uee); } }
public InputStream getUnicodeStream(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getUnicodeStream columnIndex: {0}", columnIndex); checkResultSet(columnIndex); if (wasNullFlag) { return null; } // Version 7.2 supports AsciiStream for all the PG text types // As the spec/javadoc for this method indicate this is to be used for // large text values (i.e. LONGVARCHAR) PG doesn't have a separate // long string datatype, but with toast the text datatype is capable of // handling very large values. Thus the implementation ends up calling // getString() since there is no current way to stream the value from the server try { return new ByteArrayInputStream(getString(columnIndex).getBytes("UTF-8")); } catch (UnsupportedEncodingException l_uee) { throw new PSQLException(GT.tr("The JVM claims not to support the encoding: {0}", "UTF-8"), PSQLState.UNEXPECTED_ERROR, l_uee); } }
@Override public byte getByte(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getByte columnIndex: {0}", columnIndex); checkResultSet(columnIndex); if (wasNullFlag) { return 0; // SQL NULL
public java.sql.Array getArray(int i) throws SQLException { checkResultSet(i); if (wasNullFlag) { return null; } int oid = fields[i - 1].getOID(); if (isBinary(i)) { return makeArray(oid, this_row[i - 1]); } return makeArray(oid, getFixedString(i)); }
public double getDouble(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getDouble 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.FLOAT8) { return ByteConverter.float8(this_row[col], 0); } return readDoubleValue(this_row[col], oid, "double"); } return toDouble(getFixedString(columnIndex)); }
@Override public short getShort(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getShort 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.INT2) { return ByteConverter.int2(this_row[col], 0); } return (short) readLongValue(this_row[col], oid, Short.MIN_VALUE, Short.MAX_VALUE, "short"); } return toShort(getFixedString(columnIndex)); }
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)); }
/** * {@inheritDoc} * * <p>In normal use, the bytes represent the raw values returned by the backend. However, if the * column is an OID, then it is assumed to refer to a Large Object, and that object is returned as * a byte array.</p> * * <p><b>Be warned</b> If the large object is huge, then you may run out of memory.</p> */ public byte[] getBytes(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getBytes columnIndex: {0}", columnIndex); checkResultSet(columnIndex); if (wasNullFlag) { return null; } if (isBinary(columnIndex)) { // If the data is already binary then just return it return this_row[columnIndex - 1]; } if (fields[columnIndex - 1].getOID() == Oid.BYTEA) { return trimBytes(columnIndex, PGbytea.toBytes(this_row[columnIndex - 1])); } else { return trimBytes(columnIndex, this_row[columnIndex - 1]); } }
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { connection.getLogger().log(Level.FINEST, " getBigDecimal columnIndex: {0}", columnIndex); checkResultSet(columnIndex); if (wasNullFlag) { return null;
public Object getObject(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getObject columnIndex: {0}", columnIndex); Field field; checkResultSet(columnIndex); if (wasNullFlag) { return null; } field = fields[columnIndex - 1]; // some fields can be null, mainly from those returned by MetaData methods if (field == null) { wasNullFlag = true; return null; } Object result = internalGetObject(columnIndex, field); if (result != null) { return result; } if (isBinary(columnIndex)) { return connection.getObject(getPGType(columnIndex), null, this_row[columnIndex - 1]); } return connection.getObject(getPGType(columnIndex), getString(columnIndex), null); }
public boolean getBoolean(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getBoolean columnIndex: {0}", columnIndex); checkResultSet(columnIndex); if (wasNullFlag) { return false; // SQL NULL
private LocalDateTime getLocalDateTime(int i) throws SQLException { checkResultSet(i); if (wasNullFlag) { return null; } int col = i - 1; int oid = fields[col].getOID(); if (oid != Oid.TIMESTAMP) { throw new PSQLException( GT.tr("Cannot convert the column of type {0} to requested type {1}.", Oid.toString(oid), "timestamp"), PSQLState.DATA_TYPE_MISMATCH); } if (isBinary(i)) { TimeZone timeZone = getDefaultCalendar().getTimeZone(); return connection.getTimestampUtils().toLocalDateTimeBin(timeZone, this_row[col]); } String string = getString(i); return connection.getTimestampUtils().toLocalDateTime(string); } //JCP! endif
public int getInt(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getInt 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.INT4) { return ByteConverter.int4(this_row[col], 0); } return (int) readLongValue(this_row[col], oid, Integer.MIN_VALUE, Integer.MAX_VALUE, "int"); } Encoding encoding = connection.getEncoding(); if (encoding.hasAsciiNumbers()) { try { return getFastInt(columnIndex); } catch (NumberFormatException ex) { } } return toInt(getFixedString(columnIndex)); }
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)); }
@Override public java.sql.Date getDate(int i, java.util.Calendar cal) throws SQLException { checkResultSet(i); if (wasNullFlag) { return null; } if (cal == null) { cal = getDefaultCalendar(); } if (isBinary(i)) { int col = i - 1; int oid = fields[col].getOID(); TimeZone tz = cal.getTimeZone(); if (oid == Oid.DATE) { return connection.getTimestampUtils().toDateBin(tz, this_row[col]); } else if (oid == Oid.TIMESTAMP || oid == Oid.TIMESTAMPTZ) { // If backend provides just TIMESTAMP, we use "cal" timezone // If backend provides TIMESTAMPTZ, we ignore "cal" as we know true instant value Timestamp timestamp = getTimestamp(i, cal); // Here we just truncate date to 00:00 in a given time zone return connection.getTimestampUtils().convertToDate(timestamp.getTime(), tz); } else { throw new PSQLException( GT.tr("Cannot convert the column of type {0} to requested type {1}.", Oid.toString(oid), "date"), PSQLState.DATA_TYPE_MISMATCH); } } return connection.getTimestampUtils().toDate(cal, getString(i)); }
private LocalTime getLocalTime(int i) throws SQLException { checkResultSet(i); if (wasNullFlag) { return null; } if (isBinary(i)) { int col = i - 1; int oid = fields[col].getOID(); if (oid == Oid.TIME) { return connection.getTimestampUtils().toLocalTimeBin(this_row[col]); } else { throw new PSQLException( GT.tr("Cannot convert the column of type {0} to requested type {1}.", Oid.toString(oid), "time"), PSQLState.DATA_TYPE_MISMATCH); } } String string = getString(i); return connection.getTimestampUtils().toLocalTime(string); } //JCP! endif