Home | Previous Page | Next Page   Data Manipulation > Using Numeric Data Types > Integer Data >

Integer Binary Representations

The DataBlade API provides the following data types to support the binary representations of integer values.

Integer Data DataBlade API Data Type SQL Integer Data Type
One-byte integers mi_sint1, mi_int1 None
Two-byte integers mi_smallint, mi_unsigned_smallint SMALLINT
Four-byte integers mi_integer, mi_unsigned_integer INTEGER, SERIAL
Eight-byte integers mi_int8, mi_unsigned_int8 INT8, SERIAL8

Tip:
The internal format of integer data types is often referred to as their binary representation.

One-Byte Integers

The DataBlade API supports the following data types for one-byte integer values.

DataBlade API One-Byte Integer Description
mi_sint1 Signed one-byte (eight bits) value
mi_int1 Unsigned one-byte (eight bits) value

To hold unsigned one-byte integers, you can also use the mi_unsigned_char1 data type.

Tip:
The one-byte integer data types have names that are not consistent with those of other integer data types. The mi_int1 data type is for an unsigned one-byte integer while the mi_smallint, mi_integer, and mi_int8 data types are for the signed version of the two-, four-, and eight-byte integers, respectively. Use the mi_sint1 data type to hold a signed one-byte integer value.

The DataBlade API ensures that these integer data types are one byte on all computer architectures. There is no corresponding SQL data type for one-byte integers.

Server Only

Values of the mi_int1 and mi_sint1 data types can fit into an MI_DATUM structure. They can be passed by value within C user-defined routines (UDRs).

End of Server Only
Client Only

All data types, including mi_int1 and mi_sint1, must be passed by reference within client LIBMI applications.

End of Client Only

Two-Byte Integers

The DataBlade API supports the following data types for two-byte integer values.

DataBlade API Two-Byte Integers Description
mi_smallint Signed two-byte integer value
mi_unsigned_smallint Unsigned two-byte integer value

Use these integer data types to hold values for the SQL SMALLINT data type, which stores two-byte integer numbers that range from -32,767 to 32,767. For a description of the SQL SMALLINT data type, see the IBM Informix: Guide to SQL Reference.

The mi_smallint and mi_unsigned_smallint data types hold the internal (binary) format of a SMALLINT value. The DataBlade API ensures that the mi_smallint and mi_unsigned_smallint data types are two bytes on all computer architectures. Use these integer data types instead of the native C types (such as short int). If you access two-byte values stored in a SMALLINT in the database, but use the C short int type, conversion errors might arise if the two types are not the same size.

Important:
To make your DataBlade API module portable across different architectures, it is recommended that you use the DataBlade API data type mi_smallint for two-byte integer values instead of the native C-language counterpart. The mi_smallint data type handles the different sizes of integer values across computer architectures.
Server Only

Values of the mi_smallint and mi_unsigned_smallint data types can fit into an MI_DATUM structure. They can be passed by value within C UDRs.

End of Server Only
Client Only

All data types, including mi_smallint and mi_unsigned_smallint, must be passed by reference within client LIBMI applications.

End of Client Only

To transfer two-byte integers between different computer architectures, the DataBlade API provides the following functions that handle type alignment and byte order.

DataBlade API Function
Description
mi_get_smallint( )
Copies an aligned two-byte integer, converting any difference in alignment or byte order on the client computer to that of the server computer
mi_put_smallint( )
Copies an aligned two-byte integer, converting any difference in alignment or byte order on the server computer to that of the client computer
mi_fix_smallint( )
Converts the specified two-byte integer to or from the type alignment and byte order of the client computer

These DataBlade API functions are useful in the send and receive support functions of an opaque data type that contains mi_smallint values. They ensure that two-byte integer (SMALLINT) values remain consistent when transferred to and from client applications. For more information, see Conversion of Opaque-Type Data with Computer-Specific Data Types.

Four-Byte Integers

The DataBlade API supports the following data types for four-byte integer values.

DataBlade API Four-Byte Integers Description
mi_integer Signed four-byte integer value
mi_unsigned_integer Unsigned four-byte integer value

Use these integer data types to hold values for the following SQL four-byte integer data types:

For a description of the SQL INTEGER and SERIAL data types, see the IBM Informix: Guide to SQL Reference.

The mi_integer and mi_unsigned_integer data types hold the internal (binary) format of an INTEGER or SERIAL value. The DataBlade API ensures that the mi_integer and mi_unsigned_integer data types are four bytes on all computer architectures. Use these integer data types instead of the native C types (such as int or long int). If you access four-byte values stored in a INTEGER in the database, but use the C int type, conversion errors might arise if the two types are not the same size.

Important:
To make your DataBlade API module portable across different architectures, it is recommended that you use of the DataBlade API data type mi_integer for four-byte integer values instead of the native C-language counterpart. The mi_integer data type handles the different sizes of integer values across computer architectures.
Server Only

Values of the mi_integer and mi_unsigned_integer data types can fit into an MI_DATUM structure. They can be passed by value within a C UDR.

End of Server Only
Client Only

All data types, including mi_integer and mi_unsigned_integer, must be passed by reference within client LIBMI applications.

To transfer four-byte integers between different computer architectures, the DataBlade API provides the following functions that handle type alignment and byte order.

DataBlade API Function
Description
mi_get_integer( )
Copies an aligned four-byte integer, converting any difference in alignment or byte order on the client computer to that of the server computer
mi_put_integer( )
Copies an aligned four-byte integer, converting any difference in alignment or byte order on the server computer to that of the client computer
mi_fix_integer( )
Converts the specified four-byte integer to or from the alignment and byte order of the client computer

