SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
3-1
3
Host Variables in C/C++ Programs
Host variables are data items declared in a host application program and used in both
host language statements and embedded SQL statements. They provide
communication between SQL statements and the host language statements. An input
host variable transfers data from a host language program to an SQL/MX database,
and an output host variable transfers data from a database to the program.
This section describes:
Specifying a Declare Section on page 3-1
C Host Variable Data Types on page 3-2
Using Corresponding SQL and C Data Types on page 3-7
Specifying Host Variables in SQL Statements on page 3-12
Using Host Variables in a C/C++ Program on page 3-13
Using Indicator Variables in a C/C++ Program on page 3-29
Creating C Host Variables Using INVOKE on page 3-31
Character Set Examples on page 3-40
Specifying a Declare Section
Declare all host variables within an SQL Declare Section:
Use the BEGIN DECLARE SECTION statement to begin a Declare Section.
Use the END DECLARE SECTION statement to end a Declare Section.
You can specify more than one Declare Section in your source file but do not nest
them.
You can use SQL or host language comments in a Declare Section.
For the best performance, declare the host variable as the same data type as the
column in the SELECT list. If you declare this way, you can use bulk moves to
input and output data.
Do not:
Place a Declare Section within a C structure declaration.
Include a C++ class definition within a Declare Section.
Include a C function declaration within a Declare Section.
Include any executable code within a Declare Section.
Example
This example uses host variable declarations in an SQL Declare Section:
EXEC SQL BEGIN DECLARE SECTION;
char SQLSTATE[6];
unsigned NUMERIC (6) ordernum; /* simple variables */
C