1 :mod:`dbhash` --- DBM-style interface to the BSD database library
2 =================================================================
5 :synopsis: DBM-style interface to the BSD database library.
6 .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
9 The :mod:`dbhash` module has been deprecated for removal in Python 3.0.
11 .. index:: module: bsddb
13 The :mod:`dbhash` module provides a function to open databases using the BSD
14 ``db`` library. This module mirrors the interface of the other Python database
15 modules that provide access to DBM-style databases. The :mod:`bsddb` module is
16 required to use :mod:`dbhash`.
18 This module provides an exception and a function:
23 Exception raised on database errors other than :exc:`KeyError`. It is a synonym
24 for :exc:`bsddb.error`.
27 .. function:: open(path[, flag[, mode]])
29 Open a ``db`` database and return the database object. The *path* argument is
30 the name of the database file.
32 The *flag* argument can be:
34 +---------+-------------------------------------------+
36 +=========+===========================================+
37 | ``'r'`` | Open existing database for reading only |
39 +---------+-------------------------------------------+
40 | ``'w'`` | Open existing database for reading and |
42 +---------+-------------------------------------------+
43 | ``'c'`` | Open database for reading and writing, |
44 | | creating it if it doesn't exist |
45 +---------+-------------------------------------------+
46 | ``'n'`` | Always create a new, empty database, open |
47 | | for reading and writing |
48 +---------+-------------------------------------------+
50 For platforms on which the BSD ``db`` library supports locking, an ``'l'``
51 can be appended to indicate that locking should be used.
53 The optional *mode* parameter is used to indicate the Unix permission bits that
54 should be set if a new database must be created; this will be masked by the
55 current umask value for the process.
61 Generic interface to ``dbm``\ -style databases.
64 Lower-level interface to the BSD ``db`` library.
67 Utility module used to determine the type of an existing database.
75 The database objects returned by :func:`open` provide the methods common to all
76 the DBM-style databases and mapping objects. The following methods are
77 available in addition to the standard methods.
80 .. method:: dbhash.first()
82 It's possible to loop over every key/value pair in the database using this
83 method and the :meth:`next` method. The traversal is ordered by the databases
84 internal hash values, and won't be sorted by the key values. This method
85 returns the starting key.
88 .. method:: dbhash.last()
90 Return the last key/value pair in a database traversal. This may be used to
91 begin a reverse-order traversal; see :meth:`previous`.
94 .. method:: dbhash.next()
96 Returns the key next key/value pair in a database traversal. The following code
97 prints every key in the database ``db``, without having to create a list in
98 memory that contains them all::
101 for i in xrange(1, len(db)):
105 .. method:: dbhash.previous()
107 Returns the previous key/value pair in a forward-traversal of the database. In
108 conjunction with :meth:`last`, this may be used to implement a reverse-order
112 .. method:: dbhash.sync()
114 This method forces any unwritten data to be written to the disk.