The mi_get_integer( ) and mi_put_integer( ) functions are useful in the send and receive support functions of an opaque data type that contains mi_integer values. They ensure that four-byte integer (INTEGER) values remain consistent when transferred to and from client applications. For more information, see Conversion of Opaque-Type Data with Computer-Specific Data Types.

End of Client Only

Eight-Byte Integers

The DataBlade API supports the following data types for eight-byte integer values.

DataBlade API Eight-Byte Integers Description
mi_int8 Signed eight-byte integer value
mi_unsigned_int8 Unsigned eight-byte integer value

The DataBlade API ensures that these integer data types are eight bytes on all computer architectures. Use these integer data types to hold values for the following SQL eight-byte integer data types:

For a description of the SQL INT8 and SERIAL8 data types, see the IBM Informix: Guide to SQL Reference.

The mi_int8 and mi_unsigned_int8 data types hold the internal (binary) format of an INT8 or SERIAL8 value.

Server Only

Values of the mi_int8 and mi_unsigned_int8 data types cannot fit into an MI_DATUM structure. They must be passed by reference within C UDRs.

End of Server Only
Client Only

All data types, including mi_int8 and mi_unsigned_int8, must be passed by reference within client LIBMI applications.

End of Client Only
The int8.h Header File

The int8.h header file contains the following declarations for use with the INT8 data type:

The mitypes.h header file automatically includes int8.h. In turn, the milib.h header file automatically includes mitypes.h, and mi.h automatically includes milib.h. Therefore, you automatically have access to the ifx_int8_t structure, the mi_int8 data type, or any of the ESQL/C INT8-type functions when you include mi.h in your DataBlade API module.

Internal INT8 Format

The INT8 data type stores eight-byte integers in an Informix-proprietary internal format: the ifx_int8_t structure. This structure allows the database to store eight-byte integers in a computer-independent format.

Tip:
The internal format of the INT8 data type is often referred to as its binary representation.

The mi_int8 data type uses the ifx_int8_t structure to hold the binary representation of an INT8 value.

Important:
The ifx_int8_t structure is an opaque C data structure to DataBlade API modules. Do not access its internal fields directly. The internal structure of ifx_int8_t may change in future releases.
ESQL/C INT8-Type Functions

Because the binary representation of an INT8 (and mi_int8) value is an Informix-proprietary format, you cannot use standard system functions to perform integer calculations on mi_int8 values. Instead, the DataBlade API provides support for the following categories of ESQL/C functions on the INT8 data type.

Type of INT8 Function More Information
Conversion functions Converting INT8 Values
Arithmetic-operation functions Performing Operations on Eight-Byte Values

Any other operations, modifications, or analyses can produce unpredictable results.

Transferring Eight-Byte Integers (Server)

To transfer eight-byte integers between different computer architectures, the DataBlade API provides the following functions that handle type alignment and byte order.

DataBlade API Function
Description
mi_get_int8( )
Copies an aligned eight-byte integer, converting any difference in alignment or byte order on the client computer to that of the server computer
mi_put_int8( )
Copies an aligned eight-byte integer, converting any difference in alignment or byte order on the server computer to that of the client computer

The mi_get_int8( ) and mi_put_int8( ) functions are useful in the send and receive support function of an opaque data type that contains mi_int8 values. They ensure that eight-byte integer (INT8) values remain aligned when transferred to and from client applications. For more information, see Conversion of Opaque-Type Data with Computer-Specific Data Types.

Converting INT8 Values

The ESQL/C library provides the following functions that facilitate conversion of the binary representation of INT8 (mi_int8) values to and from some C-language data types.

Function Name
Description
ifx_int8cvasc( )
Converts a C char type value to an mi_int8 type value
ifx_int8cvdbl( )
Converts a C double (mi_double_precision) type value to an mi_int8 type value
ifx_int8cvdec( )
Converts a C mi_decimal type value to an mi_int8 type value
ifx_int8cvflt( )
Converts a C float (mi_real) type value to an mi_int8 type value
ifx_int8cvint( )
Converts a C two-byte integer value to an mi_int8 type value
ifx_int8cvlong( )
Converts a C four-byte integer value to an mi_int8 type value
ifx_int8toasc( )
Converts an mi_int8 type value to a text string
ifx_int8todbl( )
Converts an mi_int8 type value to a C double (mi_double_precision) type value
ifx_int8todec( )
Converts an mi_int8 type value to a mi_decimal type value
ifx_int8toflt( )
Converts an mi_int8 type value to a C float (mi_real) type value
ifx_int8toint( )
Converts an mi_int8 type value to a C two-byte integer value
ifx_int8tolong( )
Converts an mi_int8 type value to a C four-byte integer value
Performing Operations on Eight-Byte Values

Use the following ESQL/C library functions to perform arithmetic operations on INT8 (mi_int8) type values.

Function Name
Description
ifx_int8add( )
Adds two mi_int8 numbers
ifx_int8cmp( )
Compares two mi_int8 numbers
ifx_int8copy( )
Copies an mi_int8 number
ifx_int8div( )
Divides two mi_int8 numbers
ifx_int8mul( )
Multiplies two mi_int8 numbers
ifx_int8sub( )
Subtracts two mi_int8 numbers

Any other operations, modifications, or analyses can produce unpredictable results.

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]