FireDAC.Comp.Client.TFDCustomConnection.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 TFDCustomConnection

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 those caused by the INSERT, UPDATE, or DELETE command, 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 of DBMSs, then FireDAC will emulate nested transactions using savepoints. 

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

A Rollback call on InterBase / Firebird closes and unprepares all the datasets and commands associated with this transaction object. On some other DBMSs (for example, on MS SQL Server 2005), a Rollback call invalidates all the active result sets. To force FetchAll on active datasets, use the ReleaseClients method. 

The Rollback call is the shortcut to Transaction.Rollback, if the Transaction property is assigned. Otherwise, Rollback operates on the default connection transaction.

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;

See Also

Samples