TZConnection is always in transaction state

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Artem_
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 13.11.2013, 08:54

Re: TZConnection is always in transaction state

Post by Artem_ »

Hi. To get explicit transactions control im using another way:
ZDBConnection1.Autocommit:false
I call server to start transaction before any edits starting

Code: Select all

{before opening some editor form}
ZDBConnection1.ExecuteDirect('START TRANSACTION;');
after this you should execute query to lock required object
using SELECT FOR UPDATE NOWAIT or LOCK [ TABLE ] NOWAIT;
executing that queries should be inside try-except block
If you caught exception - it mean that another user locked it
before you. In this way you should call
ZDBConnection1.ExecuteDirect('ROLLBACK;'); to cancel waste
transaction and prevents exceptions
Btw if all OK you are free to do any editing using edit-insert-post metods
Now to save all edited data you need to execute
ZDBConnection1.ExecuteDirect('COMMIT;'); at editing end.
Remember that things:
1. Till you called SQL Commit or Rollback another users will freeze trying to edit same rows(tables), that was locked. So you should check records(table) with NOWAIT SQL option
before try to edit it. If objects were locked - the exception will raise, not application freezes.
2. Calling post/applyUpdates and others DataSets methods would not affect physical database until you call COMMIT SQL commend
3. DBConnection method StartTransaction, Commit, and Rollback will do nothing in this way
Sorry for mistakes. Im NOT Englishman)
Cheer!)
Post Reply