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

11.1.1 Opening and closing a dbm database

Class: <dbm>
An abstract class for dbm-style database. Defindes the common database operations. This class has the following instance slots. They must be set before the database is actually opened by dbm-open.

The concrete class may add more slots for finer control on the database, such as locking.

Instance Variable: <dbm> path
Pathname of the dbm database. Some dbm implementation may append suffixes to this.

Instance Variable: <dbm> rw-mode
Specifies read/write mode. Can be either one of the following keywords:
:read
The database will be opened in read-only mode. The database file must exist when dbm-open is called. This is the default value.
:write
The database will be opened in Read-write mode. If the database file does not exist, dbm-open creates one.
:create
The database will be created and opened in Read-write mode. If the database file exists, dbm-open truncates it.

Instance Variable: <dbm> file-mode
Specifies the file permissions (as sys-chmod) to create the database. The default value is #o664.

Instance Variable: <dbm> key-convert
Instance Variable: <dbm> value-convert
By default, you can use only strings for both key and values. With this option, however, you can specify how to convert other Scheme values to/from string to be stored in the database. The possible values are the followings:
#f
The default value. Keys (values) are not converted. They must be a string.
#t
Keys (values) are converted to its string representation, using write, to store in the database, and converted back to Scheme values, using read, to retrieve from the database. The data must have an external representation that can be read back. (But it is not checked when the data is written; you'll get an error when you read the data). The key comparison is done in the string level, so the external representation of the same key must match.
a list of two procedures
Both procedure must take a single argument. The first procedure must receive a Scheme object and returns a string. It is used to convert the keys (values) to store in the database. The second procedure must receive a string and returns a Scheme object. It is used to convert the stored data in the database to a Scheme object. The key comparison is done in the string level, so the external representation of the same key must match.

Metaclass: <dbm-meta>
A metaclass of <dbm> and its subclasses.

Method: dbm-open (dbm <dbm>)
Opens a dbm database. dbm must be an instance of one of the concrete classes that derived from the <dbm> class, and its slots must be set appropriately. On success, it returns the dbm itself. On failure, it signals an error.

Method: dbm-open (dbm-class <dbm-meta>) options ...
A convenient method that creates dbm instance and opens it. It is defined as follows.
 
(define-method dbm-open ((class <class>) . initargs)
  (dbm-open (apply make class initargs)))

Database file is closed when it is garbage collected. However, to ensure the modification is properly synchornized, you should close the database explicitly.

Method: dbm-close (dbm <dbm>)
Closes a database dbm. Once the database is closed, any operation to access the database content raises an error.

Method: dbm-closed? (dbm <dbm>)
Returns true if a database dbm is already closed, false otherwise.


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

This document was generated by Ken Dickey on November, 28 2002 using texi2html