The import and export support functions perform any tasks needed to process external text representation of an opaque type for a bulk load and unload. When the database server copies data to or from a database in external text format, it calls the following support functions for every value copied to or from the copy file:
These support functions do not have to be named import and export, but they do have to perform the specified conversions. They should be reciprocal functions; that is, the import function should produce a value that the export function accepts as an argument and vice versa.
The import and export functions can take special actions on the values before they are copied. Typically, only opaque data types that contain smart large objects have import and export functions defined for them. For example, the export function for such a data type might create a file on the client computer, write the smart-large-object data from the database to this file, and send the name of the client file as the data to store in the copy file. Similarly, the import function for such a data type might take the client filename from the copy file, open the client file, and load the large-object data from the copy file into the database. The advantage of this design is that the smart-large-object data does not appear in the copy file; therefore, the copy file grows more slowly and is easier for users to read.
For small opaque data types, you do not usually need to define the import and export support functions. If you do not define import and export support functions, the database server uses the input and output functions, respectively, when it performs bulk copies.
For large opaque data types, the data that the input and output functions generate might be too large to fit in the file or might not represent all of the data in the object. To resolve this problem, you can use the import functions filetoclob() and filetoblob() and the export function lotofile().
SQL statements support an internal data type called IMPEXP to hold the external representation of an opaque data type for a bulk copy. The IMPEXP data type allows for any possible change in the size of the data when it is converted between the two representations. The import and export support functions serve as cast functions between the IMPEXP and opaque data type.
The import support function takes as an argument the structure that holds the bulk-copy format of the external representation of the user-defined type and returns the internal structure for the user-defined type.
Any files that the import function reads must reside on the database server computer. If you do not provide an import support function, the database server uses the input support function to import text data.
The following function signature is for an import support function of an opaque data type whose internal structure is ll_longlong_t:
ll_longlong_t * ll_longlong_import(mi_impexp *extrnl_bcopy_format);
The ll_longlong_import() function is a cast function from the IMPEXP data type to the ll_longlong_t data structure. It must be registered as an implicit cast function with the CREATE IMPLICIT CAST statement. For more information on cast functions, see Creating Casts for Opaque Data Types.
The export function takes as an argument the internal structure for the opaque type and a structure that holds the bulk-copy format of the external representation of the opaque type.
If you do not provide an export support function, the database server uses the output support function to export text data.
The following function signature is for an export support function of an opaque data type whose internal structure is ll_longlong_t:
mi_impexp * ll_longlong_export(ll_long_t *intrnl_bcopy_format);
The ll_longlong_export() function is a cast function from the ll_longlong_t internal structure to the IMPEXP data type. It must be registered as an explicit cast function with the CREATE EXPLICIT CAST statement. For more information on cast functions, see Creating Casts for Opaque Data Types.