AnyDAC
ContentsIndexHome
PreviousUpNext
TADCustomConnection.CommitRetaining Method

Permanently stores modifications to the data made in the current transaction, without ending the current transaction.

Group
Links

Call CommitRetaining to permanently store modifications, like a INSERT's / UPDATE's / DELETE's, made in current transaction to the database without finishing transaction. 

AnyDAC supports nested transactions, so the current transaction is the one started with most recent StartTransaction call. If the database does not support nested transactions, like most of DBMS's, then AnyDAC will emulate nested transactions using savepoints. CommitRetaining is usefull only for main transaction, not for nested ones. 

The CommitRetaining call is the shortcut to Transaction.CommitRetaining, if 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 will use native functionality on IB/FB. On other DBMS's the method will be equal to calls of Commit, then of StartTransaction.

procedure CommitRetaining;
procedure TForm1.DoThatButtonClick(Sender: TObject);
begin
  ADConnection1.StartTransaction;
  try
    if CustomerQuery.Locate('ID', [100]) then begin
      CustomerQuery.Edit;
      CustomerQuery.FieldByName('status').AsString := 'top';
      CustomerQuery.Post;
      ADConnection1.ExecSQL('delete from debt where CustID = 100');
      ADConnection1.CommitRetaining;
    end;
  except
    ADConnection1.RollbackRetaining;
    raise;
  end;
end;
What do you think about this topic? Send feedback!