Transactions and queries - how to...

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
GVCL
Posts: 17
Joined: Tue 09 Dec 2008 16:08

Transactions and queries - how to...

Post by GVCL » Tue 09 Dec 2008 16:34

Hi,

I have worked with the BDE for a long time and we used the IB components from Borland. We now want to use the IBCs.

When we started we tried to test a 'deep' master-detail relation: a master and 4 linked details in deep(master-detail-detail-detail-detail). We put a DBConnection, a DBTransaction and the linked queries (and some tables too) on the DataModule. When we updated data in one of the queries and posted them, all queries (and tables) of the DBConnection closed.

So I read some of the posts here and read very often, that e.g. we should use 2 transcations - one for reading and one for writing and one for each query or so. Is this true??? That would mean, that we are not able to convert our BDE based applications to IBC based application easily...even with the test apps we could not - in an easy way - update data and have the not concerned queries and tables active.

And how to apply 2 transactions to a query? Do we have to connect and reconnect these transactions programmatically for each dataset??? Is this really the way we have to do it? This would mean a lot more work for a simple application which only shows some linked data and allows to update at any level.

Is there any example of how to do this the way the IBCs exspect it?

Any hints appreciated!

Gerhard

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

Post by Plash » Wed 10 Dec 2008 08:45

Probably your queries are closed because you call the Commit method. You don't need to call this method after a post because TIBCQuery has the AutoCommit property that is True by default. When you post a record CommitRetaining is called automatically. You can also call the CommitRetaining method yourself instead of Commit. In this case your queries remain opened.

If you want to use two transactions, drop the TIBCTransaction component on the form. Then assign it to the UpdateTransaction property of each TIBCQuery component. You can do it at design time. TIBCQuery components will use this transaction to post data. Set the IsolationLevel property of the read transaction (DefaultTransaction of TIBCConnection or another TIBCTransaction component) to iblReadOnlyReadCommited.

It is not required to use two transaction in your case. Just do not call the Commit method.

GVCL
Posts: 17
Joined: Tue 09 Dec 2008 16:08

Post by GVCL » Wed 10 Dec 2008 11:26

Thank you!

This is what we thought for the 'simple' case, but were not sure...and yes, we did a Commit - which causes the 'strange' behaviour.

But what, when we have to update several tables in a transaction? We understand, we have to put one TIBCTransaction on the form and assign it to the UpdateTransaction of all queries/tables concerned. Is this right? And then as usual StartTransaction and Commit (or Rollback resp.)? This will only include the queries and tables which have the Transaction assigned?

Ok, we will see - it is a little different to the BDE etc. but we are sure it is worth the work. :wink:

Gerhard

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

Post by Plash » Thu 11 Dec 2008 13:23

Yes, you are right. You can put the TIBCTransaction component and use it to update tables.

Post Reply