Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic

DeleteRecord

Delete current fixed-length ISAM record.

Short Name

DELREC()

Type

ISAM fixed-length record function

Declaration

COUNT DeleteRecord(FILNO datno)

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

DeleteRecord() deletes the current fixed-length ISAM record for data file datno. If the data record is successfully deleted, DeleteRecord() updates all associated index files and returns the data record to the pool of available records for data file datno. After the deletion, the current ISAM record information stays unchanged! That is, even though the current record has just been deleted, the information in the current ISAM buffer is not disturbed so that you can scan in either direction through the data via the NextRecord() or PreviousRecord() routines.

In multi-user systems, invoke LockISAM(ctENABLE) before the ISAM routine which reads the record to be deleted. Call LockISAM(ctFREE) after DeleteRecord() to release the locks. See the example below.

DeleteRecord() does not shrink the files. FairCom DB tracks and reuses deleted space before expanding the files. To remove all deleted space, compact the file using CompactIFile().

Return

Value

Symbolic Constant

Explanation

0

NO_ERROR

Successful ISAM deletion. Current ISAM record remains unchanged.

4

KDEL_ERR

Could not delete key value.

48

FMOD_ERR

datno is 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 for data file.

See FairCom DB Error Codes for a complete listing of valid FairCom DB error values.

Example

FILNO invfil, part_no_idx;

LONG part_key;


struct invd {

TEXT delflg[4];

LONG part_no;

TEXT part_name[60];

} recbuf;


printf("\nEnter part number to delete: ");

scanf("%ld",&part_key);

if (LockISAM(ctENABLE))

printf("\nCould not enable locks.");

else if (GetRecord(part_no_idx, &part_key, &recbuf))

printf("\nCould not get PART #%ld (%d %d).",

part_key, isam_err, isam_fil);

else if (DeleteRecord(invfil))

printf("\nCould not delete PART #%ld (%d %d).",

part_key, isam_err, isam_fil);


LockISAM(ctFREE);

Limitations

DeleteRecord() causes the first byte of the data record to be set to FF (hex) as a delete flag. This flag is tested by all ISAM functions which read a data record. If the first byte is equal to FF (hex), an IRED_ERR (114) error is returned. The delete flag is also used by the rebuild utility to determine if a record is deleted. When you define your data record structure, the most straightforward approach is to reserve the first byte of the data record for the delete flag. You may store data in the first byte as long as the data will never be equal to FF (hex).

Fixed-length data files with RESOURCES enabled use the first byte to indicate the presence of a resource record. A byte value of FE (hex) at the beginning of the record indicates a resource record.

See also

DeleteVRecord(), NextRecord, PreviousRecord, CompactIFile, LockISAM and Fixed Length Data Record Delete Flag.

TOCIndex