Example: lrd_save_col
In Example 1, a user performed a query for John's id. He performed a second query to retrieve the salary of the employee with the id of 777. The user waited for the results of the first query, before performing the second query.
Example 2 shows the use of a placeholder with a correlated query.
In the modified script, lrd_save_col saves the value of the first query, John's id of 777. This value is stored in the first column and first row of the returned table. lrd_save_col assigns it to a newly defined parameter, emp_id. This parameter is used in the second query.
/* Recorded script */
lrd_stmt(Csr1, "select id from employees where name='John'", ...);
lrd_bind_col(Csr1,...);
lrd_exec(Csr1, ...);
lrd_fetch(Csr1, 1,...);
lrd_stmt(Csr1, "select salary from payment where id='777' ",...);
lrd_exec(Csr1, ...);
/ * Modified script */
lrd_stmt(Csr1, "select id from employees where name='John'", ...);
lrd_bind_col(Csr1,...);
lrd_exec(Csr1, ...);
lrd_save_col(Csr1, 1, 1, 0, "emp_id");
lrd_fetch(Csr1, 1, ...);
lrd_stmt(Csr1, "select salary from payment where id=''<emp_id>'", ...);
lrd_exec(Csr1, ...);
This example shows the use of a placeholder with a correlated query. A user performed his initial query for John's id. He performed a second query to retrieve the salary of the employee with that id. This actual id is bound to a placeholder using lrd_assign_bind. Note that the user waited for the results of the first query before performing the second one.
/* Recorded script */
lrd_stmt(Csr1, "select id from employees where name='John'", ...);
lrd_bind_col(Csr1,...);
lrd_exec(Csr1, ...);
lrd_fetch(Csr1, 1,...);
lrd_stmt(Csr1, "select salary from payment where id=:id",...);
lrd_assign_bind(Csr1, "id", "777", ...);
lrd_exec(Csr1, ...);
In the modified script, lrd_save_col saves the value of the first query, John's id, to a parameter. emp_id. This newly defined parameter is bound to the placeholder, id, by lrd_assign_bind.
/ * Modified script */
lrd_stmt(Csr1, "select id from employees where name='John'", ...);
lrd_bind_col(Csr1,...);
lrd_exec(Csr1, ...);
lrd_save_col(Csr1, 1, 1, 0, "emp_id");
lrd_fetch(Csr1, 1, ...);
lrd_stmt(Csr1, "select salary from payment where id=:id",...);
lrd_assign_bind(Csr1, "id", "<emp_id>", ...);
lrd_exec(Csr1, ...);