![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » DBISAM Technical Support » Product Manuals » DBISAM Version 4 Manual for RAD Studio 10.2 (Delphi Win32) » Advanced Topics » Locking and Concurrency |
Locking Model | Description |
Pessimistic | The pessimistic record locking model specifies that a record should be locked when the record is retrieved for editing, which is during a call to the TDBISAMTable or TDBISAMQuery Edit method or during the record retrieval in an UPDATE SQL statement. |
Optimistic | The optimistic locking model specifies that a record should be locked when any record modifications are posted to the table, which is during a call to the TDBISAMTable or TDBISAMQuery Post method or during the record modification in an UPDATE SQL statement. Using an optimistic record locking model for remote sessions removes the possibility that dangling record locks will be left on the database server if the application is terminated unexpectedly. |
Action | Description |
Appending | When adding a record using the Append or Insert method of the TDBISAMTable or TDBISAMQuery component, no record locks are acquired until the record is posted using the Post method of the TDBISAMTable or TDBISAMQuery component. During the posting of a new record, a record lock is implicity acquired by DBISAM on the next available physical record. This record lock will fail only if the entire table is already locked by the same session or a different session. If the record lock fails, then an EDBISAMEngineError exception will be raised. The error code that is given when a record lock fails is 10258 and is defined as DBISAM_RECLOCKFAILED in the dbisamcn unit (Delphi) or dbisamcn header file (C++). |
Editing | When editing a record using the Edit method of the TDBISAMTable or TDBISAMQuery component, a record lock is implicity acquired by DBISAM if the record locking protocol for the session is set to pessimistic (see above). This record lock will fail if the record or entire table is already locked by the same session or a different session. If the record lock fails, then an EDBISAMEngineError exception will be raised. The error code that is given when a record lock fails is 10258 and is defined as DBISAM_RECLOCKFAILED in the dbisamcn unit (Delphi) or dbisamcn header file (C++). If the locking protocol for the session is set to optmistic then the Edit method will not attempt to implicitly acquire a record lock, but will instead wait until the Post method is called to implicitly acquire the record lock. This means that another session is capable of editing the record and posting the changes to the record before the Post method is called. If this occurs, then an EDBISAMEngineError exception will be raised. The error code that is given when a call to the Post method fails because the record has been altered is 8708 and is defined as DBISAM_KEYORRECDELETED in the dbisamcn unit (Delphi) or dbisamcn header file (C++). In such a case you must discard the edited record by calling the Cancel method, call the Refresh method to refresh the record, and begin again with a fresh copy of the record using the Edit method. |
Deleting | When deleting a record using the Delete method of the TDBISAMTable or TDBISAMQuery component, a record lock is implicity acquired by DBISAM. This record lock will fail if the record or entire table is already locked by the same session or a different session. If the record lock fails, then an EDBISAMEngineError exception will be raised. The error code that is given when a record lock fails is 10258 and is defined as DBISAM_RECLOCKFAILED in the dbisamcn unit (Delphi) or dbisamcn header file (C++). If another session edits the record and posts the changes to the record before the Delete method is called, an EDBISAMEngineError exception will be raised. The error code that is given when a call to the Delete method fails because the record has been altered is 8708 and is defined as DBISAM_KEYORRECDELETED in the dbisamcn unit (Delphi) or dbisamcn header file (C++). In such a case you must call the Refresh method to refresh the record and begin again with a fresh copy of the record using the Delete method. |
begin with MyTable do begin LockTable; try { Perform some updates to the table } finally UnlockTable; end; end; end;
begin with MyTable do begin if LockSemaphore(1) then begin try { Perform a batch process } finally UnlockSemaphore(1); end; end; end; end;
This web page was last updated on Thursday, November 16, 2023 at 10:39 AM | Privacy Policy![]() © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |