Calling the SetParams Method
Go Up to Executing Update Statements
The SetParams
method for an update component uses special parameter substitution rules to substitute old and new field values into the update SQL statement. Ordinarily, SetParams
is called automatically by the update component’s Apply
method. If you call Apply
directly in an OnUpdateRecord
event, do not call SetParams
yourself. If you execute an update object using its ExecSQL
method, call SetParams
to bind values to the update statement’s parameters.
SetParams
sets the parameters of the SQL statement indicated by the UpdateKind
parameter. Only those parameters that use a special naming convention automatically have a value assigned. If the parameter has the same name as a field or the same name as a field prefixed with “OLD_” the parameter is automatically a value. Parameters named in other ways must be manually assigned values. For more information see the section Understanding Parameter Substitution in Update SQL Statements.
The following example illustrates one such use of SetParams
:
procedure TForm1.EmpAuditUpdateRecord(DataSet: TDataSet; UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction); begin with DataSet.UpdateObject as TIBUpdateSQL do begin SetParams(UpdateKind); if UpdateKind = ukModified then IBQuery[UpdateKind].ParamByName('DateChanged').Value := Now; ExecSQL(UpdateKind); end; UpdateAction := uaApplied; end;
This example assumes that the ModifySQL
property for the update component is as follows:
UPDATE EmpAudit SET EmpNo = :EmpNo, Salary = :Salary, Changed = :DateChanged WHERE EmpNo = :OLD_EmpNo
In this example, the call to SetParams
supplies values to the EmpNo
and Salary
parameters. The DateChanged
parameter is not set because the name does not match the name of a field in the dataset, so the next line of code sets this value explicitly.