Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic

Current ISAM Record

When using the ISAM functions, the concept of the current ISAM record for a data file is very important. c-tree remembers the record position of the last data record found for each ISAM data file, as well as information about the ISAM keys for that data record. This last record found is referred to as the current ISAM record.

Many of the ISAM routines use the current ISAM record. For example, DeleteRecord() deletes the current ISAM record, and NextRecord() uses the current record information to help find the next record in key sequential order. If no current ISAM record exists, as happens just after the file is opened, but is required, then the ISAM function returns error code ICUR_ERR (100).

In older versions of c-tree, V4.3 and before, you had to be very careful with record rewrites, ReWriteRecord() and ReWriteVRecord(). c-tree would use your buffer area to determine the ISAM key structure for the current record. If you changed one of the fields that was used as a part of the key, and then rewrote the record, you could damage the index files.

With c-tree you no longer have to be as careful with record rewrites. c-tree keeps its own image of the key fields. In a rewrite, c-tree determines if a key field has changed by comparing the contents of its current key image buffer with your data record buffer. If a key has been changed, the old key is deleted and the new one is added. This is automatically done for ALL indexes relating to this record.

This does not mean that you don’t have to be concerned with ISAM record rewrites. After ReWriteRecord() or ReWriteVRecord(), the current ISAM record is now the updated record. This may cause problems when your application is moving through a file in index sequential order while making updates. If the key field is updated, then the NEW current ISAM record may be substantially behind or ahead of the prior current ISAM record before the update was made. If, after an update, you wish to continue sequentially from the original record, do the following in your application:


Place this function call after your rewrite operation, and before any other ISAM function. This restores the current ISAM record to be the original one before the rewrite.

The same technique may be used with variable-length records. However, the record may move physically within the file if its size is extended during the rewrite. Therefore, it is possible to encounter the record again even if no key segment is changed. It may be necessary to mark scanned records to avoid this issue.

Other functions that access or modify the current ISAM record in c-tree are CurrentFileOffset() and SetRecord().