Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic

ReWriteRecord

Rewrite current fixed-length ISAM record.

Short Name

RWTREC()

Type

ISAM function

Declaration

COUNT ReWriteRecord(FILNO datno, pVOID recptr)

Description

In V12 the file number typedef was formally changed from COUNT, a two-byte value to FILNO, a four-byte value. Refer to this link for compatibility details. Four Byte File Numbering

ReWriteRecord() allows changes to be made in the current ISAM record for fixed-length data records belonging to data file number datno. recptr should point to the updated version of the current ISAM record. ReWriteRecord() assumes that the current ISAM record is the original version. After successful completion of ReWriteRecord(), the updated version is now stored in the data file and all necessary changes to the key values associated with the updates are automatically made.

The typical ReWriteRecord() usage is:

  • First, an ISAM retrieval function, (e.g., ReadISAMData(), GetRecord() or NextRecord()), reads the desired record, making it the current ISAM record.
  • Updates are made to the record buffer.
  • ReWriteRecord() rewrites the updated record, making the updated record the current ISAM record. If any of the key fields have been changed, the old key is removed from the appropriate indexes, and the new one is added.

Unlike c-tree version 4.3 and older, you do not have to be careful about making changes to the current record in your buffer. c-tree maintains its own copy of the current ISAM record key information and position.

Multi-user updates are more complex because of the possibility of either locking out the record for prolonged periods, or because of two users trying to update the same record at the same time. See Multi-User Concepts in the c-tree Programmer’s Reference Guide for a detailed discussion of multi-user updates.

ReWriteRecord() does not change the automatic serial number key segments, if any. If you want the serial number updated, delete the old record and add the updated record.

To make the old record the current ISAM record, so that NextRecord() will be performed relative to the position before the update, make the following call after successfully completing the record rewrite:

ResetRecord(datno,SWTCURI);

Return

Value

Symbolic Constant

Explanation

0

NO_ERROR

Successful record update. New record becomes the current ISAM record.

2

KDUP_ERR

Duplicate key value detected in index file number isam_fil. Record update not performed.

22

FNUM_ERR

File number is out of range.

26

FACS_ERR

File number is not assigned to a file in use.

48

FMOD_ERR

datno is not assigned to a fixed length data file.

57

DADV_ERR

Proper lock not found by the c-tree.

100

ICUR_ERR

No current ISAM record.

105

IUND_ERR

Could not undo a rejected ISAM update. Unless the files support transaction processing, this is a serious error indicating the data file must be rebuilt.

199

NSCH_ERR

Key segment refers to schema, but schema not defined.

433

SSCH_ERR

Segment definition inconsistent with schema.

445

SDAT_ERR

Not enough data to assembly key.

446

BMOD_ERR

Invalid key mode.

See c-tree Error Codes for a complete listing of valid c-tree error values.

Example

FILNO datno,keyno;

LONG cust_no;

TEXT buffer[128];


printf("\nEnter customer number: ");

scanf("%ld",&cust_no);

if (GetRecord(keyno,cust_no,buffer)) /* read current record */

printf("\nCould not read customer record.");

else {

update(buffer); /* make your changes to buffer */

if (ReWriteRecord(datno,buffer))

printf("\nCould not rewrite customer record.");

else

printf("\nSuccessful update of customer record.");

}


Limitations

After a call to ReWriteRecord(), the current ISAM record is set to the new record. This may create a situation that you don’t expect when ReWriteRecord() is used inside a loop that steps over the data in key sequential order. If the key value is changed during the update, the current ISAM record position will skip to the new position, which may be before or after the original position. To avoid this situation, reset the current ISAM record after ReWriteRecord() using ResetRecord().

See also

ReadISAMData(), GetRecord(), NextRecord(), ResetRecord()

TOCIndex