Product Documentation

c-treeDB API for C# - Developers Guide

Previous Topic

Next Topic

CTTable.Rebuild

Declaration

CTTable.Rebuild(CTREBUILD_MODE mode);

Description

  • See AlsoHandle [IN] Table handle
  • mode [IN] The following modes are available:

    CTREBUILD Mode

    Description

    CTREBUILD_NONE

    The normal rebuild mode.

    CTREBUILD_PURGEDUP

    Purge duplicate records during rebuild.

    CTREBUILD_UPDATEIFIL

    Update the IFIL structure in the table.

    CTREBUILD_DATAONLY

    Rebuild only the datafile.

    CTREBUILD_COMPACT

    Compact and rebuild.

Note: Exercise care when using CTREBUILD_DATAONLY and CTCREBUILD_UPDATEIFIL modes together as the index files will be removed from the table IFIL definition even if the index files still exist in the file system. This can cause later problems if Alter() is called to recreate the removed indexes.

Rebuild() calls the FairCom DB CTRBLIFILX() function to rebuild a c-tree table. When used in conjunction with the open modes CTOPEN_CORRUPT and CTOPEN_DATAONLY, the Rebuild() function can be used as a direct replacement for the c-tree Plus ctrbldif rebuild utility.

The following steps are performed by c-treeDB during a table rebuild process:

  1. If a transaction is active, and the table being rebuilt was created with CTCREATE_TRNLOG or CTCREATE_PREIMG, the transaction is committed before the table is rebuilt, and the transaction is restarted after the table rebuild process is completed.
  2. The update corrupt flag, updflg, of the header of the data file is cleared.
  3. The internal delete stack chain of fixed-length data files or the internal delete management index of variable length data files are rebuilt.
  4. The existing index files are removed and new index files are rebuilt over the existing files, optimized for both size and speed.

You must open the table before Rebuild() is executed. It is recommended that the table be opened with CTOPEN_EXCLUSIVE mode. If the table is corrupt, you will need to open the table with the CTOPEN_CORRUPT mode and then call Rebuild() to rebuild the data and index files. If there are missing or corrupt index files, open the table with CTOPEN_DATAONLY mode and Rebuild() will reconstruct the missing index files.

There may be situations when you need to invoke this function to rebuild only the data file. After the data file rebuild is successful, you may need to call Rebuild() again to rebuild the index files.

Return Values

Check CTExecption for DUPJ_ERR (650, Duplicate keys purged and logged) that may be returned.

See Also

Alter()

TOCIndex