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

SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
2-162
C Examples of PREPARE
C Examples of PREPARE
Prepare and execute an INSERT statement:
...
strcpy(stmt_buffer,"INSERT INTO SALES.CUSTOMER"
" (CUSTNUM, CUSTNAME, STREET, CITY, STATE, POSTCODE)"
" VALUES (1120, 'EXPERT MAILERS', '5769 N.25TH PLACE',"
" 'PHOENIX', 'ARIZONA', '85016')");
...
EXEC SQL PREPARE ins_cust FROM :stmt_buffer;
...
EXEC SQL EXECUTE ins_cust;
...
Prepare and execute an UPDATE statement with dynamic input parameters:
...
strcpy(stmt_buffer,"UPDATE SALES.CUSTOMER SET CREDIT = ?"
" WHERE CUSTNUM = CAST(? AS NUMERIC(4) UNSIGNED)");
...
EXEC SQL PREPARE upd_cust FROM :stmt_buffer;
...
/* Input values for parameters into host variables */
scanf("%s",in_credit);
scanf("%ld",&in_custnum);
...
EXEC SQL EXECUTE upd_cust USING :in_credit, :in_custnum;
...
This example uses extended statement names:
...
strcpy(stmt,"ins_cust1");
EXEC SQL PREPARE :stmt FROM :stmt_buffer;
EXEC SQL EXECUTE :stmt;
...
strcpy(stmt,"ins_cust2");
EXEC SQL PREPARE :stmt FROM :stmt_buffer;
EXEC SQL EXECUTE :stmt;