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 | ||
---|---|---|---|---|
|
DT_SMALLINT | 16-bit signed integer. | ||
|
DT_UNSSMALLINT | 16-bit unsigned integer. | ||
|
DT_INT | 32-bit signed integer. | ||
|
DT_UNSINT | 32-bit unsigned integer. | ||
|
DT_BIGINT | 64-bit signed integer. | ||
|
DT_UNSBIGINT | 64-bit unsigned integer. | ||
|
DT_FLOAT | 4-byte single-precision floating-point value. | ||
|
DT_DOUBLE | 8-byte double-precision floating-point value. | ||
|
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. | ||
|
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. | ||
|
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. | ||
|
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. | ||
|
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). | ||
|
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). | ||
|
DT_LONGVARCHAR | Varying length long character string, in CHAR character set, with three 4-byte length fields. Not null-terminated or blank-padded. | ||
|
DT_LONGNVARCHAR | Varying length long character string, in NCHAR character set, with three 4-byte length fields. Not null-terminated or blank-padded. | ||
|
DT_BINARY | Varying length binary data with 2-byte length field. The maximum value for n is 32765 (bytes). | ||
|
DT_LONGBINARY | Varying length long binary data with three 4-byte length fields. | ||
|
DT_FIXCHAR | Fixed length character string, in CHAR character set. Blank-padded but not null-terminated. The maximum value for n is 32767 (bytes). | ||
|
DT_NFIXCHAR | Fixed length character string, in NCHAR character set. Blank-padded but not null-terminated. The maximum value for n is 32767 (bytes). | ||
|
DT_TIMESTAMP_STRUCT | SQLDATETIME structure |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |