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:
- The SQL INTEGER data type can hold integer values in the range -2,147,483,647 - 2,147,483,647.
- The SQL SERIAL data type holds four-byte integer values that the database server automatically assigns when a value is inserted in the column.
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.
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.
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.
- 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.