blob: e08af99898331aee16ba77a061fff921d1566f52 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{dbm} ---
Fred Drakebbac4321999-02-20 00:14:17 +00002 Simple ``database'' interface}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakebbac4321999-02-20 00:14:17 +00004\declaremodule{builtin}{dbm}
Fred Drakea54a8871999-03-02 17:03:42 +00005 \platform{Unix}
Fred Drakeb91e9341998-07-23 17:59:49 +00006\modulesynopsis{The standard ``database'' interface, based on ndbm.}
7
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008
Fred Drakebbac4321999-02-20 00:14:17 +00009The \module{dbm} module provides an interface to the \UNIX{}
Fred Drake7c25f3d2000-09-15 21:31:31 +000010(\code{n})\code{dbm} library. Dbm objects behave like mappings
Guido van Rossum0bf84751995-07-07 22:55:57 +000011(dictionaries), except that keys and values are always strings.
12Printing a dbm object doesn't print the keys and values, and the
Fred Drakef6863c11999-03-02 16:37:17 +000013\method{items()} and \method{values()} methods are not supported.
Guido van Rossum0bf84751995-07-07 22:55:57 +000014
Fred Drake7c25f3d2000-09-15 21:31:31 +000015This module can be used with the ``classic'' ndbm interface, the BSD
16DB compatibility interface, or the GNU GDBM compatibility interface.
17On \UNIX, the \program{configure} script will attempt to locate the
18appropriate header file to simplify building this module.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000019
Fred Drake7c25f3d2000-09-15 21:31:31 +000020The module defines the following:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000021
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000022\begin{excdesc}{error}
Fred Drakebbac4321999-02-20 00:14:17 +000023Raised on dbm-specific errors, such as I/O errors.
24\exception{KeyError} is raised for general mapping errors like
25specifying an incorrect key.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000026\end{excdesc}
27
Fred Drake7c25f3d2000-09-15 21:31:31 +000028\begin{datadesc}{library}
29Name of the \code{ndbm} implementation library used.
30\end{datadesc}
31
32\begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}}
Guido van Rossum0bf84751995-07-07 22:55:57 +000033Open a dbm database and return a dbm object. The \var{filename}
34argument is the name of the database file (without the \file{.dir} or
Fred Drake7c25f3d2000-09-15 21:31:31 +000035\file{.pag} extensions; note that the BSD DB implementation of the
36interface will append the extension \file{.db} and only create one
37file).
Guido van Rossum0bf84751995-07-07 22:55:57 +000038
Fred Drake7c25f3d2000-09-15 21:31:31 +000039The optional \var{flag} argument must be one of these values:
40
41\begin{tableii}{c|l}{code}{Value}{Meaning}
42 \lineii{'r'}{Open existing database for reading only (default)}
43 \lineii{'w'}{Open existing database for reading and writing}
44 \lineii{'c'}{Open database for reading and writing, creating it if
45 it doesn't exist}
46 \lineii{'n'}{Always create a new, empty database, open for reading
47 and writing}
48\end{tableii}
Guido van Rossum0bf84751995-07-07 22:55:57 +000049
50The optional \var{mode} argument is the \UNIX{} mode of the file, used
51only when the database has to be created. It defaults to octal
52\code{0666}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000053\end{funcdesc}
Fred Drake4f21d541999-04-05 22:18:12 +000054
55
56\begin{seealso}
57 \seemodule{anydbm}{Generic interface to \code{dbm}-style databases.}
Fred Drake7c25f3d2000-09-15 21:31:31 +000058 \seemodule{gdbm}{Similar interface to the GNU GDBM library.}
Fred Drake4f21d541999-04-05 22:18:12 +000059 \seemodule{whichdb}{Utility module used to determine the type of an
60 existing database.}
61\end{seealso}