Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{anydbm} --- |
Fred Drake | bbac432 | 1999-02-20 00:14:17 +0000 | [diff] [blame] | 2 | Generic access to DBM-style databases} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 3 | |
Fred Drake | bbac432 | 1999-02-20 00:14:17 +0000 | [diff] [blame] | 4 | \declaremodule{standard}{anydbm} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 5 | \modulesynopsis{Generic interface to DBM-style database modules.} |
| 6 | |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 7 | |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 8 | \module{anydbm} is a generic interface to variants of the DBM |
Fred Drake | 666255f | 1999-04-15 15:11:40 +0000 | [diff] [blame] | 9 | database --- \refmodule{dbhash}\refstmodindex{dbhash} (requires |
Fred Drake | 9d15881 | 1999-04-19 21:19:21 +0000 | [diff] [blame] | 10 | \refmodule{bsddb}\refbimodindex{bsddb}), |
Fred Drake | 0155370 | 1999-04-05 19:46:21 +0000 | [diff] [blame] | 11 | \refmodule{gdbm}\refbimodindex{gdbm}, or |
| 12 | \refmodule{dbm}\refbimodindex{dbm}. If none of these modules is |
| 13 | installed, the slow-but-simple implementation in module |
| 14 | \refmodule{dumbdbm}\refstmodindex{dumbdbm} will be used. |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 15 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 16 | \begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}} |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 17 | Open the database file \var{filename} and return a corresponding object. |
Guido van Rossum | 2aefe8d | 1998-04-28 15:29:26 +0000 | [diff] [blame] | 18 | |
Fred Drake | 0155370 | 1999-04-05 19:46:21 +0000 | [diff] [blame] | 19 | If the database file already exists, the \refmodule{whichdb} module is |
Guido van Rossum | 2aefe8d | 1998-04-28 15:29:26 +0000 | [diff] [blame] | 20 | used to determine its type and the appropriate module is used; if it |
Fred Drake | 0155370 | 1999-04-05 19:46:21 +0000 | [diff] [blame] | 21 | does not exist, the first module listed above that can be imported is |
Guido van Rossum | 2aefe8d | 1998-04-28 15:29:26 +0000 | [diff] [blame] | 22 | used. |
| 23 | |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 24 | The optional \var{flag} argument can be |
| 25 | \code{'r'} to open an existing database for reading only, |
| 26 | \code{'w'} to open an existing database for reading and writing, |
| 27 | \code{'c'} to create the database if it doesn't exist, or |
| 28 | \code{'n'}, which will always create a new empty database. If not |
| 29 | specified, the default value is \code{'r'}. |
| 30 | |
| 31 | The optional \var{mode} argument is the \UNIX{} mode of the file, used |
| 32 | only when the database has to be created. It defaults to octal |
Guido van Rossum | 51a6c90 | 1997-05-09 02:23:45 +0000 | [diff] [blame] | 33 | \code{0666} (and will be modified by the prevailing umask). |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 34 | \end{funcdesc} |
| 35 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 36 | \begin{excdesc}{error} |
Guido van Rossum | 2aefe8d | 1998-04-28 15:29:26 +0000 | [diff] [blame] | 37 | A tuple containing the exceptions that can be raised by each of the |
| 38 | supported modules, with a unique exception \exception{anydbm.error} as |
| 39 | the first item --- the latter is used when \exception{anydbm.error} is |
| 40 | raised. |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 41 | \end{excdesc} |
| 42 | |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 43 | The object returned by \function{open()} supports most of the same |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 44 | functionality as dictionaries; keys and their corresponding values can |
Fred Drake | ddf03bf | 1998-02-18 15:05:47 +0000 | [diff] [blame] | 45 | be stored, retrieved, and deleted, and the \method{has_key()} and |
| 46 | \method{keys()} methods are available. Keys and values must always be |
Guido van Rossum | 51a6c90 | 1997-05-09 02:23:45 +0000 | [diff] [blame] | 47 | strings. |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 48 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 49 | |
Fred Drake | 0155370 | 1999-04-05 19:46:21 +0000 | [diff] [blame] | 50 | \begin{seealso} |
Fred Drake | 666255f | 1999-04-15 15:11:40 +0000 | [diff] [blame] | 51 | \seemodule{dbhash}{BSD \code{db} database interface.} |
Fred Drake | 0155370 | 1999-04-05 19:46:21 +0000 | [diff] [blame] | 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 Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 61 | |
Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 62 | \section{\module{dumbdbm} --- |
Fred Drake | bbac432 | 1999-02-20 00:14:17 +0000 | [diff] [blame] | 63 | Portable DBM implementation} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 64 | |
Fred Drake | bbac432 | 1999-02-20 00:14:17 +0000 | [diff] [blame] | 65 | \declaremodule{standard}{dumbdbm} |
Fred Drake | 9030b0f | 1998-07-27 22:12:26 +0000 | [diff] [blame] | 66 | \modulesynopsis{Portable implementation of the simple DBM interface.} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 67 | |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 68 | |
| 69 | A simple and slow database implemented entirely in Python. This |
| 70 | should only be used when no other DBM-style database is available. |
| 71 | |
| 72 | |
| 73 | \begin{funcdesc}{open}{filename\optional{, flag\optional{, mode}}} |
Fred Drake | 7961930 | 2001-12-07 21:56:13 +0000 | [diff] [blame] | 74 | Open the database file \var{filename} and return a corresponding |
| 75 | object. The \var{flag} argument, used to control how the database is |
| 76 | opened in the other DBM implementations, is ignored in |
| 77 | \module{dumbdbm}; the database is always opened for update, and will |
| 78 | be created if it does not exist. |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 79 | |
| 80 | The optional \var{mode} argument is the \UNIX{} mode of the file, used |
| 81 | only when the database has to be created. It defaults to octal |
| 82 | \code{0666} (and will be modified by the prevailing umask). |
Fred Drake | 7961930 | 2001-12-07 21:56:13 +0000 | [diff] [blame] | 83 | \versionchanged[The \var{mode} argument was ignored in earlier |
| 84 | versions]{2.2} |
Fred Drake | 2764dd3 | 1998-04-07 22:08:02 +0000 | [diff] [blame] | 85 | \end{funcdesc} |
| 86 | |
| 87 | \begin{excdesc}{error} |
| 88 | Raised for errors not reported as \exception{KeyError} errors. |
| 89 | \end{excdesc} |
Fred Drake | 4f21d54 | 1999-04-05 22:18:12 +0000 | [diff] [blame] | 90 | |
| 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} |