#include <db_cxx.h>void *Dbt::get_data() const; void Dbt::set_data(void *);
u_int32_t Dbt::get_size() const; void Dbt::set_size(u_int32_t);
u_int32_t Dbt::get_ulen() const; void Dbt::set_ulen(u_int32_t);
u_int32_t Dbt::get_dlen() const; void Dbt::set_dlen(u_int32_t);
u_int32_t Dbt::get_doff() const; void Dbt::set_doff(u_int32_t);
u_int32_t Dbt::get_flags() const; void Dbt::set_flags(u_int32_t);
Dbt::Dbt(void *data, size_t size); Dbt::Dbt(); Dbt::~Dbt(); Dbt::Dbt(const Dbt &); Dbt::Dbt &operator = (const Dbt &);
This manual page describes the specific details of the Dbt class, used to encode keys and data items in a 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 reference strings of essentially unlimited length. See Database limits for more information.
The Dbt class provides simple access to an underlying data structure, whose elements can be examined or changed using the set_ or get_ methods. The remainder of the manual page sometimes refers to these accesses using the underlying name, e.g., simply ulen instead of Dbt::get_ulen and Dbt::set_ulen.
The constructors set all elements of the underlying structure to zero. The constructor with two arguments has the effect of setting all elements to zero except for the specified data and size elements. In the case where the flags structure element is 0, when being provided a key or data item by the application, the Berkeley DB package expects the data object to point to a byte string of size bytes. When returning a key/data item to the application, the Berkeley DB package will store into the data object a pointer to a byte string of size bytes.
The elements of the structure underlying the Dbt class are defined as follows:
Note that applications can determine the length of a record by setting the ulen to 0 and checking the return value found in size. See the DB_DBT_USERMEM flag for more information.
This element is accessed using Dbt::get_ulen and Dbt::set_ulen.
It is an error to specify both DB_DBT_MALLOC and DB_DBT_USERMEM.
It is an error to specify both DB_DBT_MALLOC and DB_DBT_USERMEM.
For example, if the data portion of a retrieved record was 100 bytes, and a partial retrieval was done using a Dbt having a dlen field of 20 and a doff field of 85, the get call would succeed, the data field would reference the last 15 bytes of the record, and the size field would be set to 15.
If the calling application is doing a put, the dlen bytes starting doff bytes from the beginning of the specified key's data record are replaced by the data specified by the data and size objects. If dlen is smaller than size, the record will grow, and if dlen is larger than size, the record will shrink. If the specified bytes do not exist, the record will be extended using nul bytes as necessary, and the put call will succeed.
It is an error to attempt a partial put using the Db::put method in a database that supports duplicate records. Partial puts in databases supporting duplicate records must be done using a Dbc method. It is an error to attempt a partial put with differing dlen and size values in a recno database with fixed-length records.
For example, if the data portion of a retrieved record was 100 bytes, and a partial put was done using a Dbt having a dlen field of 20, a doff field of 85, and a size field of 30, the resulting record would be 115 bytes in length, where the last 30 bytes would be those specified by the put call.
Retrieved key/data permanence: When using the non-cursor Berkeley DB calls to retrieve key/data items (e.g., Db::get), the memory referenced by the pointer stored into the Dbt is only valid until the next call to Berkeley DB using the Db handle returned by Db::open. (This includes any use of the returned Db handle, including by another thread of control within the process. For this reason, when multiple threads are using the returned DB handle concurrently, either the DB_DBT_MALLOC or DB_DBT_USERMEM flag must be specified for any non-cursor Dbt used for key or data retrieval.) When using the cursor Berkeley DB calls to retrieve key/data items (e.g., Dbc::get), the memory referenced by the pointer into the Dbt is only valid until the next call to Berkeley DB using the Dbc handle returned by Db::cursor.
The Berkeley DB access methods provide no guarantees about key/data byte string alignment, and applications are responsible for arranging any necessary alignment. The DB_DBT_MALLOC and DB_DBT_USERMEM flags may be used to store returned items in memory of arbitrary alignment.
Logical record numbers are 1-based, not 0-based, i.e., the first record in the database is record number 1.