Retrieving Elements from a Database
The simplest way to retrieve elements from a database is using the DB→get interface. It takes the same five arguments as the DB→put interface:
db: The database handle returned by db_create.
txnid: A transaction ID. In our simple case, we don’t expect to recover the database after an application or system crash, so we aren’t using transactions and will leave this argument NULL.
key: The key item for the key/data pair that we want to retrieve from the database.
data: The data item for the key/data pair that we want to retrieve from the database.
flags: Optional flags that modify the underlying behavior of the DB→get interface.
Here’s what the code to call DB→get looks like:
#include <sys/types.h> #include ...