Declaring Host Variables

Embedded SQL for C and SQL Server

Embedded SQL for C and SQL Server

Declaring Host Variables

Before you use a host variable in an Embedded SQL statement, you must declare the variable by using normal C-language syntax within an Embedded SQL host declare section. Host variable declarations start with the Embedded SQL statement BEGIN DECLARE SECTION and end with the END DECLARE SECTION statement, for example:

EXEC SQL BEGIN DECLARE SECTION;
int nID;
unsigned short usNumber;
char szName[30];
EXEC SQL END DECLARE SECTION;

Note  Embedded SQL limits the length of host variable names to 30 characters. In general, Embedded SQL does not provide support for new Microsoft® SQL Server™ features such as 128-bit Unicode character support for identifiers. Declaring host variables with names longer than 30 characters causes an error at precompile time when Embedded SQL processes the host variable.

Host variables can be declared wherever C variables can be declared. However, you can use a structure member as a host variable. You can also use a pointer to a single array element as a host variable and index that pointer as appropriate before each use.

Note  You may have to modify the generated C source code when pointer variables are used. The ESQL/C precompiler will give you a warning message when it cannot determine the length of a pointer host variable. This is indicated by a value -1 in the fourth parameter to the sqlasetv API call.