blob: c05e3ac554e1885f59f0f50bb5cef540cbb24fe8 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{anydbm} ---
Fred Drakebbac4321999-02-20 00:14:17 +00002 Generic access to DBM-style databases}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakebbac4321999-02-20 00:14:17 +00004\declaremodule{standard}{anydbm}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\modulesynopsis{Generic interface to DBM-style database modules.}
6
Guido van Rossum571391b1997-04-03 22:41:49 +00007
Fred Drakeddf03bf1998-02-18 15:05:47 +00008\module{anydbm} is a generic interface to variants of the DBM
Fred Drake2764dd31998-04-07 22:08:02 +00009database --- \module{dbhash}\refbimodindex{dbhash},
Fred Drake01553701999-04-05 19:46:21 +000010\refmodule{gdbm}\refbimodindex{gdbm}, or
11\refmodule{dbm}\refbimodindex{dbm}. If none of these modules is
12installed, the slow-but-simple implementation in module
13\refmodule{dumbdbm}\refstmodindex{dumbdbm} will be used.
Guido van Rossum571391b1997-04-03 22:41:49 +000014
Fred Drake2764dd31998-04-07 22:08:02 +000015\begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}}
Fred Drakeddf03bf1998-02-18 15:05:47 +000016Open the database file \var{filename} and return a corresponding object.
Guido van Rossum2aefe8d1998-04-28 15:29:26 +000017
Fred Drake01553701999-04-05 19:46:21 +000018If the database file already exists, the \refmodule{whichdb} module is
Guido van Rossum2aefe8d1998-04-28 15:29:26 +000019used to determine its type and the appropriate module is used; if it
Fred Drake01553701999-04-05 19:46:21 +000020does not exist, the first module listed above that can be imported is
Guido van Rossum2aefe8d1998-04-28 15:29:26 +000021used.
22
Guido van Rossum571391b1997-04-03 22:41:49 +000023The optional \var{flag} argument can be
24\code{'r'} to open an existing database for reading only,
25\code{'w'} to open an existing database for reading and writing,
26\code{'c'} to create the database if it doesn't exist, or
27\code{'n'}, which will always create a new empty database. If not
28specified, the default value is \code{'r'}.
29
30The optional \var{mode} argument is the \UNIX{} mode of the file, used
31only when the database has to be created. It defaults to octal
Guido van Rossum51a6c901997-05-09 02:23:45 +000032\code{0666} (and will be modified by the prevailing umask).
Guido van Rossum571391b1997-04-03 22:41:49 +000033\end{funcdesc}
34
Fred Drake2764dd31998-04-07 22:08:02 +000035\begin{excdesc}{error}
Guido van Rossum2aefe8d1998-04-28 15:29:26 +000036A tuple containing the exceptions that can be raised by each of the
37supported modules, with a unique exception \exception{anydbm.error} as
38the first item --- the latter is used when \exception{anydbm.error} is
39raised.
Fred Drake2764dd31998-04-07 22:08:02 +000040\end{excdesc}
41
Fred Drakeddf03bf1998-02-18 15:05:47 +000042The object returned by \function{open()} supports most of the same
Guido van Rossum571391b1997-04-03 22:41:49 +000043functionality as dictionaries; keys and their corresponding values can
Fred Drakeddf03bf1998-02-18 15:05:47 +000044be stored, retrieved, and deleted, and the \method{has_key()} and
45\method{keys()} methods are available. Keys and values must always be
Guido van Rossum51a6c901997-05-09 02:23:45 +000046strings.
Guido van Rossum571391b1997-04-03 22:41:49 +000047
Fred Drake2764dd31998-04-07 22:08:02 +000048
Fred Drake01553701999-04-05 19:46:21 +000049\begin{seealso}
50 \seemodule{anydbm}{Generic interface to \code{dbm}-style databases.}
51 % Should include entry for dbhash, but that isn't documented.
52 \seemodule{dbm}{Standard \UNIX{} database interface.}
53 \seemodule{dumbdbm}{Portable implementation of the \code{dbm} interface.}
54 \seemodule{gdbm}{GNU database interface, based on the \code{dbm} interface.}
55 \seemodule{shelve}{General object persistence built on top of
56 the Python \code{dbm} interface.}
57 \seemodule{whichdb}{Utility module used to determine the type of an
58 existing database.}
59\end{seealso}
60
Fred Drake2764dd31998-04-07 22:08:02 +000061
Fred Drake295da241998-08-10 19:42:37 +000062\section{\module{dumbdbm} ---
Fred Drakebbac4321999-02-20 00:14:17 +000063 Portable DBM implementation}
Fred Drakeb91e9341998-07-23 17:59:49 +000064
Fred Drakebbac4321999-02-20 00:14:17 +000065\declaremodule{standard}{dumbdbm}
Fred Drake9030b0f1998-07-27 22:12:26 +000066\modulesynopsis{Portable implementation of the simple DBM interface.}
Fred Drakeb91e9341998-07-23 17:59:49 +000067
Fred Drake2764dd31998-04-07 22:08:02 +000068
69A simple and slow database implemented entirely in Python. This
70should only be used when no other DBM-style database is available.
71
72
73\begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}}
74Open the database file \var{filename} and return a corresponding object.
75The optional \var{flag} argument can be
76\code{'r'} to open an existing database for reading only,
77\code{'w'} to open an existing database for reading and writing,
78\code{'c'} to create the database if it doesn't exist, or
79\code{'n'}, which will always create a new empty database. If not
80specified, the default value is \code{'r'}.
81
82The optional \var{mode} argument is the \UNIX{} mode of the file, used
83only when the database has to be created. It defaults to octal
84\code{0666} (and will be modified by the prevailing umask).
85\end{funcdesc}
86
87\begin{excdesc}{error}
88Raised for errors not reported as \exception{KeyError} errors.
89\end{excdesc}
Fred Drake4f21d541999-04-05 22:18:12 +000090
91
92\begin{seealso}
93 \seemodule{anydbm}{Generic interface to \code{dbm}-style databases.}
94 \seemodule{whichdb}{Utility module used to determine the type of an
95 existing database.}
96\end{seealso}