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

MI_DATUM Data Type

The DataBlade API handles a generic data value as an MI_DATUM value, also called a datum. A datum is a chunk of memory that can fit into a computer register.

In the C language, the void * type is a typeless way to point to any object and should hold any integer value. This type is usually equivalent to the long int type and is usually 4 bytes in length, depending on the computer architecture. An MI_DATUM is defined as a void * type. The MI_DATUM data type is guaranteed to be the size of the C type void * on all computer architectures.

On 64-bit platforms, void * is 8 bytes in length. Therefore, MI_DATUM is stored in 8 bytes. However, the 4-byte MI_DATUM is put into the appropriate 4 bytes of the 8-byte void *.

This section provides the following information about the MI_DATUM data type:

The MI_DATUM Value

A datum can describe any SQL data type; it is used to transport an SQL data type between the database server and the DataBlade API module.

MI_DATUM in a C UDR

In a C UDR, the content of an MI_DATUM depends on the data type of the value, as follows:

For all data types listed in Figure 2-18, the DataBlade API passes the value in an MI_DATUM by value unless the variable is declared as pass by reference. For example, in the following sample function signature, the arg2 variable would be passed by reference to the my_func() UDR because it is declared as a pointer:

Data types with sizes smaller than or equal to the size of void* can be passed by value because they can fit into the MI_DATUM. However, passed-by-value data types that are smaller than the size of MI_DATUM are cast promoted to the MI_DATUM size with whatever byte position is appropriate for the computer architecture. When you obtain the smaller passed-by-value data type from an MI_DATUM, you need to reverse the cast promotion to assure that your value is correct.

For example, an mi_boolean value is a 1-byte value. To pass it by value, the DataBlade API performs something like the following example when it puts the mi_boolean into an MI_DATUM:

In the preceding cast promotion, datum is an MI_DATUM and bool is an mi_boolean.

When you obtain the mi_boolean value from the MI_DATUM, reverse the cast-promotion process with something like the following example:

To avoid the cast promotion situation, Informix recommends that you declare small by-value SQL types as an mi_integer.

For all data types not listed in Figure 2-18, the DataBlade API passes the value in an MI_DATUM by reference; that is, the MI_DATUM contains a pointer to the actual data type.

Warning: Do not assume that any data type of length 1, 2, or 4 is passed by value. Not all 1-, 2-, or 4-byte datums are passed by value. For example, the mi_real data type is passed by reference. Always check the data type or use the mi_type_byvalue() function to determine the passing mechanism.

User-defined routines store the data types of their arguments in the MI_FPARAM structure. You can check the type identifier of an argument to determine if it is passed by value or by reference, as the following code fragment shows:

MI_DATUM In a Client LIBMI Application

The preceding rules for passing values by reference and by value in MI_DATUM do not apply to client LIBMI applications. In client LIBMI applications, pass all data types in MI_DATUM by reference.

Uses of an MI_DATUM

An MI_DATUM value holds a value that is transferred to or from the database server. DataBlade API functions handle an MI_DATUM consistently. The following table shows examples of the use of MI_DATUM values.

Use of MI_DATUM Description For More Information
Routine arguments to a UDR When a user-defined routine is called, the routine manager passes UDR arguments as datums. The argument data type determines whether the routine manager passes the argument by reference or by value. For MI_DATUM Arguments
Return value from a user-defined function When a user-defined function exits, the routine manager passes the return value as a datum. The return-value data type determines whether the routine manager passes the return value by reference or by value. Returning a Value
OUT parameter from a user-defined
function
When a user-defined function sets an OUT parameter, the routine manager passes the parameter back as a datum. However, the routine manager always passes the parameter by reference. Using an OUT Parameter
Routine arguments to a UDR that is executed with the Fastpath interface When you execute a UDR with the Fastpath interface, the mi_routine_exec() function passes UDR arguments as datums. The argument data type determines whether this function expects the argument passed by reference or by value. Passing in Argument Values
Return value from a UDR that is executed with the Fastpath interface When a user-defined function that you execute with the Fastpath interface returns, the mi_routine_exec() function passes the return value as a datum. The return-value data type determines whether this function passes the return value by reference or by value. Receiving the Return Value
Column values returned or inserted in SQL statements When the mi_value() or mi_value_by_name() function returns a column value for a query in binary representation, it returns this value as a datum. When the mi_row_create() function creates a row structure, it accepts column values as datums. Obtaining Column Values
Element values retrieved or inserted in SQL collections When the mi_collection_fetch() function fetches an element from a collection, it represents the element as a datum. When the mi_collection_insert() function inserts an element from a collection, it represents the element as a datum. Accessing Elements of a Collection
Input-parameter values in a prepared SQL statement When the mi_exec_prepared_statement() or mi_open_prepared_statement() function provides input-parameter values, it represents them as datums. Assigning Values to Input Parameters


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