Calling the ExecSQL Method

From InterBase

Go Up to Executing Update Statements

The ExecSQL method for an update component manually applies updates for the current record. There are two steps involved in this process:

  1. Values for the record are bound to the parameters in the appropriate update SQL statement.
  2. The SQL statement is executed.

Call the 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. The ExecSQL method is most often called from within a handler for the dataset’s OnUpdateRecord event.

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 ExecSQL.

procedure TForm1.EmpAuditUpdateRecord(DataSet: TDataSet;
  UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
  with (DataSet.UpdateObject as TIBUpdateSQL) do begin
  UpdateAction := uaApplied;

If an exception is raised during the execution of the update program, execution continues in the OnUpdateError event, if it is defined.

The operations performed by ExecSQL and SetParams are analogous to the Apply method described previously.

Advance To: