|
4.9.7 DBM links
DBM links provide access to data stored in a data base.
Each entry in the data base consists of a (key_string,
value_string) pair. Such a pair can be inserted with the command
write( link, key_string, value_string) . By
calling write( link, key_string) , the entry with key
key_string is deleted from the data base. The value of an entry is
returned by the command read( link,
key_string) . With only one argument, read( link)
returns the next key in the data base. Using this feature a
data base can be scanned in order to access all entries of the data base.
If a data base with name name is opened for writing for the first
time, two files (name.pag and name.dir ), which contain the
data base, are automatically created.
The DBM link describing string has to be one of the following:
"DBM: " + name
opens the data base for reading (default mode).
"DBM:r " + name
opens the data base for reading.
"DBM:rw " + name
opens the data base for reading and writing.
Note that name must be given without the suffix .pag or
.dir . The name may contain an (absolute) path.
Example:
| link l="DBM:rw example";
write(l,"1","abc");
write(l,"3","XYZ");
write(l,"2","ABC");
l;
==> // type : DBM
==> // mode : rw
==> // name : example
==> // open : yes
==> // read : ready
==> // write: ready
close(l);
// read all keys (till empty string):
read(l);
==> 1
read(l);
==> 3
read(l);
==> 2
read(l);
==>
// read data corresponding to key "1"
read(l,"1");
==> abc
// read all data:
read(l,read(l));
==> abc
read(l,read(l));
==> XYZ
read(l,read(l));
==> ABC
// close
close(l);
|
|