Yo trabajo con TFDQuery contra una base de datos Firebird, pero supongo que es más o menos lo mismo...
Código Delphi
[-]
function DameTransactionRO(BaseDeDatos: TFDConnection; Iniciar: Boolean = False): TFDTransaction;
begin
Result := TFDTransaction.Create(BaseDeDatos);
with Result do
begin
Connection := BaseDeDatos;
Options.AutoCommit := True;
Options.DisconnectAction := xdCommit;
Options.Isolation := xiReadCommitted;
Options.ReadOnly := True;
if Iniciar and (not Result.Active) then
StartTransaction;
end;
end;
function DameTransactionRW(BaseDeDatos: TFDConnection; Iniciar: Boolean = False): TFDTransaction;
begin
Result := TFDTransaction.Create(BaseDeDatos);
with Result do
begin
Connection := BaseDeDatos;
Options.AutoCommit := True;
Options.DisconnectAction := xdRollback;
Options.Isolation := xiSnapshot;
Options.ReadOnly := False;
if Iniciar and (not Result.Active) then
StartTransaction;
end;
end;
function DameQueryRO(AOwner: TComponent; BaseDeDatos: TFDConnection): TFDQuery;
begin
Result := TFDQuery.Create(AOwner);
with Result do
begin
Connection := BaseDeDatos;
Transaction := DameTransactionRO(BaseDeDatos, True);
end;
end;
function DameQueryRW(AOwner: TComponent; BaseDeDatos: TFDConnection): TFDQuery;
begin
Result := TFDQuery.Create(AOwner);
with Result do
begin
Connection := BaseDeDatos;
Transaction := DameTransactionRW(BaseDeDatos, True);
end;
end;
TDM = class(TDataModule)
DB: TFDConnection;
[...]
procedure TDM.RegistraEntrada;
begin
with DameQueryRW(Self, DB) do
begin
try
SQL.Text := 'EXECUTE PROCEDURE LOG_ENTRADAS (:ID_USUARIO)';
ParamByName('ID_USUARIO').AsInteger := Entorno.IdUsuario;
ExecSQL;
Close;
Transaction.Commit;
finally
Free;
end;
end;
end;