FairCom Corporation


F.5 AddRecord


Add a new fixed-length data record and corresponding key values to ISAM files.

SHORT NAME

ADDREC

TYPE

ISAM function fixed length record

DECLARATION

COUNT AddRecord(COUNT datno, pVOID recptr)

DESCRIPTION

AddRecord adds the fixed-length data record pointed to by recptr to data file number datno. It automatically adds the key values defined for the data file to their respective index files. If successful, the new data record becomes the current ISAM record for data file datno.

In multi-user applications, AddRecord automatically causes a data record lock to be placed on the new record. Therefore, LockISAM(ctENABLE) and LockISAM(ctFREE) should be called before and after AddRecord. However, with transaction processing locks are enabled and freed using Begin and Commit. LockCtData(ctFREE) can also be used if the record offset is known, to provide individual record lock control. Optionally, the SetOperationState status_word OPS_UNLOCK_ADD automatically unlocks after each AddRecord.

RETURN

Value
Symbolic Constant
Explanation
0
NO_ERROR
Successful addition of a new data record.
2
KDUP_ERR
Duplicate key value found in index file number isam_fil. Data record not added and no key values inserted.
31
DELFLG_ERR
Attempt to re-use data record whose first byte is not set to ff (hex). Either the data file is corrupted,, in which case you should rebuild the ISAM files,, or the C255 constant defined in ctcmpl.h is not set properly.
33
DNUL_ERR
recptr is null. No action taken.
37
WRITE_ERR
Most likely disk or directory is full. Files are left in an indeterminate state and should be rebuilt.
48
FMOD_ERR
datno is assigned to a variable record length file.
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 Appendix A "c-tree Plus Error Codes" of the c-tree Plus Programmer's Reference Guide for a complete listing of valid c-tree Plus error values.

EXAMPLE

COUNT invfil
struct invd {
TEXT delflg;
LONG part_no;
TEXT part_name[60];
LONG on_hand;
} recbuf;
scanf("%ld %59s %ld",&recbuf.part_no,recbuf.part_name, &recbuf.on_hand);
recbuf.delflg = '\0'; /* clear delete flag */
if (LockISAM(ctENABLE) || AddRecord(invfil,&recbuf) ||
LockISAM(ctFREE))
printf("\nAddRecord error %d in file %d",
isam_err,isam_fil);

SEE ALSO

The Chapter 5 "ISAM Functions" of the c-tree Plus Programmer's Reference Guide discusses how the relationship among the data files and their corresponding index files is specified. Begin, Commit, LockCtData, LockISAM, and SetOperationState.


FairCom Corporation
www.faircom.com