Previous Topic

Next Topic

CompactIFile

Compresses a data file, then rebuilds to regenerate the indices.

Short Name

CMPIFIL()

Type

ISAM function

Declaration

COUNT CompactIFile(pIFIL ifilptr)

Description

CompactIFile() removes any deleted records from the data file pointed to by ifilptr. Up to twice the data file size is needed to perform this operation. This function calls RebuildIFile to rebuild the associated indices. CompactIFile() produces a compressed data file containing only active records and new optimized indices. By calling this function, remote client processes can compact and rebuild files in the client/server model.

InitISAM() must be called prior to calling CompactIFile(). The file(s) pointed to by ifilptr must be closed at the time of the call to CompactIFile().

CompactIFile() also supports two features that the file rebuild function RebuildIFile() supports:

  • Purging of records having illegal duplicate keys.
  • Updating the IFIL resource in the data file with the IFIL and IIDX and ISEG structure definitions passed to CompactIFile().

These features are used in the same way they are used when calling RebuildIFile():

  • To instruct the compact operation to purge records containing illegal duplicate keys, set the purgeIFIL mode in the tfilno member of the IFIL structure passed to CompactIFile().
  • To instruct the compact operation to update the IFIL resource in the data file with the structure definitions passed to CompactIFile(), set the updateIFIL mode in the tfilno member of the IFIL structure passed to CompactIFile().
  • To specify both options, add both modes to the tfilno member of the IFIL structure. For example:
   myifil.tfilno = updateIFIL + purgeIFIL;

While it is possible to rebuild a mirrored file in c-tree, it is not possible to compact such a file.

Return

A zero (0) return indicates successful operation. A non-zero return indicates an error, check isam_err. The error returns are similar OpenCtFile() and RebuildIFile(). See “c-tree Plus Error Codes” in the c-tree Plus Programmer’s Reference Guide for a complete listing of valid c-tree Plus error values.

Example

extern IFIL    customer;
       COUNT   retval;

main() {
    if (retval = InitISAM(10,10,16))
        printf("\nInitISAM error = %d",retval);

if (!(CompactIFile(&customer)))
        printf("\nSuccessful compact");
    else
        printf("\nCompactIFile isam_err = %d",isam_err);

CloseISAM();
}

Limitations

CompactIFile() does not support c-tree Plus Superfiles, see Superfiles in the c-tree Plus Programmer’s Reference Guide.

See also

CompactIFileXtd(), InitISAM(), OpenCTFile(), RebuildIFile()