Chapter 4.  The DBT Handle

#include <db.h>

    typedef struct {
        void *app_data;
        void *data;
        u_int32_t size;
        u_int32_t ulen;
        u_int32_t dlen;
        u_int32_t doff;
        u_int32_t flags;
    } DBT;

 

Storage and retrieval for the DB access methods are based on key/data pairs. Both key and data items are represented by the DBT data structure. (The name DBT is a mnemonic for data base thang, and was used because no one could think of a reasonable name that wasn't already in use somewhere else.) Key and data byte strings may refer to strings of zero length up to strings of essentially unlimited length. See Database limits for more information.

All fields of the DBT structure that are not explicitly set should be initialized to nul bytes before the first time the structure is used. Do this by declaring the structure external or static, or by calling the C library routine memset(3).

By default, the flags structure element is expected to be set to 0. In this default case, when the application is providing Berkeley DB a key or data item to store into the database, Berkeley DB expects the data structure element to point to a byte string of size bytes. When returning a key/data item to the application, Berkeley DB will store into the data structure element a pointer to a byte string of size bytes, and the memory to which the pointer refers will be allocated and managed by Berkeley DB. Note that using the default flags for returned DBTs is only compatible with single threaded usage of Berkeley DB.

The elements of the DBT structure are defined as follows:

DBT and Bulk Operations