SQL/MX 2.x Reference Manual (H06.04+)

Embedded-Only SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
3-66
C Examples of INVOKE
Using INVOKE in a C Program
The general syntax for using an embedded INVOKE directive within an SQL declare
section in a C program is:
EXEC SQL INVOKE table [AS structure-name];
struct structure-name structure-instance ;
The struct declaration declares structure-instance to be a structure of the type
structure-name. You must declare a variable of the struct type so that you can
use that variable in your C language statements.
Using typedef for a Structure
You can use typedef to create your own name for a structure that is created with an
INVOKE directive. A typedef struct statement can be global or local in scope and
must be defined in the SQL declare section of a C program.
C Examples of INVOKE
Suppose that the EMPLOYEE table consists of the EMPNUM, FIRST_NAME,
LAST_NAME, and DEPTNUM columns. The FIRST_NAME column allows null,
and the EMPNUM column is the primary key. This example shows an INVOKE
statement with the NULL STRUCTURE clause and the generated structure
template:
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL DECLARE SCHEMA 'samdbcat.persnl';
EXEC SQL INVOKE employee AS emptbl_rec NULL STRUCTURE;
struct emptbl_rec, emptbl_rec1, emptbl_rec2;
...
EXEC SQL END DECLARE SECTION;
/* Input employee number for search */
...
EXEC SQL
SELECT empnum, first_name, last_name, deptnum
INTO :emptbl_rec1.empnum, :emptbl_rec1.first_name,
:emptbl_rec1.last_name, :emptbl_rec1.deptnum
FROM persnl.employee
WHERE empnum = :hv_this_employee;
The SQL/MX C preprocessor generates the structure immediately after the
INVOKE statement in the preprocessed program code:
/* Beginning of generated code for SQL INVOKE */
struct emptbl_rec {
unsigned short empnum;
struct {
short indicator;
char valu[16];
} first_name;
char last_name[21];
unsigned short deptnum;
};