SQL/MX 3.2.1 Programming Manual for C and COBOL (H06.26+, J06.15+)

Host Variables in C/C++ Programs
HP NonStop SQL/MX Release 3.2.1 Programming Manual for C and COBOL663854-005
3-43
Creating C Host Variables Using INVOKE
...
EXEC SQL OPEN get_null_salary ;
...
EXEC SQL FETCH get_null_salary
INTO :hv_empnum,
:hv_first_name,
:hv_last_name,
:hv_deptnum,
:hv_jobcode,
:hv_salary ;
/* Process the row that contains the null salary. */
/* Branch back to FETCH the next row. */
...
EXEC SQL CLOSE get_null_salary ;
...
Creating C Host Variables Using INVOKE
The INVOKE preprocessor directive creates a structure with the names of the host
variables corresponding to columns in a table or view. INVOKE converts the column
names to C identifiers and generates a C declaration for each column. If a column
allows null, INVOKE also creates an indicator variable for the column.
You can declare host variables that correspond to the columns in an SQL table or view
without using an INVOKE statement. However, using an INVOKE statement to
generate host variables has these advantages:
Program independence: If you modify a table or view, the INVOKE statement re-
creates the host variables to correspond to the new table or view when you run the
SQL/MX C preprocessor. However, you must modify a program that refers to a
deleted column or accesses a new column.
Performance: The INVOKE statement maps SQL data types to the corresponding
host language data types, and usually no data conversion is required at run time.
For further information, see Example 3-1 on page 3-47 and Example 3-2 on
page 3-48.
Program readability and maintenance: The INVOKE statement creates host
variables using the same names as column names in the table or view.
Using the INVOKE Directive
To execute an INVOKE directive for a table or view, you must have SELECT privileges
on all applicable columns when you run the SQL/MX C preprocessor. The general
syntax for using an embedded INVOKE directive within an SQL Declare Section in a
C program is:
EXEC SQL INVOKE table-or-view [AS structure-name];
struct structure-name structure-instance ;
For complete syntax, see the INVOKE Directive in the SQL/MX Reference Manual.