Database Integrity
ObjectScript provides several commands to help ensure database integrity: Lock, TStart, and TCommit. You need to know about these in preparation for adding deletion and editing capabilities to ObjectScript.Lookup2. In general, you should use them in this way:
-
Select a record for editing.
-
Lock the record.
-
Get the updated data for the record.
-
TStart a transaction.
-
Store the new data.
-
TCommit the transaction.
-
UnLock the record.
You use the Lock command to prevent multiple processes from updating the same record at the same time. But it only works by convention: all the code throughout an application that updates a given global must try to Lock the record that is to be updated, and unLock it when finished. If one method uses Lock, but another doesn't, nothing prevents the second method from updating the record while the first method has it locked.
You use the TStart and TCommit commands to protect database transactions. A transaction is simply a series of Set and/or Kill commands on the database. You need to ensure that an entire transaction completes, or that none of it completes. This guarantees that all the globals in a transaction (for both data and indexes, for example) remain in sync.