Text file import and export functions
The text file import function transfers a flat file to the text representation of the opaque data type. The C name of the text file import function for each opaque data type is OpaqueImportText(). The text file export function transfers the text representation of the opaque data type to a flat file. The C name of the text file export function for each opaque data type is OpaqueExportText().
BladeSmith generates complete C code for these functions.
The generated code
The database server calls the text file import function with a pointer to an mi_impexp type containing the input text, which it retrieves from an external file, and an unused MI_FPARAM pointer. The text file import function converts the text to an instance of the opaque type and returns a pointer to it.
The text file import function allocates memory for the opaque structure that it returns and then calls Gen_sscanf() for each member of the structure, storing the scanned values in the allocated memory.
The database server calls the text file export function with a pointer to an instance of the opaque type and an unused MI_FPARAM pointer. The text file export function converts the opaque type value to a text value stored in an mi_lvarchar variable that it allocates. The generated code works the same way as the text output function.
The text file export function computes the maximum length of the text value it can return by adding the maximum lengths for each structure member. Then it calls mi_new_var() to allocate an mi_impexp argument large enough to hold the largest possible text value.
To create the output text, the function calls sprintf() once for each member of the opaque type structure, concatenating a text representation of the value to the string in the mi_impexp variable. Each value is followed by a space.
The default text file export function uses the same text representation as the input and import functions. This format allows database users to enter values for the opaque type and enables opaque types to be displayed. For bulk copy operations, however, a user-readable format is not necessary.
Customize the code
The default format for imported text is the same as for the text input function: a string containing each structure member, delimited with spaces. If you use a different text representation for your data type, you can modify the format strings in the Gen_sscanf() calls.
To conserve space in the external file or to match the representation required by some another application that uses the export file, you can use a different text representation for bulk copy. When you modify the text representation that the text file export function uses for copy-out operations, make corresponding modifications in the text file import function.
Smart large object considerations
If the data type contains the smart large object handle data type MI_LO_HANDLE, the input contains the large object file name in double quotation marks.
The text file import function calls Gen_LoadLOFromFile() to retrieve the smart large object data from the external file. The text file export function calls Gen_StoreLOToFile() to save the smart large object in an external file.