background image
<< new variable | Correlating Queries for Tables with Constraints >>
<< new variable | Correlating Queries for Tables with Constraints >>

Correlating Queries with Output Placeholders

Database Vuser Scripts · Correlating Database Statements
Creating Vuser Scripts
Chapter 10, page 181
Correlating Queries with Output Placeholders--Example
The following example illustrates a correlated query using binding with output
placeholders set by a stored procedure. A stored procedure,
get_emp_id,
retrieves John's id. The lrd_assign_bind function assigns the retrieved value, 777,
to a host variable.
To correlate the queries, use the lrd_save_value function to save the value of the
placeholder descriptor representing John's ID. Use this value in the second query.
lrd_stmt(Csr1, "begin :id=get_emp_id('john') end",...);
lrd_bind_placeholder(Csr1, "id", &ID_D1, 0, 0);
lrd_exec(Csr1, ...);
lrd_stmt(Csr1, "select salary from payment where year='1996' and
id=:id",...);
lrd_assign_bind(Csr1, "id", "777", &id_D2, ...);
lrd_exec(Csr1, ...);
lrd_stmt(Csr1, "begin :id=get_emp_id('john') end", ...);
lrd_bind_placeholder(Csr1, "id", &ID_D1, 0, 0);
lrd_exec(Csr1, ...);-
lrd_save_value(&ID_D1, 0, 0, "emp_id");
lrd_stmt(Csr1, "select salary from payment where year='1996' and
id=:id",...);
lrd_assign_bind(Csr1, "id", "<emp_id>",&id_D2, ...);
lrd_exec(Csr1, ...);