lrt_save32_fld_val

Correlating Functions

Saves the current value of an FML32 buffer to a parameter.

int lrt_save32_fld_val( FBFR32 *fbfr, char *name, FLDOCC32 occ, char *paramName );

fbfr The FML32 buffer whose contents you want to save.
name The name of the FML32 buffer, in the form "name=<NAME>" or "id=<ID>".
occ Identification to refer to the buffer occurrence. This is used for uniquely identifying more than one occurrence of a buffer with the same name or id (0 for 1st occurrence, 1 for 2nd, etc.).
paramName Parameter name to be used in subsequent lrt statements to refer to the saved information. Name is enclosed in double-quotes.

The lrt_save32_fld_val function saves the current value of an FML32 buffer to a parameter specified by paramName. This function is used for correlating queries 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.

Some systems represent a field by an id number rather than a field name during recording. You can correlate by field id as follows:

lrt_save32_fld_val(fbfr, "id=xxxx", 0, "parameter");

Return Values

If this function fails, it returns a negative value. If it succeeds, it returns 0.

Parameterization

You cannot use standard parameterization for any arguments in this function.

Example

In the following example, the user opened a new bank account and then deposited money. If you replay the recorded script you would be unable to deposit money into the new account because you would not know the new account number. In the modified script, lrt_save32_fld_val saves the account number to the parameter account_id, and uses it in the Deposit statement.

Copy code
/* Recorded <i>script</i> */
/* Fill the data_0 buffer with new account information */
data_0 = lrt_tpalloc("FML32", "", 512);
lrt_Finitialize32((FBFR32*)data_0);
lrt_Fadd32_fld((FBFR32*)data_0, "name=BRANCH_ID", "value=1", LRT_END_OF_PARMS);
data_1 = lrt_tpalloc("FML32", "", 512);
/* Open a new account */
tpresult_int = lrt_tpcall("OPEN_ACCT", data_0, 0,                                                                                &data_1, &olen_2, 0);
lrt_abort_on_error();
/*Fill buffer for the deposit*/
lrt_Finitialize32((FBFR32*)data_0);
lrt_Fadd32_fld((FBFR32*)data_0, "name=ACCOUNT_ID", "value=10007", LRT_END_OF_PARMS);
lrt_Fadd32_fld((FBFR32*)data_0, "name=SAMOUNT", "value=200.11", LRT_END_OF_PARMS);
/* Deposit money into the new account */
tpresult_int = lrt_tpcall("DEPOSIT", data_0, 0, &data_1, &olen_7, 0);
lrt_abort_on_error();
/* Modified <i>script</i> */
/* Fill the data_0 buffer with new account information */
data_0 = lrt_tpalloc("FML32", "", 512);
lrt_Finitialize32((FBFR32*)data_0);
lrt_Fadd32_fld((FBFR32*)data_0, "name=BRANCH_ID", "value=1", LRT_END_OF_PARMS);
data_1 = lrt_tpalloc("FML32", "", 512);
/* Open a new account and save the new account number*/
tpresult_int = lrt_tpcall("OPEN_ACCT", data_0, 0,                                                                                &data_1, &olen_2, 0);
lrt_abort_on_error();
lrt_save32_fld_val((FBFR32*)data_1, "name=ACCOUNT_ID", 0, "account_id");                                                                                                                
/* Use result from first query to fill buffer for the deposit*/
lrt_Finitialize32((FBFR32*)data_0);
lrt_Fadd32_fld((FBFR32*)data_0, "name=ACCOUNT_ID", "value=<account_id>", LRT_END_OF_PARMS);
lrt_Fadd32_fld((FBFR32*)data_0, "name=SAMOUNT", "value=200.11", LRT_END_OF_PARMS);
/* Deposit money into the new account */
tpresult_int = lrt_tpcall("DEPOSIT", data_0, 0, &data_1, &olen_7, 0);
lrt_abort_on_error();