|
AnyDAC
|
Occurs when record update is applying to a database.
Use an OnUpdateRecord event handler to process immediate or cached updates that cannot be correctly or easily handled:
This event is useful for applications that require:
ASender is the dataset to which updates are applied.
ARequest indicates whether the current update is the insertion, deletion or modification of a record.
AAction indicates the action taken by the OnUpdateRecord handler before it exits. On entry into the handler, AAction is always set to eaDefault. If OnUpdateRecord is successful, it should set AAction to eaApplied before exiting.
|
AAction value |
Description |
|
eaFail |
Mark the update as failed and return an error. |
|
eaSkip |
Skip current update and do not mark it as applied. |
|
eaRetry |
Retry the current operation. |
|
eaApplied |
Mark current update as applied. |
|
eaDefault |
Take default action. For successful update it is eaApplied, for failed update it is eaFail. |
|
eaExitSuccess |
Stop to process the cached updates, return success. |
|
eaExitFailure |
Stop to process the cached updates, return failure. |
The OnUpdateRecord event handler code should read the dataset field values, including TField.NewValue, OldValue and CurValue. There:
Note, the OnUpdateRecord handler code must not call the methods that change the current dataset position.
property OnUpdateRecord: TADUpdateRecordEvent;
Overriding Posting Updates, ApplyUpdates, CachedUpdates, Post, Delete, OnUpdateError
procedure TForm1.ADQuery1UpdateRecord(ASender: TDataSet; ARequest: TADUpdateRequest; var AAction: TADErrorAction; AOptions: TADUpdateRowOptions); begin if ARequest = arInsert then begin // set the SQL command to insert new record ADQuery2.SQL := 'insert into mytab (id, code, name) values (:id, :code, :name) returning tmstamp into :ts'; // set parameter values ADQuery2.Params[0].Value := ASender['id']; ADQuery2.Params[1].Value := ASender['code']; ADQuery2.Params[2].Value := ASender['name']; // specially define TS parameter ADQuery2.Params[3].DataType := ftDateTime; ADQuery2.Params[3].ParamType := ptOutput; // insert new record ADQuery2.ExecSQL; // move TS output parameter value back to dataset ASender['tmstamp'] := ADQuery2.Params[3].Value; // return 'Ok' status AAction := eaApplied; end; end;
See demos:
|
What do you think about this topic? Send feedback!
|