FireDAC.Comp.Client.TFDCustomTransaction.Commit

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure Commit;

C++

void __fastcall Commit();

Properties

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

Description

Permanently stores modifications to the data made in the current transaction, and optionally ends the current transactions.

Call Commit to permanently store 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 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 Commit, an application may check the status of the Active property. If an application calls Commit and there is no current transaction, an exception is raised. 

A Commit 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 := FDTransaction1;
  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