Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic

Begin Transactions - Begin()

You will need to decide on logical groups of file updates that can be delimited as transactions. Record locks are held on updated records for the duration of the transaction, so you don’t want to make the transaction group too large. On the other hand, you do not want to make the transaction group too small. You must contain all of the related updates in one transaction. Using our example from above, you don’t want to have the transaction group involve more than one invoice. You also don’t want it to involve less than a whole invoice.

To begin a transaction make the following call to the Begin() function:

Begin(ctTRNLOG | ctENABLE);

The ctENABLE parameter eliminates the need for a call to LockISAM(). A LockCtData() call attempting to unlock a record that is part of transaction returns NO_ERROR (0), but sets sysiocod to UDLK-TRN (-3), indicating the lock will be held until the end of the transaction.

Begin

You use the Begin() function to mark the beginning of the transaction. This function will return a transaction number that you may want to use in some situations. You will pass a mode to Begin, which can be either ctTRNLOG or ctPREIMG.

The file modes of all files updated during a transaction must be compatible with the mode used in the Begin() call.

  • If the Begin() mode is ctPREIMG, all files updated during the transaction must have been created with a file mode of ctPREIMG, or no transaction processing at all. If an updated file was created with a file mode of ctTRNLOG then the update will return the TTYP_ERR (99) error code. You cannot skip transaction logging if the files have been set up for transaction logging.
  • If the Begin() mode is ctTRNLOG, transaction logging for a file will not take place if the file was created with a file mode of ctPREIMG or no transaction mode at all.

If you created a file with a file mode of ctTRNLOG, then you must use ctTRNLOG with your call to Begin() (if the file is to be updated during the transactions).

There are other values that you can OR in with the transaction mode.:

  • ctENABLE: Automatically invokes LockISAM( ctENABLE ) for all records in the transaction.
  • ctREADREC: Automatically invokes LockISAM( ctREADREC ) for all records in the transaction.
  • ctLK_BLOCK: Used in addition to ctENABLE or ctREADREC converts them to ctENABLE_BLK or ctREADREC_BLK, respectively.

ctSAVENV: With this mode, each Begin() and SetSavePoint() saves the current ISAM record information so a subsequent Abort() or RestoreSavePoint() automatically restores the current ISAM record information.

TOCIndex