informix
Informix DataBlade API Programmer's Manual
Accessing SQL Data Types

SQL Data Types

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:

Type Identifiers

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.

Type-Identifier Check DataBlade API Function
Are two type identifiers equal? mi_typeid_equals()
Does the type identifier represent a built-in data type: mi_typeid_is_builtin()
Does the type identifier represent a collection (SET, MULTISET, LIST) data type? mi_typeid_is_collection()
Does the type identifier represent a complex data type? mi_typeid_is_complex()
Does the type identifier represent a distinct data type? mi_typeid_is_distinct()
Does the type identifier represent a LIST data type? mi_typeid_is_list()
Does the type identifier represent a MULTISET data type? mi_typeid_is_multiset()
Does the type identifier represent a row type (named or unnamed)? mi_typeid_is_row()
Does the type identifier represent a SET data type? mi_typeid_is_set()

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.

Type Identifier Usage DataBlade API Function For More Information
To indicate a column type in a row descriptor mi_column_type_id() Obtaining Column Information
To indicate data type of arguments in a UDR mi_fp_argtype(), mi_fp_setargtype() Determining the Data Type of UDR Arguments
To indicate data type of return type of a UDR mi_fp_rettype(), mi_fp_setrettype() Determining the Data Type of UDR Return Values
To indicate data type of a column with which an input parameter in a prepared statement is associated mi_parameter_type_id() Obtaining Input-Parameter Information
To identify a user-defined routine by the data types of its arguments to generate its function descriptor mi_routine_get_by_typeid() Looking Up User-Defined Routines
To identify a cast function by the source and target data types to generate its function descriptor mi_cast_get() Looking Up Cast Functions
To identify the element type of a collection mi_collection_create() Creating a Collection

Type Descriptors

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
Data Type Information in a Type Descriptor

Data Type Information DataBlade API
Accessor Function
The alignment, in number of bytes, of the data type mi_type_align()
Whether the data type is passed by reference or by value mi_type_byvalue()
A type descriptor for the element type of a collection data type mi_type_element_typedesc()
The full name (owner.type_name) of the data type mi_type_full_name()
The length of the data type mi_type_length()
The maximum length of the data type mi_type_maxlength()
The owner of the data type mi_type_owner()
The precision (total number of digits) of the data type mi_type_precision()
The qualifier of a DATETIME or INTERVAL data type mi_type_qualifier()
The scale of a data type mi_type_scale()
The short name (no owner) of the data type mi_type_typename()
The type identifier for the data type mi_typedesc_typeid()

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.

Type Descriptor Usage For More Information
To indicate a column type in a row descriptor mi_column_typedesc() Obtaining Column Information
To obtain the source type of a distinct type mi_get_type_source_type()
To process returned row data, especially when not all the rows returned by a query have the same size and structure mi_get_row_desc_from_type_desc()
To identify a cast function by the source and target data types to generate its function descriptor mi_td_cast_get() Looking Up Cast Functions

Type-Structure Conversion

You can use the following DataBlade API functions to obtain a type descriptor or type identifier.

Convert From Convert To DataBlade API Function
Type identifier Type descriptor mi_type_typedesc()
Type descriptor Type identifier mi_typedesc_typeid()
Type name (as mi_lvarchar) Type identifier mi_typename_to_id()
Type name (as mi_lvarchar) Type descriptor mi_typename_to_typedesc()
Type name (as string: char *) Type identifier mi_typestring_to_id()
Type name (as string: char *) Type descriptor mi_typestring_to_typedesc()

Data Type Descriptors and Column Type Descriptors

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-2
Sample Named Row Type With Parameterized Fields

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.

Figure 2-3
Type Descriptor and Column Type Descriptor for DATETIME field

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.

Figure 2-4
Type Descriptor and Column Type Descriptor for DECIMAL field

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:


Informix DataBlade API Programmer's Manual, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved