|
Figure 1-1 on page 1-11 lists the correspondences between SQL and DataBlade API data types. To declare a variable for an SQL data type, use the appropriate DataBlade API predefined data type or structure for the variable. The mi.h header file includes the header files for the definitions of all DataBlade API data types. Include mi.h in all DataBlade API modules that use DataBlade API data types.
The DataBlade API represents the SQL data type of a column value with the following data structures:
A type identifier, MI_TYPEID, is a DataBlade API structure that identifies a data type uniquely. For extended data types, the type identifier is database-dependent; that is, the same type identifier might identify different data types for different databases. You can determine the data type that a type identifier represents with the following DataBlade API functions.
Important: To a DataBlade API module, the type identifier (MI_TYPEID) is an opaque C data structure. Do not access its internal fields directly. Informix does not guarantee that the internal structure of a type identifier will not change in future releases. Therefore, to create portable code, always use the accessor functions for this structure to determine data type.
The DataBlade API uses type identifiers in the following situations.
A type descriptor, MI_TYPE_DESC, is a DataBlade API structure that contains information about an SQL data type. For built-in data types, this information comes from the syscolumns table. For extended data types, it contains the information in the sysxtdtypes table. Figure 2-1 lists the DataBlade API accessor functions that obtain information from a type descriptor.
Figure 2-1
Important: To a DataBlade API module, the type descriptor (MI_TYPE_DESC) is an opaque C structure. Do not access its internal fields directly. Informix does not guarantee that the internal structure of MI_TYPE_DESC will not change in future releases. Therefore, to create portable code, always use the accessor functions in Figure 2-1 to obtain values from this structure.
The DataBlade API uses type descriptors in the following situations.
You can use the following DataBlade API functions to obtain a type descriptor or type identifier.
A type descriptor for a data type and one for a column use the same accessor functions and share the same underlying data structures. However, these descriptors differ in the handling of parameterized data types (such as DATETIME, INTERVAL, DECIMAL, and money) as follows:
When you use type-descriptor accessor functions (see Figure 2-1 on page 2-6) on parameterized data types, the results depend on which kind of type descriptor you pass into the accessor function.
For example, Figure 2-2 shows a named row type with fields that have parameterized data types.
Figure 2-3 shows a code fragment that obtains a data type descriptor and a column type descriptor for the first field (time_fld) from the row descriptor (row_desc) for the row_type row type.
For the DATETIME data type of the time_fld column, the type-descriptor accessor functions obtain different qualifier information for each kind of type descriptor, as follows:
Similarly, for DECIMAL and MONEY data types, the type-descriptor accessor functions can obtain scale and precision information from a column type descriptor but not a data type descriptor. Figure 2-4 shows a code fragment that obtains a data type descriptor and a column type descriptor for the second field (dec_fld) from the row descriptor (row_desc) for the row_type row type.
For the DECIMAL data type of the dec_fld column, the results from the type-descriptor accessor functions depend on which type descriptor you pass into the accessor function, as follows: