Determining equivalent SQL and C or C++ data types

The precompiler determines the base SQLTYPE and SQLLEN of host variables based on the table. If a host variable appears with an indicator variable, the SQLTYPE is the base SQLTYPE plus one.

Table 1. C or C++ declarations mapped to typical SQL data types
C or C++ data type SQLTYPE of host variable SQLLEN of host variable SQL data type
short int 500 2 SMALLINT
long int 496 4 INTEGER
long long int 492 8 BIGINT
decimal(p,s) 484 p in byte 1, s in byte 2 DECIMAL (p,s)
_Decimal32 996 4 Treated as DECFLOAT(7) although SQL does not directly support this data type.
_Decimal64 996 8 DECFLOAT(16)
_Decimal128 996 16 DECFLOAT(34)
float 480 4 FLOAT (single precision)
double 480 8 FLOAT (double precision)
single-character form 452 1 CHAR(1)
NUL-terminated character form 460 length VARCHAR (length - 1)
VARCHAR structured form 448 length VARCHAR (length)
single-graphic form 468 1 GRAPHIC(1)
NUL-terminated single-graphic form 400 length VARGRAPHIC (length - 1)
VARGRAPHIC structured form 464 length VARGRAPHIC (length)

You can use the following table to determine the C or C++ data type that is equivalent to a given SQL data type.

Table 2. SQL data types mapped to typical C or C++ declarations
SQL data type C or C++ data type Notes
SMALLINT short int  
INTEGER long int  
BIGINT long long int  
DECIMAL(p,s) decimal(p,s) p is a positive integer from 1 to 63, and s is a positive integer from 0 to 63.
NUMERIC(p,s) or nonzero scale binary No exact equivalent Use DECIMAL (p,s).
DECFLOAT(16) _Decimal64 Only supported in C.
DECFLOAT(34) _Decimal128 Only supported in C.
FLOAT (single precision) float  
FLOAT (double precision) double  
CHAR(1) single-character form  
CHAR(n) No exact equivalent If n>1, use NUL-terminated character form.
VARCHAR(n) NUL-terminated character form Allow at least n+1 to accommodate the NUL-terminator. If data can contain character NULs (/0), use VARCHAR structured form or SQL VARCHAR.

n is a positive integer. The maximum value of n is 32740.

VARCHAR structured form The maximum value of n is 32740. The SQL VARCHAR form may also be used.
CLOB None Use SQL TYPE IS to declare a CLOB in C or C++.
GRAPHIC (1) single-graphic form  
GRAPHIC (n) No exact equivalent  
VARGRAPHIC(n) NUL-terminated graphic form If n > 1, use NUL-terminated graphic form.
VARGRAPHIC structured form If data can contain graphic NUL values (/0/0), use VARGRAPHIC structured form. Allow at least n + 1 to accommodate the NUL-terminator.

n is a positive integer. The maximum value of n is 16370.

DBCLOB None Use SQL TYPE IS to declare a DBCLOB in C or C++.
BINARY None Use SQL TYPE IS to declare a BINARY in C or C++.
VARBINARY None Use SQL TYPE IS to declare a VARBINARY in C or C++.
BLOB None Use SQL TYPE IS to declare a BLOB in C or C++.
DATE NUL-terminated character form If the format is *USA, *ISO, *JIS, or *EUR, allow at least 11 characters to accommodate the NUL-terminator. If the format is *MDY, *YMD, or *DMY, allow at least 9 characters to accommodate the NUL-terminator. If the format is *JUL, allow at least 7 characters to accommodate the NUL-terminator.
VARCHAR structured form If the format is *USA, *ISO, *JIS, or *EUR, allow at least 10 characters. If the format is *MDY, *YMD, or *DMY, allow at least 8 characters. If the format is *JUL, allow at least 6 characters.
TIME NUL-terminated character form Allow at least 7 characters (9 to include seconds) to accommodate the NUL-terminator.
VARCHAR structured form Allow at least 6 characters; 8 to include seconds.
TIMESTAMP NUL-terminated character form Allow at least 20 characters (33 to include all fractional seconds) to accommodate the NUL-terminator. If n is less than 33, truncation occurs on the fractional seconds part.
VARCHAR structured form Allow at least 19 characters. To include all fractional seconds, allow 32 characters. If the number of characters is less than 32, truncation occurs on the fractional seconds part.
XML None Use SQL TYPE IS to declare XML in C or C++.
DATALINK Not supported  
ROWID None Use SQL TYPE IS to declare a ROWID in C or C++.
Result set locator None Use SQL TYPE IS to declare a result set locator in C or C++.