Previous Topic

Next Topic

DeleteRecord

Delete current fixed length ISAM record.

Short Name

DELREC()

Type

ISAM fixed length record function

Declaration

COUNT DeleteRecord(COUNT datno)

Description

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. c-tree Plus tracks and reuses deleted space before expanding the files. To remove all deleted space, compact the file using CompactIFile() or the compact utility, ctcmpc.

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 c-tree Server.

100

ICUR_ERR

No current ISAM record for data file.

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

Example

COUNT        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 “3.3.2 IMPORTANT - Data Record Delete Flag on page 3-7” in the c-tree Plus Programmer’s Reference Guide.