Function DbPack() Foundation

Physically removes records marked as deleted from a file.

Syntax
DbPack() --> NIL
Return

The return value of DbPack() is always NIL.

Description

The database function DbPack() reorganizes a file open in a work area by physically removing all records marked as deleted.

A record is marked as deleted with the function DbDelete() and is unmarked as deleted (the record is recalled) using the function DbRecall(). records with a deletion flag are logically filtered out and made not visible by the command SET DELETED ON. But they can be made visible again using DbRecall(). After DbPack() completes, records can no longer be "undeleted" with DbRecall() since they are physically removed from the file.

If a DBF file has memo fields, the matching DBT file containing the contents of the memo fields is not rebuilt. To reorganize a DBT file, use the function DbExport() or the command COPY TO.

Examples
DbPack()
// The example shows the use of DbPack(). All records 
// marked for deletion are removed from a file. In this 
// example, assume seven records are so marked. 

PROCEDURE Main 
   USE Address EXCLUSIVE 
   ? LastRec()                      // result: 100 

   DbPack() 
   ? LastRec()                      // result: 93 

   USE 
RETURN 
Reorganize memo files

// The example demonstrates how memo files can be reorganized. 
// The file "Address.dbf" contains memo fields whose contents 
// are stored in the file "Address.dbt". The records are 
// copied into a temporary file. The original files are 
// renamed as a backup copy and the temporary files are renamed 
// prior to the end of the program. 
PROCEDURE Main 
   LOCAL lDeleted := Set( _SET_DELETED, .T. ) 
                                    // set/save deleted flag 
   DbUseArea(.T.,, "Address" )      // open DBF and DBT file 
   DbGoTop()                        // select first, not 
                                    // deleted record 
   DbExport( "Temp" )               // export records 

   DbCloseArea()                    // create backup copies 
   FRename( "Address.dbf", "Address.bak" ) 
   FRename( "Address.dbt", "Address.tbk" ) 

                                    // rename temporary files 
   FRename( "Temp.dbf", "Address.dbf" ) 
   FRename( "Temp.dbt", "Address.dbt" ) 
   Set( _SET_DELETED, lDeleted ) 
RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.