Binary Data Types

Binary data types can either be fixed width or variable length. For storing binary data larger than this maximum, use a BLOB data type (see BLOB/CLOB Types).

Data Type Size Size (Not Null) Synonyms
BINARY(length_num) (length_num) + 1 length_num  
VARBINARY(length_num) length_num + 3 length_num + 2 BINARY VARYING

Fixed Width Binary String

Example 1

create table component (
    id rowid primary key,
    name char(80),
    image binary(32)
);

Snippet from the generated C structure from rdm-compile tool using --c-structs option.

/** \brief struct definition for table COMPONENT */
typedef struct COMPONENT_S
{
    RDM_ROWID_T ID;
    char NAME[321];
    uint8_t REGISTER[32];
    RDM_HAS_VALUE_T _NAME_has_value;
    RDM_HAS_VALUE_T _REGISTER_has_value;
} COMPONENT;

The above example shows the binary column has been generated internally as an array of unsigned 8-bit integers (unsigned char) with a length of 32 bytes. Since the schema did not declare that the field could be NOT NULL, another boolean structure member, _REGISTER_has_value, has been created to signal whether the REGISTER column has been populated or not.

Example 2

create table component (
    id rowid primary key,
    name char(80) not null,
    register binary(32) not null
);

Snippet from the generated C structure from rdm-compile tool using --c-structs option.

/** \brief struct definition for table COMPONENT */
typedef struct COMPONENT_S
{
    RDM_ROWID_T ID;
    char NAME[321];
    uint8_t REGISTER[32];
} COMPONENT;

The above example is the same as Example 1 but shows the effect of the NOT NULL declaration with the C structure. With the above, the system assumes that the contents of the REGISTER column has been filled.

Variable Width Binary String

Example 1

create table component (
    id rowid primary key,
    name char(80),
    sample varbinary(10000)
);

Snippet from the generated C structure from rdm-compile tool using --c-structs option.

/** \brief struct definition for table COMPONENT */
typedef struct COMPONENT_S
{
    RDM_ROWID_T ID;
    char NAME[321];
    struct
    {
        uint16_t len;
        uint8_t data[10000];
    } SAMPLE;
    RDM_HAS_VALUE_T _NAME_has_value;
    RDM_HAS_VALUE_T _SAMPLE_has_value;
} COMPONENT;

The above example shows the binary SAMPLE column has been generated internally as an array of unsigned 8-bit integers (unsigned char) with a length of 32 bytes. Since the schema did not declare that the field could be NOT NULL, another boolean structure member, _REGISTER_has_value, has been created to signal whether the REGISTER column has been populated or not. Please refer to the NULL Values section for a more complete description.

See Also

NULL Values

DEFAULT Values

Limitations