Tutorial

Closing Databases

Database handles are closed with ups_close. This function implicitly flushes the Database, writes the modified file to disk and closes the file handle. If you forget to call this function you will lose your data and the Database may be corrupted.

Prior to closing a Database, all Transactions and Cursors of this Database must be closed. Transactions can be aborted (or committed) automatically if the flag UPS_TXN_AUTO_ABORT (or UPS_TXN_AUTO_COMMIT respectively) were specified.

Cursors are closed automatically if the flag UPS_AUTO_CLEANUP was specified. Otherwise you have to call ups_cursor_close on each opened Cursor to avoid memory leaks.

ups_status_t
ups_db_close(ups_db_t *db, uint32_t flags);

API reference of ups_db_close

The following snippet closes the Database, and automatically closes all open Cursors.

if ((st = ups_db_close (db, UPS_AUTO_CLEANUP))) {
  printf ("ups_close failed: %d \n", st, ups_strerror(st));
  exit (–1);
}