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

SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
2-135
C Examples of EXECUTE
Use EXECUTE USING for one parameter value, which is unnamed in the prepared
statement:
PREPARE FINDEMP FROM
SELECT * FROM persnl.employee
WHERE salary > ?SALARY AND jobcode = ?;
SET PARAM ?SALARY 40000.00;
EXECUTE FINDEMP USING 450;
SET PARAM ?SALARY 20000.00;
EXECUTE FINDEMP USING 300;
C Examples of EXECUTE
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;
...
Prepare a statement, allocate input and output descriptor areas, describe the input
and output descriptor areas, and execute the statement by using the descriptor
areas:
...
strcpy(stmt_buffer,"SELECT * FROM EMPLOYEE"
" WHERE EMPNUM = CAST(? AS NUMERIC(4) unsigned)");
...
EXEC SQL PREPARE S1 FROM :stmt_buffer;
...
desc_max = 1;
EXEC SQL ALLOCATE DESCRIPTOR 'in_args' WITH MAX :desc_max;
desc_max = 6;
EXEC SQL ALLOCATE DESCRIPTOR 'out_cols' WITH MAX :desc_max;
...
EXEC SQL DESCRIBE INPUT S1 USING SQL DESCRIPTOR 'in_args';
EXEC SQL DESCRIBE OUTPUT S1 USING SQL DESCRIPTOR 'out_cols';
...
EXEC SQL EXECUTE S1 USING SQL DESCRIPTOR 'in_args'
INTO SQL DESCRIPTOR 'out_cols';
...