SQL/MP Programming Manual for C
Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C—429847-008
10-43
Detailed Dynamic SQL Program
Defines a buffer to store output variables, with storage for column values of
different data types.
Defines a buffer to store input parameters, with storage for parameter values of
different data types.
Prepares the SQL statement and assigns it a statement name. (Note: statement
and cursor host variables are not used in this program.)
Determines the data types of the input parameters and moves them to the host
variables of the corresponding data types.
Determines the data types of the output variables and moves them to the host
variables of the corresponding data types.
Sets up the SQLDA to point to the storage for the variables referenced by the
query. The storage is allocated at run time.
Using the input SQLDA if there were parameters, either performs a cursor FETCH
for a SELECT statement or runs a non-SELECT statement.
Before running the program, command interpreter ADD DEFINE commands were
entered to associate tables orders and odetail with logical names =orders and =odetail,
respectively. The sample query shown selects order numbers and customer numbers
from the orders table where the order includes part number 6400.
Following is sample output from the program. The program prompts for input with the
>> symbol. A semicolon is required to terminate input.
33> run cdynobj
This is DYNAMIC SQL test.
Enter SQL statement or SAME to reuse last statement or END:
>>select ordernum, custnum
from =orders where ordernum in
(select ordernum from =odetail where partnum = 6400);
ORDERS.ORDERNUM 200320
ORDERS.CUSTNUM 21
ORDERS.ORDERNUM 300350
ORDERS.CUSTNUM 543
ORDERS.ORDERNUM 800660
ORDERS.CUSTNUM 3210
ORDERS.ORDERNUM 400410
ORDERS.CUSTNUM 7654
--- 4 row(s) selected.
Enter SQL statement or SAME to reuse last statement or END:
>>end;
End of current session
34>