Tutorial

Deleting Data

The API function ups_db_erase deletes a Database item. It receives four parameters: a Database handle, a Transaction handle, the key of the item which will be deleted and flags. The flags are currently not used and should be set to NULL.

The second parameter of ups_db_erase is a Transaction handle; if you do not use Transactions, then set this parameter to NULL. Transactions are covered in a later chapter.

ups_status_t
ups_db_erase(ups_db_t *db, ups_txn_t *txn, ups_key_t *key, uint32_t flags);

API reference for ups_db_erase

The following example deletes the item with the key color

ups_status_t st;
// key length is strlen("color") + 1 (including zero byte)
ups_key_t key = ups_make_key((void *)"color", 6);

if ((st = ups_db_erase(db, NULL, &key, 0)) != UPS_SUCCESS) {
  printf ("error %d (%s)\n", st, ups_strerror (st));
  exit (–1);
}

If you followed the tutorial, the item “color”/“green” is now deleted from the Database. A subsequent ups_db_find (covered in the next chapter) on that value will fail with UPS_KEY_NOT_FOUND.

If you try to delete an item which does not exist, upscaledb will return UPS_KEY_NOT_FOUND.