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;');
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!)