dbm_store() — Store database record

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <ndbm.h>

int dbm_store(DBM *db, datum key, datum content, int store_mode);

General description

The dbm_store() function writes a record to a database. The db argument specifies the database handle returned by a previous call to dbm_open(). The key argument identifies the record the program is deleting. The key datum must contain a dptr pointer to the key, and the key length in dsize. The argument content is a datum. that describes the data record being stored. record the program is writing. The content datum. contains a dptr pointer to the data, and the data length in dsize.

The argument store_mode controls whether dbm_store() replaces a already existing record that has the same key. The store_mode argument may be any one of the following set of symbols defined in the <ndbm.h> include file:
DBM_INSERT
Do not add the key and content pair if the key already exists in the database. If the key doesn't already exist, add the new key and content pair.
DBM_REPLACE
Replace the key and content pair in the database with the new pair if the key already exists. If the key doesn't already exist, add the new key and content pair.

After calling dbm_store(), during a pass through the keys by dbm_firstkey() and dbm_nextkey(), the application positioning must be reset by calling dbm_firstkey(). If not, unpredictable results may occur including retrieval of the same key multiple times, or not at all.

The number of records that can be stored in the database is limited by the file space available for the .dir and .pag files, and by the underlying key hashing. If multiple keys hash to the same 32 bit hash value, the number of keys for that hash value is limited to the amount of data (key sizes plus content sizes plus overhead) that can be stored in a single logical block of 1024 bytes.

Special behavior for z/OS® UNIX Services: In a multithreaded environment, changes made to the database by a dbm_store() operation affect all threads using the database handle. Thus, all other threads must also reset their positioning by using the dbm_firstkey() function before using dbm_nextkey(). A previously executed dbm_fetch() operation by another thread for the same key still has correct buffer pointers to the previous data. The dbm_store() operation does not affect this. All other operations, such as dbm_fetch() or dbm_delete(), will automatically have access to the new key and content pair.

Returned value

If successful, dbm_store() returns 0. If DBM_INSERT is specified, and the key already exists, dbm_store() returns 1.

If unsuccessful, dbm_store() returns -1 and sets errno to one of the following values. Also, the database error indicator may be set.
Error Code
Description
EFBIG
Seek/Write operation failed attempting to write new block. This errno is not part of the errno set described by X/Open for this function. You may be able to store other key and content pairs when the key hashes to a different value.
ENOSPC
key plus content plus block overhead does not fit into a block. This errno is not part of the errno set described by X/Open for this function. The key plus content underlying data lengths need be less or equal to 1012 bytes in length.

Related information