AutoCommit behaviour?

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
tsteinmaurer
Posts: 52
Joined: Thu 17 Dec 2009 08:25

AutoCommit behaviour?

Post by tsteinmaurer » Thu 17 Dec 2009 08:29

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

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Thu 17 Dec 2009 08:53

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.

tsteinmaurer
Posts: 52
Joined: Thu 17 Dec 2009 08:25

Post by tsteinmaurer » Thu 17 Dec 2009 09:00

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

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Fri 18 Dec 2009 10:54

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.

ralfiii
Posts: 25
Joined: Wed 16 Mar 2011 09:25

Unclear AutoCommit docu

Post by ralfiii » Wed 16 Mar 2011 13:31

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

tsteinmaurer
Posts: 52
Joined: Thu 17 Dec 2009 08:25

Post by tsteinmaurer » Wed 23 Mar 2011 19:32

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

AndreyZ

Post by AndreyZ » Fri 25 Mar 2011 09:37

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.

Post Reply