Class SQLBinary

java.lang.Object
org.apache.derby.iapi.types.DataType
org.apache.derby.iapi.types.SQLBinary
All Implemented Interfaces:
Externalizable, Serializable, Comparable, Formatable, Storable, StreamStorable, TypedFormat, BitDataValue, ConcatableDataValue, DataValueDescriptor, Orderable, VariableSizeDataValue
Direct Known Subclasses:
SQLBit, SQLBlob

abstract class SQLBinary extends DataType implements BitDataValue
SQLBinary is the abstract class for the binary datatypes.
  • CHAR FOR BIT DATA
  • VARCHAR FOR BIT DATA
  • LONG VARCHAR
  • BLOB

Format :
Length is encoded to support Cloudscape 5.x databases where the length was stored as the number of bits. The first bit of the first byte indicates if the format is an old (Cloudscape 5.x) style or a new Derby style. Derby then uses the next two bits to indicate how the length is encoded.
is one of N styles.

  • (5.x format zero) 4 byte Java format integer value 0 - either is 0 bytes/bits or an unknown number of bytes.
  • (5.x format bits) 4 byte Java format integer value >0 (positive) - number of bits in raw data, number of bytes in is the minimum number of bytes required to store the number of bits.
  • (Derby format) 1 byte encoded length (0 <= L <= 31) - number of bytes of raw data - encoded = 0x80 & L
  • (Derby format) 3 byte encoded length (32 <= L < 64k) - number of bytes of raw data - encoded = 0xA0
  • (Derby format) 5 byte encoded length (64k <= L < 2G) - number of bytes of raw data - encoded = 0xC0
  • (future) to be determined L >= 2G - encoded 0xE0 (0xE0 is an esacape to allow any number of arbitary encodings in the future).

When the value was written from a byte array the Derby encoded byte length format was always used from Derby 10.0 onwards (ie. all open source versions).
When the value was written from a stream (e.g. PreparedStatement.setBinaryStream) then the Cloudscape '5.x format zero' was used by 10.0 and 10.1. The was due to the class RawToBinaryFormatStream always writing four zero bytes for the length before the data.
The Cloudscape '5.x format bits' format I think was never used by Derby.
  • Field Details

    • PAD

      static final byte PAD
      See Also:
    • BASE_MEMORY_USAGE

      private static final int BASE_MEMORY_USAGE
    • LEN_OF_BUFFER_TO_WRITE_BLOB

      private static final int LEN_OF_BUFFER_TO_WRITE_BLOB
      See Also:
    • _blobValue

      Blob _blobValue
    • dataValue

      byte[] dataValue
    • stream

      InputStream stream
      Value as a stream, this stream represents the on-disk format of the value. That is it has length information encoded in the first fe bytes.
    • streamValueLength

      int streamValueLength
      Length of the value in bytes when this value is set as a stream. Represents the length of the value itself and not the length of the stream which contains this length encoded as the first few bytes. If the value of the stream is unknown then this will be set to -1. If this value is not set as a stream then this value should be ignored.
  • Constructor Details

    • SQLBinary

      SQLBinary()
      Create a binary value set to NULL
    • SQLBinary

      SQLBinary(byte[] val)
    • SQLBinary

      SQLBinary(Blob val)
  • Method Details