Page 1 of 1

AutoCommit behaviour?

Posted: Thu 17 Dec 2009 08:29
by tsteinmaurer
Hello,

I have the following code, with AutoCommit := True at TIBCQuery level. The query executes a simple INSERT INTO statement with returning one parameter due to using the RETURNING clause.

Code: Select all

  IBCQuery1.Transaction.StartTransaction;
  try
    IBCQuery1.Execute;
    ShowMessage(IBCQuery1.ParamByName('RET_T1_ID').AsString);
  except
    IBCQuery1.Transaction.Rollback;
  end;
Is it as designed, when starting an explicit transaction with StartTransaction, that AutoCommit of the query still applies, which means, after query execution I do see the inserted record in another application? Any other access components I have used until now will set AutoCommit to false in case of starting an explicit transaction and turns back to AutoCommit = True, when the transaction has been committed or rolled back.

Thanks
Thomas

Posted: Thu 17 Dec 2009 08:53
by Plash
In IBDAC transaction is always started for Execute because InterBase requires an active transaction for executing queries. IBDAC does not distinguish explicit and implicit transaction start. If transaction is already started before Execute, IBDAC uses CommitRetaining to commit changes.

Set the AutoCommit property of TIBCConnection to False to disable autocommit while working in transaction.

Posted: Thu 17 Dec 2009 09:00
by tsteinmaurer
Hello,

but I did start a transaction with:

Code: Select all

IBCQuery1.Transaction.StartTransaction
so there is no need for the query component to start another (?) transaction and commit that behind the scene with CommitRetaining. As said, BDE, IBObjects, ... they all turn AutoCommit Off when the developer starts a transaction with StartTransaction until the transaction gets committed, rolled back with Commit or Rollback.

Thanks,
Thomas

Posted: Fri 18 Dec 2009 10:54
by Plash
The query does not start another transaction. It uses CommitRetaining for the transaction that you have started.

I agree that AutoCommit should be disabled when transaction is started explicitly. We have made such behaviour in our UniDAC product. But we cannot change the behaviour of IBDAC for backward compatibility.

Unclear AutoCommit docu

Posted: Wed 16 Mar 2011 13:31
by ralfiii
I have a problem understanding the docu of the AutoCommit property.

In the help file I read "AutoCommit in TIBCConnection has higher precedence over the same properties in dataset components"

What does that mean? If this property overwrites the AutoCommit in Datasets then there would be no use for that property there.

I get the feeling that an autocommit of a dataset-action is only performed if both the Connection and the Dataset have set this property to True. Or am I wrong?

Thanks,
Ralf

Posted: Wed 23 Mar 2011 19:32
by tsteinmaurer
Ralf,

according to the example in the documentation, your assumption is true.

Interesting that this thread pops up again. I still think, that AutoCommit should be temporarily off for the dataset component behind the scene, in case an explicit transaction has been started for the database.

All access components I know handle it that way. Has that changed in some recent versions? If not, isn't that a big bugger when converting from other products?

Thanks,
Thomas

Posted: Fri 25 Mar 2011 09:37
by AndreyZ
If the TIBCConnection.AutoCommit property is set to True, all queries commit changes using the IBCQuery.AutoCommit (or TIBCTable.AutoCommit) property. If the TIBCConnection.AutoCommit property is set to False, all changes are commited only explicitly.