lrd_save_col
Saves the value of a table cell.
LRDRET lrd_save_col( LRD_CURSOR *mptCursor, unsigned int muiColNum, long mliRowNum, unsigned long muliOption, char *mpszParamName );
| mptCursor | A pointer to an LRD_CURSOR structure. |
| muiColNum | The column number of the value to save. |
| muiRowNum | The row number of the value to save. To save the last row, set the row number to zero. |
| muliOption | One of the Save Column Options. |
| mpszParamName | A parameter name using alpha-numerical characters, enclosed by quotation marks. |
The lrd_save_col function saves the dynamic value of a specified table cell and assigns it to a parameter. This function is used for Correlating Statements and other SQL statements within a script. Instead of using the actual result fetched during a query, you replace the constant value with a parameter. This parameter can then be used by other database statements within the same script. Note that lrd_save_col always precedes an lrd_fetch statement.
For more details refer to the Function Header File lrd.h in the include directory.
Return Values
See LRD Return Values.
Parameterization
You cannot use standard parameterization for any arguments in this function.
Example
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.
Example 1
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, ...);Example 2
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, ...);

