Scalable Database Server, HiRDB Version 8 UAP Development Guide
The preprocessor features an option that allows you to use a structure written in C to specify multiple embedded variables at one time.
Structures can be used as embedded variables in the following locations:
For details about SQL preprocessor options, see the option descriptions in 8.2.2 Preprocessing in UNIX or 8.2.3 Preprocessing in Windows. For details about SQL statements that can use structures, see 8.2.8 Use of pointers, structures, and structure qualifiers when the -E2 or -E3 option of the preprocessor is specified.
A structure usage example is shown as follows.
struct { char xpcode[5]; char xpname[17]; char xcolor[3]; long xstock; long xprice; } xrec; ... EXEC SQL DECLARE CR3 CURSOR FOR SELECT PCODE,PNAME,COLOR,SQUANTITY, PRICE FROM STOCK; ... EXEC SQL OPEN CR3 ; /* heading */ printf(" ***** STOCK TABLE LIST *****\n\n"); printf(" PRODUCT CODE PRODUCT NAME COLOR PRICE CURRENT STOCK\n"); printf(" ---- ---------------- -- -------- --------\n"); EXEC SQL WHENEVER SQLERROR GOTO END; EXEC SQL WHENEVER NOT FOUND GOTO END; /* FETCH */ for(;;){ EXEC SQL FETCH CR3 INTO :xrec; printf(" %4s %-16s %2s %8d %8d\n", xrec.xpcode, xrec.xpname, xrec.xcolor, xrec.xprice, xrec.xstock); } END: ...
When you use a structure as an embedded variable and also want to use indicator variables, declare the indicator variables in a structure as well. Associate the individual members of the indicator variable structure in declaration sequence with the individual members of the embedded variable structure. An example is shown as follows.
struct { char xpcode[5]; char xpname[17]; char xcolor[3]; long xstock; long xprice; } xrec; struct { short xpcode_ind; short xpname_ind; short xcolor_ind; short xstock_ind; short xprice_ind; } xrec_ind; ... /* FETCH */ for(;;){ EXEC SQL FETCH CR3 INTO :xrec :xrec_ind; printf(" %4s %-16s %2s %8d %8d\n", xrec.xpcode, xrec.xpname, xrec.xcolor, xrec.xprice, xrec.xstock); } ...
You can also specify a pointer to a structure as an embedded variable. The area indicated by the pointer must be allocated beforehand.
struct tag_xrec { char xpcode[5]; char xpname[17]; char xcolor[3]; long xstock; long xprice; } *xrec_ptr; struct tag_xrec_ind { short xpcode_ind; short xpname_ind; short xcolor_ind; short xstock_ind; short xprice_ind; } *xrec_ind_ptr; ... /* FETCH */ xrec_ptr = (struct tag_xrec *)malloc(sizeof(struct tag_xrec)); xrec_ind_ptr = (struct tag_xrec_ind *) malloc(sizeof(struct tag_xrec_ind)); for(;;){ EXEC SQL FETCH CR3 INTO :xrec_ptr :xrec_ind_ptr; printf(" %4s %-16s %2s %8d %8d\n", xrec_ptr->xpcode, xrec_ptr->xpname, xrec_ptr->xcolor, xrec_ptr->xprice, xrec_ptr->xstock); } ...
All Rights Reserved. Copyright (C) 2007, Hitachi, Ltd.