C host variable types

Only a limited number of C data types are supported as host variables. Also, certain host variable types do not have a corresponding C type.

Macros defined in the sqlca.h header file can be used to declare host variables of the following types: NCHAR, VARCHAR, NVARCHAR, LONGVARCHAR, LONGNVARCHAR, BINARY, LONGBINARY, DECIMAL, DT_FIXCHAR, DT_NFIXCHAR, DATETIME (SQLDATETIME), BIT, BIGINT, or UNSIGNED BIGINT. They are used as follows:



EXEC SQL BEGIN DECLARE SECTION;
DECL_NCHAR                 v_nchar[10];
DECL_VARCHAR( 10 )         v_varchar;
DECL_NVARCHAR( 10 )        v_nvarchar;
DECL_LONGVARCHAR( 32768 )  v_longvarchar;
DECL_LONGNVARCHAR( 32768 ) v_longnvarchar;
DECL_BINARY( 4000 )        v_binary;
DECL_LONGBINARY( 128000 )  v_longbinary;
DECL_DECIMAL( 30, 6 )      v_decimal;
DECL_FIXCHAR( 10 )         v_fixchar;
DECL_NFIXCHAR( 10 )        v_nfixchar;
DECL_DATETIME              v_datetime;
DECL_BIT                   v_bit;
DECL_BIGINT                v_bigint;
DECL_UNSIGNED_BIGINT       v_ubigint;
EXEC SQL END DECLARE SECTION;

The preprocessor recognizes these macros within an embedded SQL declaration section and treats the variable as the appropriate type. It is recommended that the DECIMAL (DT_DECIMAL, DECL_DECIMAL) type not be used since the format of decimal numbers is proprietary.

The following table lists the C variable types that are allowed for host variables and their corresponding embedded SQL interface data types.

C data type Embedded SQL interface type Description
short              si;
short int          si;
DT_SMALLINT 16-bit signed integer.
unsigned short int usi;
DT_UNSSMALLINT 16-bit unsigned integer.
long              l;
long int          l;
DT_INT 32-bit signed integer.
unsigned long int ul;
DT_UNSINT 32-bit unsigned integer.
DECL_BIGINT       ll;
DT_BIGINT 64-bit signed integer.
DECL_UNSIGNED_BIGINT ull;
DT_UNSBIGINT 64-bit unsigned integer.
float f;
DT_FLOAT 4-byte single-precision floating-point value.
double d;
DT_DOUBLE 8-byte double-precision floating-point value.
char a[n]; /*n>=1*/
DT_STRING Null-terminated string, in CHAR character set. The string is blank-padded if the database is initialized with blank-padded strings. This variable holds n-1 bytes plus the null terminator.
char *a;
DT_STRING Null-terminated string, in CHAR character set. This variable points to an area that can hold up to 32766 bytes plus the null terminator.
DECL_NCHAR a[n]; /*n>=1*/
DT_NSTRING Null-terminated string, in NCHAR character set. The string is blank-padded if the database is initialized with blank-padded strings. This variable holds n-1 bytes plus the null terminator.
DECL_NCHAR *a;
DT_NSTRING Null-terminated string, in NCHAR character set. This variable points to an area that can hold up to 32766 bytes plus the null terminator.
DECL_VARCHAR(n) a;
DT_VARCHAR Varying length character string, in CHAR character set, with 2-byte length field. Not null-terminated or blank-padded. The maximum value for n is 32765 (bytes).
DECL_NVARCHAR(n) a;
DT_NVARCHAR Varying length character string, in NCHAR character set, with 2-byte length field. Not null-terminated or blank-padded. The maximum value for n is 32765 (bytes).
DECL_LONGVARCHAR(n) a;
DT_LONGVARCHAR Varying length long character string, in CHAR character set, with three 4-byte length fields. Not null-terminated or blank-padded.
DECL_LONGNVARCHAR(n) a;
DT_LONGNVARCHAR Varying length long character string, in NCHAR character set, with three 4-byte length fields. Not null-terminated or blank-padded.
DECL_BINARY(n) a;
DT_BINARY Varying length binary data with 2-byte length field. The maximum value for n is 32765 (bytes).
DECL_LONGBINARY(n) a;
DT_LONGBINARY Varying length long binary data with three 4-byte length fields.
char            a; /*n=1*/ 
DECL_FIXCHAR(n) a;
DT_FIXCHAR Fixed length character string, in CHAR character set. Blank-padded but not null-terminated. The maximum value for n is 32767 (bytes).
DECL_NCHAR       a; /*n=1*/
DECL_NFIXCHAR(n) a;
DT_NFIXCHAR Fixed length character string, in NCHAR character set. Blank-padded but not null-terminated. The maximum value for n is 32767 (bytes).
DECL_DATETIME a;
DT_TIMESTAMP_STRUCT SQLDATETIME structure
 Character sets
 Data lengths
 Pointers to char
 Scope of host variables
 See also