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.