Saving Values in an sqlda Structure (ESQL/C)
If you do not know the number of output values to be returned at runtime or their data types, you can associate output values from an sqlda structure. An sqlda structure lists the data type and memory location of one or more return values. To specify an sqlda structure as the location of return values, use the INTO DESCRIPTOR clause of the EXECUTE statement. Each time the EXECUTE statement is run, the database server places the returns values that the sqlda structure describes into the sqlda structure.
struct sqlda *pointer2; ... sprintf(sel_stmt, "%s %s %s", "select fname, lname from customer", "where customer_num =", cust_num); EXEC SQL prepare sel1 from :sel_stmt; EXEC SQL describe sel1 into pointer2; EXEC SQL execute sel1 into descriptor pointer2;
The sqlda.sqld value specifies the number of output values that are described in occurrences of sqlvar. This number must correspond to the number of values that the SELECT or EXECUTE FUNCTION (or EXECUTE PROCEDURE) statement returns.
For more information, refer to the sqlda discussion in the HCL OneDB™ ESQL/C Programmer's Manual.
EXEC SQL prepare sel1 from 'select fname, lname from customer where customer_num =123'; EXEC SQL execute sel1 into :fname, :lname using :cust_num;
EXEC SQL BEGIN DECLARE SECTION; int customer_num =100; char fname[25]; EXEC SQL END DECLARE SECTION; EXEC SQL prepare sel1 from 'select fname from customer where customer_num=?'; for ( ;customer_num < 200; customer_num++) { EXEC SQL execute sel1 into :fname using customer_num; printf("Customer number is %d\n", customer_num); printf("Customer first name is %s\n\n", fname); }