Support functions as casts
The internal (binary) representation of an opaque type is a C structure that encapsulates the opaque-type information. The database server does not know about the structure of this internal representation. To be able to transfer opaque-type data to various locations, the database server assumes that cast functions exist between the internal representation of the opaque type (which the database server does not know) and some known representation of the opaque-type data.
Many of the opaque-type support functions serve as casts between some known representation of opaque-type data and the internal representation of the opaque type. Each known representation of an opaque type has an associated SQL data type, which you use when you register the support function. Each of these SQL data types has a corresponding DataBlade® API data type, which you use when you declare the C function that implements the support function. The following table shows the opaque-type representations and the corresponding SQL and DataBlade® API data types that implement them.
Opaque-type representation | SQL data type | DataBlade® API data type | Opaque-type support functions |
---|---|---|---|
External (text) representation | LVARCHAR | mi_lvarchar | input, output |
External binary representation on the client | SENDRECV | mi_sendrecv | receive, send |
Text load file representation | IMPEXP | mi_impexp | import, export |
Binary load file representation | IMPEXPBIN | mi_impexpbin | importbin, exportbin |
Cast from | Cast to | Opaque-type support functions |
---|---|---|
LVARCHAR | opaque data type | input |
SENDRECV | opaque data type | receive |
IMPEXP | opaque data type | import |
IMPEXPBIN | opaque data type | importbin |
circle_t *circle_input(external_rep)
mi_lvarchar *external_rep;
Cast from | Cast to | Opaque-type support function |
---|---|---|
opaque data type | LVARCHAR | output |
opaque data type | SENDRECV | send |
opaque data type | IMPEXP | export |
opaque data type | IMPEXPBIN | exportbin |
The DataBlade® API data types in SQL and DataBlade API data types for opaque-type representations are all implemented as varying-length structures. Therefore, all these data types have the same internal format. Any DataBlade® API function that is declared to handle the mi_lvarchar data type can also handle these other varying-length data types. However, you might need to cast between these types to avoid compilation warnings. If you are using a varying-length data type other than mi_lvarchar, you can cast between the varying-length type you are using and mi_lvarchar.
mi_impexp *new_impexp;
...
new_impexp = (mi_impexp *)mi_string_to_lvarchar(strng);
This casting is not strictly required, but many compilers recommend it and it does improve clarity of purpose.
Any size of data can fit into a varying-length structure. When a varying-length data type holds a value for an opaque-type column, this two-kilobyte size restriction for LVARCHAR columns does not apply. You can write the appropriate support functions of the opaque data type to handle more than two kilobytes. For more information about how to manage these varying-length structures, see Varying-length data type structures.
Opaque-type support functions | Description | More information |
---|---|---|
input, output |
|
The input and output support functions |
send, receive |
|
The send and receive support functions |
import, export |
|
External unload representation |
importbin, exportbin |
|
Internal unload representation |