The import support function
When a bulk-copy utility performs a load of opaque-type data in its external unload representation, the database server calls the import support function. For example, when performs a bulk load of an opaque-type column with the LOAD statement, the database server calls the import support function for the opaque type.
Function signature
srvr_internal_rep import(external_unload_rep)
mi_impexp *external_unload_rep;
- external_unload_rep
- A pointer to an mi_impexp structure that holds the external
unload representation of the opaque type.
An mi_impexp is always passed by reference. Therefore, the external_unload_rep argument must always be a pointer to the mi_impexp data type. For information about how to obtain information from this varying-length structure, see Information about varying-length data.
- import
- The name of the C-language function that implements the import support function for the opaque type. It is recommended that you include the name of the opaque type in its import function.
- srvr_internal_rep
- The appropriate format for the server internal representation of the opaque data type. The passing mechanism of this return value depends on the kind of opaque type, as Figure 1 through Figure 3 show. Most opaque types are passed by reference.
Sample code fragments
/* Import support function: circle */
circle_t *circle_imp(extrnl_unload_rep)
mi_impexp *extrnl_unload_rep;
{
return (circle_input((mi_lvarchar *)extrnl_unload_rep));
}
The circle_imp() function is a cast function from the mi_impexp data type (which contains the external unload representation for the circle opaque type) to the circle_t internal representation (on the server computer). The database server executes circle_imp() when it needs a cast function to convert from the SQL data type IMPEXP to the server internal representation of the circle opaque type. For more information, see Support functions as casts.
The circle_imp() function returns a pointer to the circle_t data type. Because circle cannot fit into an MI_DATUM structure, it must be passed by reference. If your fixed-length opaque type can fit into an MI_DATUM structure, the import support function can return the server internal representation by value.
/* Import support function: two_bytes */
two_bytes_t two_bytes_imp(extrnl_unload_rep)
mi_impexp *extrnl_unload_rep;
{
return ( two_bytes_input( (mi_lvarchar *)extrnl_unload_rep) );
}
The two_bytes opaque type must be registered as PASSEDBYVALUE to tell the database server that it can be passed by value.
/* Import support function: image */
mi_lvarchar *image_imp(extrnl_unload_rep)
mi_impexp *extrnl_unload_rep;
Usage
The image opaque type stores its data inside an mi_lvarchar structure, which must be passed by reference. The image_imp() function is a cast function from the mi_impexp data type (which contains the external unload representation of image) to the mi_lvarchar data type (which contains the server internal representation of image).
- Open the specified client file.
- Load the data from the client file into a new smart large object, starting at the specified offset, and ending when the specified length is reached.
Function tasks
- Accepts as an argument a pointer to the external unload representation
of the opaque type
The external unload representation is in the data portion of an mi_impbin structure, which is passed by reference.
- Allocates enough space to hold the server internal representation
of the opaque type
The import function can use the mi_alloc() DataBlade API function to allocate the space for the internal representation. For more information about memory management, see Manage user memory.
- Parses the input string of the external unload representation
Obtain the individual members from the input string and store them into the appropriate fields of the server internal representation. The DataBlade API provides functions to convert various DataBlade API data types from their external to internal representations. For example, to convert a date string in an external unload representation to its internal representation (the mi_date value in the image_t structure), the image_imp() function can call the mi_string_to_date() function. For a list of these DataBlade API functions, see Conversion of opaque-type data between text and binary representations.
- Returns the appropriate server internal representation for the
opaque type
If the opaque data type is passed by reference, the import function returns a pointer to the server internal representation. If the opaque data type is passed by value, the import function returns the actual value of the internal representation instead of a pointer to this representation. For more information, see Determine the passing mechanism for an opaque type.
Because the image opaque type contains a smart large object, it would require an import function. From the external unload representation that is read from the copy file, the import function can obtain the name of the client file that contains the smart-large-object data.