FireDAC.Phys.MongoDBDataSet.TFDMongoDataSet.OnUpdateRecord

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property OnUpdateRecord;

C++

__property OnUpdateRecord;

Properties

Type Visibility Source Unit Parent
event published
FireDAC.Phys.MongoDBDataSet.pas
FireDAC.Phys.MongoDBDataSet.hpp
FireDAC.Phys.MongoDBDataSet TFDMongoDataSet

Description

Occurs when a record update is applied to a database.

FireDAC.Phys.MongoDBDataSet.TFDMongoDataSet.OnUpdateRecord inherits from FireDAC.Comp.DataSet.TFDDataSet.OnUpdateRecord. All content below this line refers to FireDAC.Comp.DataSet.TFDDataSet.OnUpdateRecord.

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:

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 

eaFail

Marks the update as failed and returns an error. 

eaSkip 

Skips the current update and does not mark it as applied. 

eaRetry

Retries the current operation. 

eaApplied 

Marks the current update as applied. 

eaDefault 

Takes the default action. For a successful update, it is eaApplied, while for a failed update, it is eaFail

eaExitSuccess 

Stops processing the cached updates, returns a success message. 

eaExitFailure 

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

Samples