1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset= ISO-8859-1">
<TITLE>
The dbm library: access to NDBM databases
</TITLE>
</HEAD>
<BODY >
<A HREF="manual064.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual066.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<HR>
<H1>Chapter 23: The dbm library: access to NDBM databases</H1>
The <TT>dbm</TT> library provides access to NDBM databases under Unix.
NDBM databases maintain key/data associations, where both the key and
the data are arbitrary strings. They support fairly large databases
(several gigabytes) and can retrieve a keyed item in one or two file
system accesses. Refer to the Unix manual pages for more information.<BR>
<BR>
<FONT COLOR=purple>Unix:</FONT>
<BLOCKQUOTE>
Programs that use the <TT>dbm</TT> library must be linked in ``custom
runtime'' mode, as follows:
<PRE>
ocamlc -custom <I>other options</I> dbm.cma <I>other files</I> -cclib -lmldbm -cclib -lndbm
ocamlopt <I>other options</I> dbm.cmxa <I>other files</I> -cclib -lmldbm -cclib -lndbm
</PRE>
For interactive use of the <TT>dbm</TT> library, do:
<PRE>
ocamlmktop -custom -o mytop dbm.cma -cclib -lmldbm -cclib -lndbm
./mytop
</PRE>
Depending on the Unix system used, the <TT>-cclib -lndbm</TT> option is not
always necessary, or the library may have another name than <TT>-lndbm</TT>.
</BLOCKQUOTE>
<FONT COLOR=purple>Windows:</FONT>
<BLOCKQUOTE>
This library is not available.
</BLOCKQUOTE>
<H2>23.1 Module <TT>Dbm</TT>: interface to the NDBM databases</H2><A NAME="s:Dbm"></A>
<A NAME="@manual879"></A><PRE>
type t
</PRE>
<BLOCKQUOTE>
The type of file descriptors opened on NDBM databases.
</BLOCKQUOTE>
<PRE>
type open_flag =
Dbm_rdonly | Dbm_wronly | Dbm_rdwr | Dbm_create
</PRE>
<BLOCKQUOTE>
Flags for opening a database (see <CODE>opendbm</CODE>).
</BLOCKQUOTE>
<PRE>
exception Dbm_error of string
</PRE>
<A NAME="@manual880"></A><BLOCKQUOTE>
Raised by the following functions when an error is encountered.
</BLOCKQUOTE>
<PRE>
val opendbm : string -> open_flag list -> int -> t
</PRE>
<A NAME="@manual881"></A><BLOCKQUOTE>
Open a descriptor on an NDBM database. The first argument is
the name of the database (without the <CODE>.dir</CODE> and <CODE>.pag</CODE> suffixes).
The second argument is a list of flags: <CODE>Dbm_rdonly</CODE> opens
the database for reading only, <CODE>Dbm_wronly</CODE> for writing only,
<CODE>Dbm_rdwr</CODE> for reading and writing; <CODE>Dbm_create</CODE> causes the
database to be created if it does not already exist.
The third argument is the permissions to give to the database
files, if the database is created.
</BLOCKQUOTE>
<PRE>
val close : t -> unit
</PRE>
<A NAME="@manual882"></A><BLOCKQUOTE>
Close the given descriptor.
</BLOCKQUOTE>
<PRE>
val find : t -> string -> string
</PRE>
<A NAME="@manual883"></A><BLOCKQUOTE>
<CODE>find db key</CODE> returns the data associated with the given
<CODE>key</CODE> in the database opened for the descriptor <CODE>db</CODE>.
Raise <CODE>Not_found</CODE> if the <CODE>key</CODE> has no associated data.
</BLOCKQUOTE>
<PRE>
val add : t -> string -> string -> unit
</PRE>
<A NAME="@manual884"></A><BLOCKQUOTE>
<CODE>add db key data</CODE> inserts the pair (<CODE>key</CODE>, <CODE>data</CODE>) in
the database <CODE>db</CODE>. If the database already contains data
associated with <CODE>key</CODE>, raise <CODE>Dbm_error "Entry already exists"</CODE>.
</BLOCKQUOTE>
<PRE>
val replace : t -> string -> string -> unit
</PRE>
<A NAME="@manual885"></A><BLOCKQUOTE>
<CODE>replace db key data</CODE> inserts the pair (<CODE>key</CODE>, <CODE>data</CODE>) in
the database <CODE>db</CODE>. If the database already contains data
associated with <CODE>key</CODE>, that data is discarded and silently
replaced by the new <CODE>data</CODE>.
</BLOCKQUOTE>
<PRE>
val remove : t -> string -> unit
</PRE>
<A NAME="@manual886"></A><BLOCKQUOTE>
<CODE>remove db key data</CODE> removes the data associated with <CODE>key</CODE>
in <CODE>db</CODE>. If <CODE>key</CODE> has no associated data, raise
<CODE>Dbm_error "dbm_delete"</CODE>.
</BLOCKQUOTE>
<PRE>
val firstkey : t -> string
val nextkey : t -> string
</PRE>
<A NAME="@manual887"></A><A NAME="@manual888"></A><BLOCKQUOTE>
Enumerate all keys in the given database, in an unspecified order.
<CODE>firstkey db</CODE> returns the first key, and repeated calls
to <CODE>nextkey db</CODE> return the remaining keys. <CODE>Not_found</CODE> is raised
when all keys have been enumerated.
</BLOCKQUOTE>
<PRE>
val iter : (string -> string -> 'a) -> t -> unit
</PRE>
<A NAME="@manual889"></A><BLOCKQUOTE>
<CODE>iter f db</CODE> applies <CODE>f</CODE> to each (<CODE>key</CODE>, <CODE>data</CODE>) pair in
the database <CODE>db</CODE>. <CODE>f</CODE> receives <CODE>key</CODE> as first argument
and <CODE>data</CODE> as second argument.
</BLOCKQUOTE>
<HR>
<A HREF="manual064.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual066.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
</BODY>
</HTML>
|