Varying-length opaque data type
If the C structure that holds your opaque type can vary in size depending on the data it holds, you must declare the opaque type as a varying-length opaque type.
The opaque type can contain character strings. Each instance of the opaque type can contain a character string with a different size. When you define the internal representation of a varying-length opaque, make sure that only the last member of the C structure is of varying size.
typedef struct
{
mi_integer img_id;
mi_integer img_thresh_trck;
mi_integer img_thresh;
mi_date img_date;
mi_integer img_flags;
mi_lvarchar img_data;
} image_t;
You tell the database server that an opaque type is varying length when you register the opaque type. In the CREATE OPAQUE TYPE statement, you must include the INTERNALLENGTH modifier with the VARIABLE keyword.
CREATE OPAQUE TYPE image
(INTERNALLENGTH = VARIABLE);
The database server stores the value of the INTERNALLENGTH modifier in the length column of the sysxtdtypes system catalog table. For varying-length opaque types, this column holds a value of zero.
- By default, the maximum size for a varying-length opaque type is two kilobytes.
- You specify a different maximum size for a varying-length opaque
type when you register the opaque type.
In the CREATE OPAQUE TYPE statement, use the MAXLEN modifier. You can specify a maximum length of up to 32 kilobytes. The database server stores the value of the MAXLEN modifier in the maxlen column of the sysxtdtypes system catalog table.
CREATE OPAQUE TYPE var_type
(INTERNALLENGTH=VARIABLE, MAXLEN=4096);
Because the database server uses mi_lvarchar to transfer varying-length data, the passing mechanism for a varying-length opaque type is always by reference. For more information, see Determine the passing mechanism for an opaque type.