ReWriteVRecord Rewrite current variable-length ISAM record. Short Name RWTVREC() Type ISAM function Declaration COUNT ReWriteVRecord(COUNT datno, pVOID recptr, VRLEN varlen) Description 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 indices are updated appropriately. The typical ReWriteVRecord() usage is:
Note: Variable-length retrieval functions, such as ReadISAMVData(), GetVRecord(), and NextVRecord(), accomplish these two steps in one function call.
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 Plus 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
See c-tree Plus Error Codes for a complete listing of valid c-tree Plus error values. Example COUNT datno, keyno; VRLEN newlen, varlen; LONG cust_no; TEXT buffer[512];
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(), |
||||||||||||||||||||||||||||||||||||||||||