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 - 32,767.

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.

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.

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

To transfer two-byte integers between different computer architectures, the DataBlade® API provides the following functions that handle type alignment and byte order.
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.