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

7 Searching for records in the database.

gdbm interface: datum gdbm_fetch (GDBM_FILE dbf, datum key)

Looks up a given key and returns the information associated with it. The ‘dptr’ field in the structure that is returned points to a memory block allocated by malloc. It is the caller’s responsibility to free it when no longer needed.

If the ‘dptr’ is ‘NULL’, no data was found.

The parameters are:

dbf

The pointer returned by gdbm_open.

key

The search key.

An example of using this function:

content = gdbm_fetch (dbf, key);
if (content.dptr == NULL)
  {
    fprintf(stderr, "key not found\n");
  }
else
  {
    /* do something with content.dptr */
  }

You may also search for a particular key without retrieving it:

gdbm interface: int gdbm_exists (GDBM_FILE dbf, datum key)

Returns ‘true’ (‘1’) if the key exists in dbf and ‘false’ (‘0’) otherwise.

The parameters are:

dbf

The pointer returned by gdbm_open.

key

The search key.


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