SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Host Variables in C/C++ Programs
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
3-39
C Example of Using INVOKE
C Example of Using INVOKE
The next example declares and uses host variable names and indicator variable
names and shows:
•
A host variable declaration using INVOKE that includes indicator variables. The
structure is declared as global so that any function can reference the host
variables.
•
A host variable indicator variable used in the SELECT statement. The columns that
might contain null require the indicator variable following the host variable to
receive information on nulls.
•
An indicator variable testing for null. If the value of the indicator variable following
the SELECT is less than zero, the associated column is null.
Example 3-3 retrieves four columns of an order detail table. The table is like the
ODETAIL table of the sample database except that the UNIT_PRICE and
QTY_ORDERED columns allow null.
Example 3-3. C INVOKE (page 1 of 2)
...
void handle_null(void);
void display_result(void);
...
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL INVOKE samdbcat.mysch.odetail;
/* Beginning of generated code for SQL INVOKE */
struct odetail_type {
unsigned long ordernum;
unsigned short partnum;
short unit_price_i;
long unit_price;
short qty_ordered_i;
unsigned long qty_ordered;
} ;
struct odetail_type odetail_rec;
EXEC SQL END DECLARE SECTION;
int main()
{
EXEC SQL BEGIN DECLARE SECTION;
char SQLSTATE[6];
unsigned NUMERIC (6) in_ordernum;
unsigned NUMERIC (4) in_partnum;
EXEC SQL END DECLARE SECTION;
...
C