AnyDAC
ContentsIndexHome
PreviousUpNext
TADCustomTransaction.Rollback Method

Cancels all modifications to the data made in the current transaction and optionally ends transaction.

Group
Links

Call Rollback to cancel all modifications, like a INSERT's / UPDATE's / DELETE's, made in current transaction to the database. 

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. 

Before calling Rollback, an application may check the status of the Active property. If an application calls Rollback and there is no current transaction, an exception is raised. 

Rollback call on Interbase / Firebird will close and unprepare all datasets and commands, associated with this transaction object. On some other DBMS's a call will invalidate all active result sets. For example, on MS SQL Server 2005.

procedure Rollback;
procedure TForm1.ChangeButtonClick(Sender: TObject);
begin
  ADQuery1.Transaction := ADTransaction1;
  ADQuery1.SQL.Text := 'update employees set salary = salary * :k where id = :id';
  ADTransaction1.StartTransaction;
  try
    ADQuery1.ExecSQL('', [1.2, 100]);
    ADQuery1.ExecSQL('', [1.3, 200]);
    ADTransaction1.Commit;
  except
    ADTransaction1.Rollback;
    raise;
  end;
end;
What do you think about this topic? Send feedback!