1999-04-15 12:11:40 -03:00
|
|
|
\section{\module{dbhash} ---
|
|
|
|
DBM-style interface to the BSD database library}
|
|
|
|
|
|
|
|
\declaremodule{standard}{dbhash}
|
|
|
|
\modulesynopsis{DBM-style interface to the BSD database library.}
|
1999-04-16 11:03:32 -03:00
|
|
|
\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
|
1999-04-15 12:11:40 -03:00
|
|
|
|
|
|
|
|
|
|
|
The \module{dbhash} module provides a function to open databases using
|
|
|
|
the BSD \code{db} library. This module mirrors the interface of the
|
|
|
|
other Python database modules that provide access to DBM-style
|
1999-04-19 18:19:21 -03:00
|
|
|
databases. The \refmodule{bsddb}\refbimodindex{bsddb} module is required
|
1999-04-15 12:11:40 -03:00
|
|
|
to use \module{dbhash}.
|
|
|
|
|
|
|
|
This module provides an exception and a function:
|
|
|
|
|
|
|
|
|
|
|
|
\begin{excdesc}{error}
|
|
|
|
Exception raised on database errors other than
|
|
|
|
\exception{KeyError}. It is a synonym for \exception{bsddb.error}.
|
|
|
|
\end{excdesc}
|
|
|
|
|
2001-06-27 10:49:59 -03:00
|
|
|
\begin{funcdesc}{open}{path\optional{, flag\optional{, mode}}}
|
1999-04-15 12:11:40 -03:00
|
|
|
Open a \code{db} database and return the database object. The
|
|
|
|
\var{path} argument is the name of the database file.
|
|
|
|
|
|
|
|
The \var{flag} argument can be
|
1999-04-16 11:03:32 -03:00
|
|
|
\code{'r'} (the default), \code{'w'},
|
1999-04-15 12:11:40 -03:00
|
|
|
\code{'c'} (which creates the database if it doesn't exist), or
|
|
|
|
\code{'n'} (which always creates a new empty database).
|
|
|
|
For platforms on which the BSD \code{db} library supports locking,
|
|
|
|
an \character{l} can be appended to indicate that locking should be
|
|
|
|
used.
|
|
|
|
|
|
|
|
The optional \var{mode} parameter is used to indicate the \UNIX{}
|
|
|
|
permission bits that should be set if a new database must be
|
|
|
|
created; this will be masked by the current umask value for the
|
|
|
|
process.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
|
|
|
|
\begin{seealso}
|
|
|
|
\seemodule{anydbm}{Generic interface to \code{dbm}-style databases.}
|
1999-04-19 18:19:21 -03:00
|
|
|
\seemodule{bsddb}{Lower-level interface to the BSD \code{db} library.}
|
1999-04-15 12:11:40 -03:00
|
|
|
\seemodule{whichdb}{Utility module used to determine the type of an
|
|
|
|
existing database.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
|
|
|
|
|
|
\subsection{Database Objects \label{dbhash-objects}}
|
|
|
|
|
|
|
|
The database objects returned by \function{open()} provide the methods
|
2003-09-12 03:33:37 -03:00
|
|
|
common to all the DBM-style databases and mapping objects. The following
|
|
|
|
methods are available in addition to the standard methods.
|
1999-04-15 12:11:40 -03:00
|
|
|
|
|
|
|
\begin{methoddesc}[dbhash]{first}{}
|
2003-09-12 03:33:37 -03:00
|
|
|
It's possible to loop over every key/value pair in the database using
|
|
|
|
this method and the \method{next()} method. The traversal is ordered by
|
1999-04-15 12:11:40 -03:00
|
|
|
the databases internal hash values, and won't be sorted by the key
|
|
|
|
values. This method returns the starting key.
|
|
|
|
\end{methoddesc}
|
|
|
|
|
|
|
|
\begin{methoddesc}[dbhash]{last}{}
|
2003-09-12 03:33:37 -03:00
|
|
|
Return the last key/value pair in a database traversal. This may be used to
|
1999-04-15 12:11:40 -03:00
|
|
|
begin a reverse-order traversal; see \method{previous()}.
|
|
|
|
\end{methoddesc}
|
|
|
|
|
2003-09-10 01:44:29 -03:00
|
|
|
\begin{methoddesc}[dbhash]{next}{}
|
2003-09-12 03:33:37 -03:00
|
|
|
Returns the key next key/value pair in a database traversal. The
|
1999-04-15 12:11:40 -03:00
|
|
|
following code prints every key in the database \code{db}, without
|
|
|
|
having to create a list in memory that contains them all:
|
|
|
|
|
|
|
|
\begin{verbatim}
|
2003-09-10 01:44:29 -03:00
|
|
|
print db.first()
|
2003-09-16 18:45:22 -03:00
|
|
|
for i in xrange(1, len(db)):
|
2003-09-10 01:44:29 -03:00
|
|
|
print db.next()
|
1999-04-15 12:11:40 -03:00
|
|
|
\end{verbatim}
|
|
|
|
\end{methoddesc}
|
|
|
|
|
2003-09-10 01:44:29 -03:00
|
|
|
\begin{methoddesc}[dbhash]{previous}{}
|
2003-09-12 03:33:37 -03:00
|
|
|
Returns the previous key/value pair in a forward-traversal of the database.
|
2003-09-10 01:44:29 -03:00
|
|
|
In conjunction with \method{last()}, this may be used to implement
|
|
|
|
a reverse-order traversal.
|
1999-04-15 12:11:40 -03:00
|
|
|
\end{methoddesc}
|
|
|
|
|
|
|
|
\begin{methoddesc}[dbhash]{sync}{}
|
|
|
|
This method forces any unwritten data to be written to the disk.
|
|
|
|
\end{methoddesc}
|