Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic

ReWriteVRecord

Rewrite current variable-length ISAM record.

Short Name

RWTVREC()

Type

ISAM function

Declaration

COUNT ReWriteVRecord(FILNO datno, pVOID recptr, VRLEN varlen)

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

ReWriteVRecord() allows changes to be made in the current variable-length ISAM record for data file number datno. recptr should point to the updated version of the current ISAM record, and varlen specifies the length of the updated version. ReWriteVRecord() assumes that the current ISAM record is the original version. After successful completion of ReWriteVRecord(), 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. If the updated version does not fit into the space available for the current record, it is moved to another location in the data file. All associated indexes are updated appropriately.

The typical ReWriteVRecord() usage is:

  • First, an ISAM retrieval function, (e.g., GetRecord() or NextRecord()), reads the fixed portion of desired record, making it the current ISAM record.
  • ReReadVRecord() reads the entire record into the buffer. This buffer now contains the entire current ISAM record.

Note: Variable-length retrieval functions, such as ReadISAMVData(), GetVRecord(), and NextVRecord(), accomplish these two steps in one function call.

  • Updates are made to the record buffer.
  • ReWriteVRecord() 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.

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.

ReWriteVRecord() does not change the automatic serial number key segments, if any. To update the serial number, 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 variable-length data file.

57

DADV_ERR

Proper lock not found by the FairCom Server.

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;

VRLEN newlen, varlen;

LONG cust_no;

TEXT buffer[512];


printf("\nEnter customer number: ");

scanf("%ld",&cust_no);

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

|| ReReadVRecord(datno,buffer,512))

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

else {

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

if (ReWriteVRecord(datno,buffer,newlen))

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

else

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

}

Limitations

After a call to ReWriteVRecord(), the current ISAM record is set to the new record. This may create a situation that you don’t expect when ReWriteVRecord() 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 ReWriteVRecord() using ResetRecord().

See also

GetRecord(), NextRecord(), ReReadVRecord(), ReadISAMVData(), GetVRecord(),
NextVRecord(), ResetRecord()

TOCIndex