The Record Access Group contains the API for fetching, storing, and deleting records. More...
Classes | |
struct | mdbm_fetch_info |
Macros | |
#define | MDBM_FETCH_FLAG_DIRTY 0x01 |
Cache entry is dirty. More... | |
#define | MDBM_INSERT 0 |
Insert if key does not exist; fail if exists. More... | |
#define | MDBM_REPLACE 1 |
Update if key exists; insert if does not exist. More... | |
#define | MDBM_INSERT_DUP 2 |
Insert new record (creates duplicate if key exists) More... | |
#define | MDBM_MODIFY 3 |
Update if key exists; fail if does not exist. More... | |
#define | MDBM_STORE_MASK 0x3 |
Mask for all store options. More... | |
#define | MDBM_STORE_MODE(f) ((f) & MDBM_STORE_MASK) |
Extract the store mode from an options mask. More... | |
#define | MDBM_RESERVE 0x100 |
Reserve space; Value not copied. More... | |
#define | MDBM_CLEAN 0x200 |
Mark entry as clean. More... | |
#define | MDBM_CACHE_ONLY 0x400 |
Do not operate on the backing store; use cache only. More... | |
#define | MDBM_CACHE_REPLACE 0 |
Update cache if key exists; insert if does not exist. More... | |
#define | MDBM_CACHE_MODIFY 0x1000 |
Update cache if key exists; do not insert if does not. More... | |
#define | MDBM_CACHE_UPDATE_MODE(f) ((f) & MDBM_CACHE_MODIFY) |
#define | MDBM_STORE_SUCCESS 0 |
Returned if store succeeds. More... | |
#define | MDBM_STORE_ENTRY_EXISTS 1 |
Returned if MDBM_INSERT used and key exists. More... | |
Functions | |
datum | mdbm_fetch (MDBM *db, datum key) |
Fetches the record specified by the key argument and returns a datum that points to the value. More... | |
int | mdbm_fetch_r (MDBM *db, datum *key, datum *val, MDBM_ITER *iter) |
Fetches the record specified by the key argument. More... | |
int | mdbm_fetch_buf (MDBM *db, datum *key, datum *val, datum *buf, int flags) |
Fetches and copies the record specified by the key argument. More... | |
int | mdbm_fetch_dup_r (MDBM *db, datum *key, datum *val, MDBM_ITER *iter) |
Fetches the next value for a key inserted via mdbm_store_r with the MDBM_INSERT_DUP flag set. More... | |
char * | mdbm_fetch_str (MDBM *db, const char *key) |
Fetches a string. More... | |
int | mdbm_fetch_info (MDBM *db, datum *key, datum *val, datum *buf, struct mdbm_fetch_info *info, MDBM_ITER *iter) |
Fetches and copies the record specified by the key argument. More... | |
int | mdbm_delete (MDBM *db, datum key) |
Deletes a specific record. More... | |
int | mdbm_delete_r (MDBM *db, MDBM_ITER *iter) |
Deletes the record currently addressed by the iter argument. More... | |
int | mdbm_delete_str (MDBM *db, const char *key) |
Deletes a string from the MDBM. More... | |
int | mdbm_store (MDBM *db, datum key, datum val, int flags) |
This is a wrapper around mdbm_store_r, with a static iterator. More... | |
int | mdbm_store_r (MDBM *db, datum *key, datum *val, int flags, MDBM_ITER *iter) |
Stores the record specified by the key and val parameters. More... | |
int | mdbm_store_str (MDBM *db, const char *key, const char *val, int flags) |
Stores a string into the MDBM. More... | |
The Record Access Group contains the API for fetching, storing, and deleting records.
#define MDBM_FETCH_FLAG_DIRTY 0x01 |
Cache entry is dirty.
#define MDBM_INSERT 0 |
Insert if key does not exist; fail if exists.
#define MDBM_REPLACE 1 |
Update if key exists; insert if does not exist.
#define MDBM_INSERT_DUP 2 |
Insert new record (creates duplicate if key exists)
#define MDBM_MODIFY 3 |
Update if key exists; fail if does not exist.
#define MDBM_STORE_MASK 0x3 |
Mask for all store options.
#define MDBM_STORE_MODE | ( | f | ) | ((f) & MDBM_STORE_MASK) |
Extract the store mode from an options mask.
#define MDBM_RESERVE 0x100 |
Reserve space; Value not copied.
#define MDBM_CLEAN 0x200 |
Mark entry as clean.
#define MDBM_CACHE_ONLY 0x400 |
Do not operate on the backing store; use cache only.
#define MDBM_CACHE_REPLACE 0 |
Update cache if key exists; insert if does not exist.
#define MDBM_CACHE_MODIFY 0x1000 |
Update cache if key exists; do not insert if does not.
#define MDBM_CACHE_UPDATE_MODE | ( | f | ) | ((f) & MDBM_CACHE_MODIFY) |
#define MDBM_STORE_SUCCESS 0 |
Returned if store succeeds.
#define MDBM_STORE_ENTRY_EXISTS 1 |
Returned if MDBM_INSERT used and key exists.
Fetches the record specified by the key argument and returns a datum that points to the value.
If such a record exists in the database, the size and location (pointer) are stored in the returned datum. If no matching record exists, a null datum (dsize==0, dptr==NULL) is returned.
The contents returned in datum has a pointer to a value in mapped memory. If there is any system-wide process that could modify your MDBM, this value must be accessed in a locked context.
For example, the following is correct code to copy a lookup value for subsequent return:
[in,out] | db | Database handle |
[in] | key | Lookup key |
datum | found, with size and pointer set, on success |
datum | not found, with dsize==0, and dptr==NULL, and errno==ENOENT. errno may have other values for failure (ex., EINVAL). |
Fetches the record specified by the key argument.
If such a record exists in the database, the size and location (pointer) are stored in the datum pointed to by val. If no matching record exists, a null datum (dsize==0, dptr==NULL) is returned.
The contents returned in val is a pointer to a value in mapped memory. If there is any system-wide process that could modify your MDBM, this value must be accessed in a locked context.
For example, the following is correct code to copy a lookup value for subsequent return:
A record can be updated in-place by fetching the value datum, casting the dptr as appropriate, and updating those contents. However, the update must not change the size of the record.
[in,out] | db | Database handle |
[in] | key | Pointer to datum used as the index key |
[out] | val | Pointer to datum returned |
[in,out] | iter | MDBM iterator |
-1 | Error, and errno is set |
0 | Success |
Fetches and copies the record specified by the key argument.
If such a record exists in the database, the size and location are stored in the datum pointed to by val. The same record is also copied into the buf argument. If no matching record exists, a null datum (dsize==0, dptr==NULL) is returned.
Note that a record can be updated in-place by fetching the value datum, casting the dptr as appropriate, and updating the record. However, the update must not change the size of the record.
buf.dptr must point to memory that has been previously malloc'd on the heap. buff.dptr will be realloc'd if is too small.
[in,out] | db | Database handle |
[in] | key | Lookup key |
[out] | val | Lookup value (pointer) |
[in,out] | buf | Copy-out of lookup reference returned in val |
[in] | flags | Reserved for future use |
-1 | Error, and errno is set |
0 | Success |
Fetches the next value for a key inserted via mdbm_store_r with the MDBM_INSERT_DUP flag set.
The order of values returned by iterating via this function is not guaranteed to be the same order as the values were inserted.
As with any db iteration, record insertion and deletion during iteration may cause the iteration to skip and/or repeat records.
Calling this function with an iterator initialized via MDBM_ITER_INIT will cause this function to return the first value for the given key.
[in,out] | db | Database handle |
[in] | key | Pointer to datum used as the index key |
[out] | val | Pointer to datum returned |
[in,out] | iter | MDBM iterator |
-1 | Error, and errno is set |
0 | Success |
char* mdbm_fetch_str | ( | MDBM * | db, |
const char * | key | ||
) |
Fetches a string.
[in,out] | db | Database handle |
[in] | key | Stored key |
Pointer | to string, on success |
NULL | if key does not exist |
int mdbm_fetch_info | ( | MDBM * | db, |
datum * | key, | ||
datum * | val, | ||
datum * | buf, | ||
struct mdbm_fetch_info * | info, | ||
MDBM_ITER * | iter | ||
) |
Fetches and copies the record specified by the key argument.
If such a record exists in the database, the size and location are stored in the datum pointed to by val. The same record is also copied into the buf argument. If no matching record exists, a null datum (dsize==0, dptr==NULL) is returned.
mdbm_fetch_info is only supported by MDBM version 3 or higher.
Note that a record can be updated in-place by fetching the value datum, casting the dptr as appropriate, and updating the record. However, the update must not change the size of the record.
Additional information is passed back in the info argument: entry flags, the number of accesses to cache entry, and the last access time (LRU/LFU only).
buf.dptr cannot point to statically allocated memory. It must point to memory that has been previously malloc'd on the heap.
[in,out] | db | Database handle |
[in] | key | Pointer to datum used as the index key |
[out] | val | Pointer to datum returned |
[out] | buf | Copy found datum into this parameter |
[out] | info | Pointer to additional information (struct mdbm_fetch_info) |
[in,out] | iter | MDBM iterator |
-1 | Error, and errno is set |
0 | Success |
Deletes a specific record.
[in,out] | db | Database handle |
[in] | key | Key to be removed |
-1 | Error, and errno is set |
0 | Success |
Deletes the record currently addressed by the iter argument.
After deletion, the key and/or value returned by the iterating function is no longer valid. Calling mdbm_next_r on the iterator will return the key/value for the entry following the entry that was deleted.
[in,out] | db | Database handle |
[in,out] | iter | MDBM iterator pointing to item to be deleted |
-1 | Error, and errno is set |
0 | Success |
int mdbm_delete_str | ( | MDBM * | db, |
const char * | key | ||
) |
Deletes a string from the MDBM.
[in,out] | db | Database handle |
[in] | key | Stored key |
-1 | Error, and errno is set |
0 | Success |
This is a wrapper around mdbm_store_r, with a static iterator.
[in,out] | db | Database handle |
[in] | key | Stored key |
[in] | val | Key's value |
[in] | flags | Store flags |
-1 | Error, and errno is set |
0 | Success |
1 | Flag MDBM_INSERT was specified, and the key already exists |
Values for flags mask:
Insertion with flag MDBM_MODIFY set will fail if the key does not already exist.
Insertion with flag MDBM_RESERVE set will allocate space within the MDBM for the object; but will not copy it. The caller is responsible for copying the value into the indicated position.
Replacement with flag MDBM_CACHE_MODIFY for a cache with a backing store, has the effect of writing through the cache to the backing store without updating the cache unless that cache entry already exists.
Quick option summary:
NOTE: Ensure that the key and value datum pointers reference storage that is external to the db and not the result of, for example, an mdbm_fetch, mdbm_first, or mdbm_next. A store operation can result in various db internal modifications that invalidate previously returned key and value pointers. Also be aware that mdbm_store_r overwrites key.dptr and val.dptr, so to avoid memory leaks for the case when key.dptr or val.dptr point to malloc-ed or new-ed memory, you should keep a copy of above pointers and deallocate them when done.
NOTE: If you do multiple stores to the same key using MDBM_REPLACE, the corresponding value's location in memory can change after each store. The MDBM_REPLACE flag does not imply that the value will reuse the same location. Even if you store a smaller value for an existing key, it probably won't reuse the existing value's location. In the current implementation, the only time it tries to reuse a value's location is when replacing data with exactly the same size. This internal optimization is subject to change in any future release.
Stores the record specified by the key and val parameters.
[in,out] | db | Database handle |
[in] | key | datum to be used as the index key |
[in] | val | datum containing the value to be stored |
[in] | flags | Type of store operation to be performed. See mdbm_store for flag values. |
[in,out] | iter | MDBM iterator |
-1 | Error, and errno is set |
0 | Success |
1 | Flag MDBM_INSERT was specified, and the key already exists |
See mdbm_store for additional usage information.
int mdbm_store_str | ( | MDBM * | db, |
const char * | key, | ||
const char * | val, | ||
int | flags | ||
) |
Stores a string into the MDBM.
[in,out] | db | Database handle |
[in] | key | Key for storage |
[in] | val | String to store |
[in] | flags | Type of store operation to be performed. |
-1 | Error, and errno is set |
0 | Success |
1 | Flag MDBM_INSERT was specified, and the key already exists |
See mdbm_store for additional usage information.