Page 1 of 1

Rollback Transaction

Posted: Wed 01 Jul 2009 15:41
by Josef Gschwendtner
Hi,
we are in the process of testing IBDAC Suite (v. 3.00.0.4 for Delphi 7)
At the end of this message you can see the code of a short method which does not work as expected.

If I execute the method below and open the table Log afterwards in a new transaction (e.g. with IBExpert) I see an inserted record, which is weird because of the "Rollback" at the end of the method.

What is wrong here?

I hope somebody can enlighten me,
Josef


procedure TForm1.Button2Click(Sender: TObject);
begin
IBCQuery2.Transaction.StartTransaction;
with IBCQuery2 do begin
SQL.Clear;
SQL.Add('Insert into Log(Logpriority, Logcontext, Logmessage)');
SQL.Add(' values (:prio, :context, :message)');
ParamByName('prio').AsInteger := 2;
ParamByName('context').AsString := 'IBDAC';
ParamByName('message').AsString := 'Test 1';
ExecSQL;
end;
IBCQuery2.Transaction.Rollback;
end;

Posted: Thu 02 Jul 2009 08:54
by Plash
You should set AutoCommit property of TIBCConnection or TIBCQuery to False.

When AutoCommit=True, CommitRetaining is performed after each execution.

Posted: Thu 02 Jul 2009 13:25
by Josef Gschwendtner
Hi,

thank you for your quick response.
Yes, with AutoCommit = False the Rollback works, but I think this behavior conflicts with the explanation in IBDAC-help (see below).

Here the text from IBDAC-Help
Class
TCustomIBCDataSet

Syntax
property AutoCommit: boolean;

Remarks
When True and Connection.AutoCommit is True, and Connection.InTransaction is False, each update, insert or delete statement is automatically committed by database server.

-----

The current behavior gives us problems in converting an IBO application to IBDAC, because in IBO, I always could rollback an explicitly started transaction independently from the setting of Autocommit.

Regards,
Josef Gschwendtner

Posted: Fri 03 Jul 2009 09:23
by Plash
Sorry, there is an mistake in the help. We'll fix it in the next IBDAC build.

IBDAC has such behaviour for compatibility with IBX.

You can try to use UniDAC instead of IBDAC. In UniDAC we have made the checking whether a transaction is started explicitly or implicitly, and disable AutoCommit automatically. In IBDAC you need to manually set AutoCommit of the connection component to False after you start a transaction.