CONNX Data Integration Suite 14.8.0 | CONNX Embedded SQL for Adabas | Programming Guide - C | Host Variables in C
 
Host Variables in C
C host variables used in SQL statements must be declared within the SQL BEGIN DECLARE SECTION and END DECLARE SECTION statements. CONNX Embedded SQL allows the use of single host variables and host variable structures.
Host Variable Declaration
C structures are named sets of C single host variables and must conform to the ANSI Standard (X3.159-1989) for C. The use of C structures within SQL statements is a CONNX Embedded SQL extension and not part of the ANSI SQL Standard. It is not possible to use a union of host variables. The use of the enum type is also not possible.
Binary Data Type
There is no intrinsic binary data type in the C host language. In order to retrieve and supply binary data using host variables, the intrinsic C data type of character must be mapped to the CONNX Embedded SQL data type of binary. A pseudo type has been introduced using a CONNX Embedded SQL macro. Therefore, host variables, which will be used for binary data type transportation, must be declared as SAGBINARY. The CONNX Embedded SQL will then associate such variables with the type binary. Such variables can only be used as binary host variables. The type declaration is a C macro, provided by the CONNX Embedded SQL. A SAGBINARY variable is declared as follows:
EXEC SQL BEGIN DECLARE SECTION;
SAGBINARY ( hv_name, x );
EXEC SQL END DECLARE SECTION;
where hv_name is the name of the host variable and x is the length of the variable in bits.
The macro is resolved as follows:
char hv_name[y];
where y is the required length in bytes.
Binary host variables are not subject to byte swapping, nor are they subject to any ASCII/ EBCDIC conversion. No string terminator is to be provided for binary host variables. Therefore, the direct binary contents of a host variable will be received by CONNX Embedded SQL, with each element of the character array representing a full 8 bytes.
The pre-compiler must run prior to the C macro processor. No corresponding functionality is supported for the C language when using dynamic SQL and the SQLDA.
Syntax
To declare a host variable, the syntax is declaration-specifiers, optional init-declarator-list and the terminating delimiter ;.The different items in the init-declarator are seperated by a "," character.The init-declarator syntax is declarator. You can optionally assign an initializer as a declarator.In the declaration specifiers, the storage-class specifier, the type-qualifier, the type-specifier, the large-number specifier, and the binary-specifier must come before the delcaration-specifiersThe storage-class-specifier can be any of the following: auto, register, static, extern, typedef.The type-qualifier can be "const" or "volatile".The storage-class-specifier data type can be any of the following: void, char, short, int, long, float, double, signed, unsigned, typedef-name, and struct-specifier.The typedef-name must have an identifier.Each struct in an init-declarator must have an identifier or a struct-declaration-list.A struct-declaration-list has stuct-declarations.A struct-declaration contains specifier-qualifer-list and a struct-declarator-list with a terminating delimiter (;) at the end.A specifier-qualifer-list has a type-specifier or type-qualifier. a type qualifier can optionally have another specifier-qualifier-list.A struct-declarator-list contains many struct-declarators, each seperated by a comma.A struct declarator can contain declarators or constant expressions.A declarator can contain an identifier, or a declarator with either a constant-expression, a parameter-list, or an identifier list.An identifier-list is a series of identifiers, each seperated by a comma.A parameter-list contains a parameter-declaration or a parameter-list, a comma, and a parameter-declaration.A direct-abstract-declarator can contain another direct-abstract-declarator, or another direct-abstract-declarator with a constant-expression, or just a parameter-type-list.A parameter-type-list contains a parameter-list. You can add additional parameters after the parameter-list by seperating them with a comma.The initializer contains an assigment-expresion or an initializer-list. You can add additional assigment-expressions after the initializer-list by separating them with a comma.An initializer-list contains comma seperated initializers.
Within embedded SQL statements, the C naming qualification rules for structure and array elements are as defined in the ANSI standard (X3.159-1989) for C. There can be any number of SQL BEGIN DECLARE SECTION statements.
Ambiguous References and Multiple Declarations
A declaration that appears more than once with the same identifier is called a multiple declaration. If a host variable refers to a multiple declaration, and the different declarations are of different types, an error occurs. Otherwise the host variable is accepted.
Data Type Conversion
The following table shows the conversion of C data types to SQL data types:
C Data Types
SQL Data Types
char (array)
CHARACTER
long (signed or unsigned)
INTEGER
int (signed or unsigned)
INTEGER
float
REAL
double
DOUBLE PRECISION
short (signed or unsigned)
SMALLINT
long long
BIGINT
For more details on SQL data types and their usage in SQL statements refer to the section on Common Elements in this online help file.
The following table shows the conversion of SQL data types to C data types:
SQL Data Types
C Data Types
CHAR (more than one character)
char (array)
BINARY
SAGBINARY (char array)
INTEGER
long
SMALLINT
short
REAL
float
DOUBLE PRECISION
double
FLOAT
float
DECIMAL
float, double or long
NUMERIC
float, double or long
BIGINT
long long