informix
INFORMIX-ESQL/C Programmer's Manual
Working with Numeric Data Types

The Integer Data Types

The database server supports the following data types for integer values.

SQL Integer Data Type Number of Bytes Range of Values
SMALLINT 2 -32767 to 32767
INTEGER, INT,
SERIAL
4 -2,147,483,647 to 2,147,483,647
INT8, SERIAL8 8 -9,223,372,036,854,775,807 to
9,223,372,036,854,775,807

The C language supports the short int and long int data types for integers. The size of these C integer data types depends on the hardware and operating system of the computer you use. For example, a long data type could be 4 bytes long on a 32-bit platform but 8 bytes long on a 64-bit platform.

Therefore, when you declare an integer host variable, you must ensure that this host variable is large enough for all possible values of the SQL integer data type with which the variable is associated. For more information about how to implement integer data types on your system, check with your system administrator or your C documentation.

The Integer Host Variable Types

Informix provides the following data types for specifying integer host variables of specific lengths.

Data Type Length
int1 One-byte integer
int2 Two-byte integer
int4 Four byte integer
mint Native integer data type for the machine
mlong Native long integer data type for the machine
MSHORT Native short integer data type for the machine
MCHAR Native char data type for the machine

Warning: The preceding integer data types are reserved. Your programs must not use typedef or $typedef statements to define these data types.

The integer host variable data types are defined in the ifxtypes.h file, which is automatically included in your program when you compile it with the esql script.

Important: Many of the INFORMIX-ESQL/C library functions have been changed to declare the Informix integer data types rather than the machine specific types such as int, short, and long. Informix recommends that you use the Informix integer types when you call ESQL/C library functions.

The INT8 and SERIAL8 SQL Data Types

ESQL/C supports the SQL INT8 and SERIAL8 data types with the int8 data type. The int8 data type is a machine-independent method that represents numbers in the range -(263 -1) to 263-1.

For a complete description of the INT8 and SERIAL8 SQL data types, see the Informix Guide to SQL: Reference. This section describes how to manipulate the ESQL/C data type, int8.

The int8 Data Type

Use the ESQL/C int8 data type to declare host variables for database values of type INT8 and SERIAL8. Figure 5-1 shows the fields of the structure ifx_int8_t, which represents an INT8 or SERIAL8 value.

Figure 5-1
Fields of the ifx_int8_t Structure

Field Name Field Type Purpose
data unsigned 4-byte
integer
[INT8SIZE]
An array of integer values that make up the 8-byte integer value. When the INT8SIZE constant is defined as 2, this array contains two unsigned 4-byte integers. The actual data type of an unsigned 4-byte integer can be machine specific.
sign short integer A short integer to hold the sign (null, negative, or positive) of the 8-byte integer. The actual data type of a 2-byte integer can be machine specific.

The int8.h header file contains the ifx_int8 structure and a typedef called ifx_int8_t. Include this file in all C source files that use any int8 host variables as shown in the following example:

You can declare an int8 host variable in either of the following ways:

The int8 Library Functions

You must perform all operations on int8 type numbers through the ESQL/C library functions for the int8 data type. Any other operations, modifications, or analyses can produce unpredictable results. The ESQL/C library provides functions that allow you to manipulate int8 numbers and convert int8 type numbers to and from other data types. The following table describes these functions.

Function Name Description Page Reference
Manipulation Functions
ifx_getserial8() Returns an inserted SERIAL8 value B-113
ifx_int8add() Adds two int8 numbers B-116
ifx_int8cmp() Compares two int8 numbers B-119
ifx_int8copy() Copies an int8 number B-121
ifx_int8div() Divides two int8 numbers B-135
ifx_int8mul() Multiplies two int8 numbers B-137
ifx_int8sub() Subtracts two int8 numbers B-139
Type Conversion Functions
ifx_int8cvasc() Converts a C char type value to an int8 type value B-124
ifx_int8cvdbl() Converts a C double type value to an int8 type value B-124
ifx_int8cvdec() Converts a C decimal type value to a int8 type value B-126
ifx_int8cvflt() Converts a C float type value to an int8 type value B-129
ifx_int8cvint() Converts a C int type value to an int8 type value B-131
ifx_int8cvlong() Converts a C 4-byte integer type value to an int8 type value B-133
ifx_int8toasc() Converts an int8 type value to a text string B-142
ifx_int8todbl() Converts an int8 type value to a C double type value B-146
ifx_int8todec() Converts aint8 type value to a decimal type value B-149
ifx_int8toflt() Converts an int8 type value to a C float type value B-153
ifx_int8toint() Converts an int8 type value to a C int type value B-156
ifx_int8tolong() Converts an int8 type value to a C 4-byte integer type value B-159

For information on the syntax and behavior of these library functions, refer to Appendix B, ESQL/C Function Library.


INFORMIX-ESQL/C Programmer's Manual, Version 9.21
Copyright © 1999, Informix Software, Inc. All rights reserved