manpagez: man pages & more
info gdbm
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6 Inserting and replacing records in the database.

gdbm interface: int gdbm_store (GDBM_FILE dbf, datum key, datum content, int flag)

The function gdbm_store inserts or replaces records in the database.

The parameters are:

dbf

The pointer returned by gdbm_open.

key

The search key.

content

The data to be associated with the key.

flag

Defines the action to take when the key is already in the database. The value ‘GDBM_REPLACE’ (defined in ‘gdbm.h’) asks that the old data be replaced by the new content. The value ‘GDBM_INSERT’ asks that an error be returned and no action taken if the key already exists.

This function can return the following values:

-1

The item was not stored in the database because the caller was not an official writer or either key or content have a ‘NULL’ ‘dptr’ field.

Both key and content must have the ‘dptr’ field be a non-‘NULL’ value. Since a ‘NULL’ ‘dptr’ field is used by other functions to indicate an error, it cannot be valid data.

+1

The item was not stored because the argument flag was ‘GDBM_INSERT’ and the key was already in the database.

0

No error. The value of content is keyed by key. The file on disk is updated to reflect the structure of the new database before returning from this function.

If you store data for a key that is already in the data base, gdbm replaces the old data with the new data if called with ‘GDBM_REPLACE’. You do not get two data items for the same key and you do not get an error from gdbm_store.

The size in gdbm is not restricted like dbm or ndbm. Your data can be as large as you want.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on December 2, 2011 using texi2html 5.0.