background image
<< To enable the script to run | Tuxedo Vuser Scripts >>
<< To enable the script to run | Tuxedo Vuser Scripts >>

To use the newly assigned value of the placeholder

Database Vuser Scripts · Correlating Database Statements
Creating Vuser Scripts
Chapter 10, page 185
After saving the
count
value from the first fetch, the script derives the next value
with a stored procedure, using the formula
newemp=empno+1
. The placeholder
descriptor,
newemp,
receives this new value when the stored procedure is
executed.
To use the newly assigned value of the placeholder, you save it to a variable using
the lrd_save_value function. The script below saves the placeholder descriptor to
the
new_no
variable and binds its value to a host variable. The new, dynamically
saved value, is inserted into the table with the rest of the elements of the employee
record.
/* Define next employee's number: newemp = empno +1 */
lrd_stmt(Csr1, "\t\tdeclare\n \tPROCEDURE new_emp (empno in integer, "
"newemp out integer) is\n\t\tbegin\n\t\t\tnewemp:=empno+1;\n\t\tend "
"new_emp;\n\t begin\n\t\t\tnew_emp(:empno,:newemp);\n\t\tend;", -1, -1
/*Deferred*/, 2 /*Ora V7*/, 0);
/* Bind the placeholder values to the variables. */
lrd_assign_bind(Csr1, "empno", "<row_cnt>", &empno_D2, 0, 0, 0);
lrd_assign_bind(Csr1, "newemp", "0", &newemp_D3, 0, 0, 0);
lrd_exec(Csr1, 0, 0, 0, 0, 0);
lrd_save_value(&newemp_D3, 0, 0, "new_no");
lrd_stmt(Csr2, "insert into employees values ('TOM JONES',:newemp,"
"'1-JAN-97','R&D',22)", -1, 0 /*Non deferred*/, 2 /*Ora V7*/, 0);
lrd_assign_bind(Csr2, "newemp", "<new_no>", &newemp_D4, 0, 0, 0);
lrd_exec(Csr2, 0, 0, 0, 0, 0);