Contents Index Using the encryption key on the Palm Computing Platform Adding synchronization to your application

UltraLite Embedded SQL User's Guide
  Adding Non Data Access Features to UltraLite Applications
    Configuring and managing database storage

Defragmenting UltraLite databases


The UltraLite store is designed to efficiently reuse free space, so explicit defragmentation is not required under normal circumstances. This section describes a technique to explicitly defragment UltraLite databases, for use by applications with extremely strict space requirements.

UltraLite provides a defragmentation step function, which defragments a small part of the database. To defragment the entire database at once, call the defragmentation step function in a loop until it returns ul_true. This can be an expensive operation, and SQLCODE must also be checked to detect errors (an error here usually indicates a file I/O error).

Explicit defragmentation occurs incrementally under application control during idle time. Each step is a small operation.

For more information, see ULStoreDefragFini function, ULStoreDefragInit function, and ULStoreDefragStep function.

To defragment an UltraLite database

  1. Obtain a p_ul_store_defrag_info information block. For example,

    p_ul_store_defrag_info     DefragInfo;
    //...
    db_init( &sqlca );
    DefragInfo = ULStoreDefragInit( &sqlca );
  2. During idle time, call UlStoreDefragStep to defragment a piece of the database. For example,

    ULStoreDefragStep( &sqlca, DefragInfo );
  3. When complete, dispose of the defragmentation block. For example,

    ULStoreDefragFini( &sqlca, DefragInfo );
Example 

In this embedded SQL sample, defragmentation occurs incrementally under application control during idle time. Each defragmentation step is a small operation.

p_ul_store_defrag_info     DefragInfo;

idle()
{
   for( i = 0; i < DEFRAG_IDLE_STEPS; i++ ){
      ULStoreDefragStep( &sqlca, DefragInfo );
      if( SQLCODE != SQLE_NOERROR ) break;
   }
}

main()
{
   db_init( &sqlca );
   DefragInfo = ULStoreDefragInit( &sqlca );
   //
   // main application code,
   // calls idle() when appropriate...
   //
   ULStoreDefragFini( &sqlca, DefragInfo );
   db_fini( &sqlca );
}

To defragment the entire store at once, you can call ULStoreDefragStepin a loop until it returns ul_true. This can be an expensive operation, and you must check SQLCODE to detect errors such as file I/O errors.


Contents Index Using the encryption key on the Palm Computing Platform Adding synchronization to your application