download index This S-Lang module provides access to gdbm databases.

features

To implement this I started by stealing from the pcre module, then I went on to steal from slstdio.c, then from slassoc.c.

limitations

assoc syntax

You can access a dbf with an assoc-like syntax. This is similar to the anydbm interface of python and perl's tie() interface. You can write val = key[dbf]; as an alternative to val = gdbm_fetch(dbf, key); as well as dbf[key]=val; as shorthand for () = gdbm_store(dbf, key, val, GDBM_REPLACE); In this last case, gdbm_store() returns a value but dbf[key]=val; does not. I don't know if a syntax like ret = (dbf[key]=val); is possible, but such a syntax would be confusing to C programmers anyway. Also, the chosen syntax has the advantage that it is possible to some extent to write code that works on an object without knowing if the object is an assoc or a dbf.

foreach

You can also iterate over the database entries using the syntax foreach (dbf) using ("keys", "values") However, this uses gdbm's sequential access method. If you do this

 foreach(dbf) using ("keys")
   {
      key = ();
      if ( some condition )
        gdbm_delete ( dbf, key );
   }
the hash will be rearranged and some entries may be skipped by the loop. See also info:(gdbm)Sequential. Changing values of entries in a foreach loop is OK, I think.

applications

A recent files mode for JED using slgdbm is available from the Jed Modes Repository.

copyright

Slgdbm is Copyright (c) 2004, 2005, 2007 Paul Boekholt. Released under the terms of the GNU GPL (version 2 or later).