Calling the ExecSQL Method
Go Up to Executing Update Statements
ExecSQL method for an update component manually applies updates for the current record. There are two steps involved in this process:
- Values for the record are bound to the parameters in the appropriate update SQL statement.
- The SQL statement is executed.
ExecSQL method to apply the update for the current record in the update cache. Only use
ExecSQL when the update object is not associated with the dataset using the dataset component’s
UpdateObject property, in which case the update object is not automatically executed.
ExecSQL does not automatically call the
SetParams method to bind update SQL statement parameter values; call
SetParams yourself before invoking
ExecSQL method is most often called from within a handler for the dataset’s
If you use the dataset component’s
UpdateObject property to associate dataset and update object, this method is called automatically. Do not call
ExecSQL in a handler for the dataset component’s
OnUpdateRecord event as this will result in a second attempt to apply the current record’s update.
In a handler for the
OnUpdateRecord event, the
UpdateKind parameter is used to determine which update SQL statement to use. If invoked by the associated dataset, the
UpdateKind is set automatically. If you invoke the method in an
OnUpdateRecord event, pass an
UpdateKind constant as the parameter of
procedure TForm1.EmpAuditUpdateRecord(DataSet: TDataSet; UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction); begin with (DataSet.UpdateObject as TIBUpdateSQL) do begin SetParams(UpdateKind); ExecSQL(UpdateKind); end; UpdateAction := uaApplied; end;
If an exception is raised during the execution of the update program, execution continues in the
OnUpdateError event, if it is defined.