FireDAC.Comp.Client.TFDCustomTransaction.CommitRetaining
Delphi
procedure CommitRetaining;
C++
void __fastcall CommitRetaining(void);
Contents
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
procedure function |
public | FireDAC.Comp.Client.pas FireDAC.Comp.Client.hpp |
FireDAC.Comp.Client | TFDCustomTransaction |
Description
Permanently stores modifications to the data made in the current transaction, without ending the current transaction.
Call CommitRetaining to permanently store modifications, such as INSERT / UPDATE / DELETE
commands, made in the current transaction to the database, without finishing the transaction.
FireDAC supports nested transactions, so the current transaction is the one started with the most recent StartTransaction call. If the database does not support nested transactions, like most DBMSs, then FireDAC will emulate nested transactions using savepoints. CommitRetaining is useful only for the main transaction, not for nested ones.
Before calling CommitRetaining, an application may check the status of the Active property. If an application calls CommitRetaining and there is no current transaction, an exception is raised.
CommitRetaining will use native functionality on Interbase/Firebird. On other DBMSs, the method is equal to calls of Commit, then of StartTransaction.
Example
procedure TForm1.ChangeButtonClick(Sender: TObject);
begin
FDQuery1.Transaction := FDTransaction1;
FDQuery1.SQL.Text := 'select * from employees';
FDQuery2.Transaction := FDTransaction1;
FDQuery2.SQL.Text := 'update employees set salary = salary * :k where id = :id';
FDTransaction1.StartTransaction;
try
FDQuery1.Open;
while not FDQuery1.Eof do begin
FDQuery2.ExecSQL('', [1.2, ADQuery1.FieldByName('id').AsInteger]);
FDTransaction1.CommitRetaining;
FDQuery1.Next;
end;
FDTransaction1.Commit;
except
FDTransaction1.Rollback;
raise;
end;
end;