Host Variables

C host variables used in SQL statements must be declared within the SQL BEGIN DECLARE SECTION and END DECLARE SECTION statements. Adabas SQL Gateway 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 an Adabas SQL Gateway 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 Adabas SQL Gateway Embedded SQL data type of binary. A pseudo type has been introduced using an Adabas SQL Gateway Embedded SQL macro. Therefore, host variables which are to be used for binary data type transportation, must be declared as SAGBINARY. The Adabas SQL Gateway Embedded SQL will then associate such variables with the type binary. Such variables can, therefore, only be used as binary host variables. The type declaration, is indeed a C macro, provided by the Adabas SQL Gateway 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 in bits of the variable.

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 Adabas SQL Gateway 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

 

graphic_059.png

 

graphic_060.png

graphic_061.png

graphic_062.png

graphic_063.png

graphic_064.png

graphic_065.png

graphic_068.png

graphic_069.png

 

graphic_070.png

graphic_071.png

graphic_072.png

graphic_073.png

graphic_074.png

graphic_075.png

graphic_076.png

graphic_077.png

graphic_078.png

graphic_079.png

graphic_080.png

graphic_081.png

graphic_082.png

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 may be any number of SQL BEGIN DECLARE SECTIONs.

 

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 such 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