FireDAC.Comp.Client.TFDCustomConnection.CommitRetaining
Delphi
procedure CommitRetaining;
C++
void __fastcall CommitRetaining();
Contents
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
procedure function |
public | FireDAC.Comp.Client.pas FireDAC.Comp.Client.hpp |
FireDAC.Comp.Client | TFDCustomConnection |
Description
Permanently stores the modifications to the data made in the current transaction, without ending the current transaction.
Call CommitRetaining to permanently store modifications, such as those caused by the INSERT, UPDATE, or DELETE command, 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 of DBMSs, then FireDAC emulates nested transactions using savepoints. CommitRetaining is useful only for the main transaction, not for nested ones.
The CommitRetaining call is the shortcut to Transaction.CommitRetaining, if the Transaction property is assigned. Otherwise, CommitRetaining will operate on default connection transaction.
Before calling CommitRetaining, an application may check the status of the InTransaction property. If an application calls CommitRetaining and there is no current transaction, an exception is raised.
CommitRetaining uses native functionality on IB/FB. On other DBMSs, the method is equal to calls of Commit, then of StartTransaction.
Example
procedure TForm1.DoThatButtonClick(Sender: TObject);
begin
FDConnection1.StartTransaction;
try
if CustomerQuery.Locate('ID', [100]) then begin
CustomerQuery.Edit;
CustomerQuery.FieldByName('status').AsString := 'top';
CustomerQuery.Post;
FDConnection1.ExecSQL('delete from debt where CustID = 100');
FDConnection1.CommitRetaining;
end;
except
FDConnection1.RollbackRetaining;
raise;
end;
end;