-
Notifications
You must be signed in to change notification settings - Fork 0
/
testdbm.ml
33 lines (27 loc) · 1.45 KB
/
testdbm.ml
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
(***********************************************************************)
(* *)
(* CamlDBM *)
(* *)
(* Francois Rouaix, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 1996 Institut National de Recherche en Informatique et *)
(* en Automatique. All rights reserved. This file is distributed *)
(* under the terms of the GNU Library General Public License, with *)
(* the special exception on linking described in file ../../LICENSE. *)
(* *)
(***********************************************************************)
let optfind d k = try Some(Dbm.find d k) with Not_found -> None
let _ =
let db = Dbm.opendbm "testdatabase" [Dbm.Dbm_rdwr;Dbm.Dbm_create] 0o666 in
Dbm.add db "one" "un";
Dbm.add db "two" "dos";
Dbm.replace db "two" "deux";
Dbm.add db "three" "trois";
assert (optfind db "one" = Some "un");
assert (optfind db "two" = Some "deux");
assert (optfind db "three" = Some "trois");
assert (optfind db "four" = None);
Dbm.close db;
let db = Dbm.opendbm "testdatabase" [Dbm.Dbm_rdonly] 0 in
Dbm.iter (fun k d -> Printf.printf "key '%s' -> data '%s'\n" k d) db;
Dbm.close db