FireDAC.Comp.Client.TFDCustomTransaction.Rollback

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure Rollback;

C++

void __fastcall Rollback();

Properties

Type Visibility Source Unit Parent
procedure
function
public
FireDAC.Comp.Client.pas
FireDAC.Comp.Client.hpp
FireDAC.Comp.Client TFDCustomTransaction

Description

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

Call Rollback to cancel all modifications, such as INSERT / UPDATE / DELETE commands, made in the current transaction to the database. 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. 

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 DBMSs, a call will invalidate all active result sets (for example, on MS SQL Server 2005).

Example

procedure TForm1.ChangeButtonClick(Sender: TObject);
begin
  FDQuery1.Transaction := ADTransaction1;
  FDQuery1.SQL.Text := 'update employees set salary = salary * :k where id = :id';
  FDTransaction1.StartTransaction;
  try
    FDQuery1.ExecSQL('', [1.2, 100]);
    FDQuery1.ExecSQL('', [1.3, 200]);
    FDTransaction1.Commit;
  except
    FDTransaction1.Rollback;
    raise;
  end;
end;

See Also