FireDAC.Comp.DataSet.TFDDataSet.OnUpdateRecord
Delphi
property OnUpdateRecord: TFDUpdateRecordEvent read FOnUpdateRecord write FOnUpdateRecord;
C++
__property TFDUpdateRecordEvent OnUpdateRecord = {read=FOnUpdateRecord, write=FOnUpdateRecord};
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
event | public | FireDAC.Comp.DataSet.pas FireDAC.Comp.DataSet.hpp |
FireDAC.Comp.DataSet | TFDDataSet |
Description
Occurs when a record update is applied to a database.
Use an OnUpdateRecord event handler to process immediate or cached updates that cannot be correctly or easily handled:
- Using FireDAC automatic SQL update command generation.
- By a single table adapter component.
- By a single update component.
This event is useful for applications that require:
- Additional control over parameters and macros substitution in update components.
- Multi-SQL statement updates, when the DBMS does not support batches or blocks.
- Non-SQL updates posting.
ASender
is the dataset to which updates are applied.
ARequest
indicates whether the current update is the insertion, deletion, or the modification of a record.
AAction
indicates the action taken by the OnUpdateRecord event handler before it exits. On entry into the handler, AAction
is always set to eaApplied
. If OnUpdateRecord is successful, it should set AAction
to eaApplied
before exiting.
AAction value |
Description |
---|---|
|
Marks the update as failed and returns an error. |
|
Skips the current update and does not mark it as applied. |
|
Retries the current operation. |
|
Marks the current update as applied. |
|
Takes the default action. For a successful update, it is |
|
Stops processing the cached updates, returns a success message. |
|
Stops processing the cached updates, returns a failure message. |
The OnUpdateRecord event handler code should read the dataset field values, including NewValue, OldValue, and CurValue. There:
- NewValue is the new field value, as it is before posting the updates.
- OldValue is the original field value, as it is after fetching the record or after applying the last updates.
- CurValue is the current field value, the same as the Value property.
Note: The OnUpdateRecord event handler code must not call the methods that change the current dataset position.
Example
procedure TForm1.FDQuery1UpdateRecord(ASender: TDataSet; ARequest: TFDUpdateRequest;
var AAction: TFDErrorAction; AOptions: TFDUpdateRowOptions);
begin
if ARequest = arInsert then begin
// set the SQL command to insert new record
FDQuery2.SQL := 'insert into mytab (id, code, name) values (:id, :code, :name) returning tmstamp into :ts';
// set parameter values
FDQuery2.Params[0].Value := ASender['id'];
FDQuery2.Params[1].Value := ASender['code'];
FDQuery2.Params[2].Value := ASender['name'];
// specially define TS parameter
FDQuery2.Params[3].DataType := ftDateTime;
FDQuery2.Params[3].ParamType := ptOutput;
// insert new record
FDQuery2.ExecSQL;
// move TS output parameter value back to dataset
ASender['tmstamp'] := FDQuery2.Params[3].Value;
// return 'Ok' status
AAction := eaApplied;
end;
end;
See Also
- Overriding Posting Updates
- FireDAC.Comp.DataSet.TFDDataSet.ApplyUpdates
- FireDAC.Comp.DataSet.TFDDataSet.CachedUpdates
- FireDAC.Comp.DataSet.TFDDataSet.OnUpdateError