Chapter 4.  The Dbt Handle

#include <db_cxx.h>

class Dbt { 
public: 
        Dbt(void *data, size_t size); 
        Dbt(); 
        Dbt(const Dbt &); 
        Dbt &operator = (const Dbt &); 
        ~Dbt();

        void *get_data() const; 
        void set_data(void *);

        u_int32_t get_size() const; 
        void set_size(u_int32_t);

        u_int32_t get_ulen() const; 
        void set_ulen(u_int32_t);

        u_int32_t get_dlen() const; 
        void set_dlen(u_int32_t);

        u_int32_t get_doff() const; 
        void set_doff(u_int32_t);

        u_int32_t get_flags() const; 
        void set_flags(u_int32_t);

        DBT *Dbt::get_DBT(); 
        const DBT *Dbt::get_const_DBT() const; 
        static Dbt *Dbt::get_Dbt(DBT *dbt); 
        static const Dbt *Dbt::get_const_Dbt(const DBT *dbt); 
}; 

The Dbt class is used to encode key and data items in a Berkeley DB database.

Storage and retrieval for the Db access methods are based on key/data pairs. Both key and data items are represented by Dbt objects. 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.

In the case when the flags structure element is set to 0, when the application is providing Berkeley DB a key or data item to store into the database, Berkeley DB expects the data object 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 object 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.

Access to Dbt objects is not re-entrant. In particular, if multiple threads simultaneously access the same Dbt object using Db API calls, the results are undefined, and may result in a crash. One easy way to avoid problems is to use Dbt objects that are constructed as stack variables.

Each Dbt object has an associated DBT struct, which is used by the underlying implementation of Berkeley DB and its C-language API. The Dbt::get_DBT() method returns a pointer to this struct. Given a const Dbt object, Dbt::get_const_DBT() returns a const pointer to the same struct.

Given a DBT struct, the Dbt::get_Dbt() method returns the corresponding Dbt object, if there is one. If the DBT object was not associated with a Dbt (that is, it was not returned from a call to Dbt::get_DBT()), then the result of Dbt::get_Dbt() is undefined. Given a const DBT struct, Dbt::get_const_Dbt() returns the associated const Dbt object, if there is one.

These methods may be useful for Berkeley DB applications including both C and C++ language software. It should not be necessary to use these calls in a purely C++ application.

DBT and Bulk Operations