| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
|
| 3 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 4 |
|
| 5 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 6 |
|
| 7 |
<head> |
| 8 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 9 |
<meta http-equiv="Content-Style-Type" content="text/css" /> |
| 10 |
<meta name="author" content="Mikio Hirabayashi" /> |
| 11 |
<meta name="keywords" content="QDBM, Perl, Depot, Curia, Villa" /> |
| 12 |
<meta name="description" content="specifications of Perl API of QDBM" /> |
| 13 |
<link rel="contents" href="./" /> |
| 14 |
<link rel="alternate" href="plspex-ja.html" hreflang="ja" title="the Japanese version" /> |
| 15 |
<link rev="made" href="mailto:[email protected]" /> |
| 16 |
<title>Specifications of QDBM for Perl</title> |
| 17 |
<style type="text/css">html { margin: 0em 0em; padding: 0em 0em; background: #eeeeee none; } |
| 18 |
body { margin: 2em 2em; padding: 0em 0em; |
| 19 |
background: #eeeeee none; color: #111111; |
| 20 |
font-style: normal; font-weight: normal; } |
| 21 |
h1 { margin-top: 1.8em; margin-bottom: 1.3em; font-weight: bold; } |
| 22 |
h2 { margin-top: 1.8em; margin-bottom: 1.1em; font-weight: bold; |
| 23 |
border-left: solid 0.6em #445555; border-bottom: solid 1pt #bbbbbb; |
| 24 |
padding: 0.5em 0.5em; width: 60%; } |
| 25 |
h3 { margin-top: 1.8em; margin-bottom: 0.8em; font-weight: bold; } |
| 26 |
hr { margin-top: 2.5em; margin-bottom: 1.5em; height: 1pt; |
| 27 |
color: #999999; background-color: #999999; border: none; } |
| 28 |
div.note,div.navi { text-align: right; } |
| 29 |
div.logo { text-align: center; margin: 3em 0em; } |
| 30 |
div.logo img { border: inset 2pt #ccccdd; } |
| 31 |
p { margin: 0.8em 0em; line-height: 140%; } |
| 32 |
p,dd { text-indent: 0.8em; } |
| 33 |
div,pre { margin-left: 1.7em; margin-right: 1.7em; } |
| 34 |
pre { background-color: #ddddee; padding: 0.2em; border: 1pt solid #bbbbcc; font-size: smaller; } |
| 35 |
kbd { color: #111111; font-style: normal; font-weight: bold; } |
| 36 |
a { color: #0022aa; text-decoration: none; } |
| 37 |
a:hover,a:focus { color: #0033ee; text-decoration: underline; } |
| 38 |
a.head { color: #111111; text-decoration: none; } |
| 39 |
table { padding: 1pt 2pt 1pt 2pt; border: none; margin-left: 1.7em; border-collapse: collapse; } |
| 40 |
th { padding: 1pt 4pt 1pt 4pt; border-style: none; |
| 41 |
text-align: left; vertical-align: bottom; } |
| 42 |
td { padding: 1pt 4pt 1pt 4pt; border: 1pt solid #333333; |
| 43 |
text-align: left; vertical-align: top; } |
| 44 |
ul,ol,dl { line-height: 140%; } |
| 45 |
dt { margin-left: 1.2em; } |
| 46 |
dd { margin-left: 2.0em; } |
| 47 |
ul.lines { list-style-type: none; } |
| 48 |
@media print { |
| 49 |
html,body { margin: 0em 0em; background-color: #ffffff; color: #000000; } |
| 50 |
h1 { padding: 8em 0em 0.5em 0em; text-align: center; } |
| 51 |
h2 { page-break-before: always; } |
| 52 |
div.note { text-align: center; } |
| 53 |
div.navi,div.logo { display: none } |
| 54 |
hr { display: none; } |
| 55 |
pre { margin: 0.8em 0.8em; background-color: #ffffff; |
| 56 |
border: 1pt solid #aaaaaa; font-size: smaller; } |
| 57 |
a,kbd { color: #000000; text-decoration: none; } |
| 58 |
h1,h2,h3 { font-family: sans-serif; } |
| 59 |
p,div,li,dt,dd { font-family: serif; } |
| 60 |
pre,kbd { font-family: monospace; } |
| 61 |
dd { font-size: smaller; } |
| 62 |
} |
| 63 |
</style> |
| 64 |
</head> |
| 65 |
|
| 66 |
<body> |
| 67 |
|
| 68 |
<h1>Specifications of QDBM for Perl</h1> |
| 69 |
|
| 70 |
<div class="note">Copyright (C) 2000-2006 Mikio Hirabayashi</div> |
| 71 |
<div class="note">Last Update: Thu, 26 Oct 2006 15:00:20 +0900</div> |
| 72 |
<div class="navi">[<a href="plapidoc/index.html">API</a>] [<a href="plspex-ja.html" hreflang="ja">Japanese</a>]</div> |
| 73 |
|
| 74 |
<hr /> |
| 75 |
|
| 76 |
<h2>Table of Contents</h2> |
| 77 |
|
| 78 |
<ol> |
| 79 |
<li><a href="#overview">Overview</a></li> |
| 80 |
<li><a href="#installation">Installation</a></li> |
| 81 |
<li><a href="#examples">Examples</a></li> |
| 82 |
<li><a href="#bugs">Bugs</a></li> |
| 83 |
</ol> |
| 84 |
|
| 85 |
<hr /> |
| 86 |
|
| 87 |
<h2><a name="overview" id="overview" class="head">Overview</a></h2> |
| 88 |
|
| 89 |
<p>QDBM provides API for Perl. This encapsulates the basic API, the extended API and the advanced API of QDBM. These APIs are implemented with the APIs for C called with XS language. There are two kinds of interfaces to handle a database: using methods directly and using tying functions with a hash.</p> |
| 90 |
|
| 91 |
<p>In case of using methods, you call the constructor `new' of the class `Depot', `Curia' or `Villa' to open a database file or directory and get the handle. The method `close' is used in order to close the database. If the instance is destroyed without closing the database explicitly, the destructor closes the database. The method `put' is used in order to store a record. The method `out' is used in order to delete a record. The method `get' is used in order to retrieve a record. Besides, most operations like ones of the APIs for C are available.</p> |
| 92 |
|
| 93 |
<p>In case of using tying functions, you call the `tie' function whose parameters are the same as ones of the constructor. After tying, operations with the tied hash perform as operations to the binded database. You use the `untie' function to close the database.</p> |
| 94 |
|
| 95 |
<p>Although keys and values of storing records are treated as strings, binary data can be stored as they are. `Depot' realizes a hash database with a file. `Curia' realizes a hash database with a directory and multiple files. `Villa' realizes a B+ tree database with a file. `Depot' is fastest. `Curia' is most scalable. `Villa' provides cursor supporting ordering access.</p> |
| 96 |
|
| 97 |
<p>For more information about the APIs, read documents in the sub directory `<a href="plapidoc/">plapidoc</a>'.</p> |
| 98 |
|
| 99 |
<hr /> |
| 100 |
|
| 101 |
<h2><a name="installation" id="installation" class="head">Installation</a></h2> |
| 102 |
|
| 103 |
<p>Make sure that Perl 5.6.0 or later version is installed and make sure that QDBM is installed under `/usr/local'.</p> |
| 104 |
|
| 105 |
<p>Change the current working directory to the sub directory named `perl'.</p> |
| 106 |
|
| 107 |
<pre>cd perl |
| 108 |
</pre> |
| 109 |
|
| 110 |
<p>Run the configuration script.</p> |
| 111 |
|
| 112 |
<pre>./configure |
| 113 |
</pre> |
| 114 |
|
| 115 |
<p>Build programs.</p> |
| 116 |
|
| 117 |
<pre>make |
| 118 |
</pre> |
| 119 |
|
| 120 |
<p>Perform self-diagnostic test.</p> |
| 121 |
|
| 122 |
<pre>make check |
| 123 |
</pre> |
| 124 |
|
| 125 |
<p>Install programs. This operation must be carried out by the root user.</p> |
| 126 |
|
| 127 |
<pre>make install |
| 128 |
</pre> |
| 129 |
|
| 130 |
<p>When a series of work finishes, `Depot.so', `Depot.pm', `Curia.so', `Curia.pm', `Villa.so', `Villa.pm', and so on are installed under an appropriate directory according to the install directory of Perl. Executable commands `pldptest', `plcrtest', and `plvltest' will be installed in `/usr/local/bin'.</p> |
| 131 |
|
| 132 |
<p>To uninstall them, execute the following command after `./configure'. This operation must be carried out by the root user.</p> |
| 133 |
|
| 134 |
<pre>make uninstall |
| 135 |
</pre> |
| 136 |
|
| 137 |
<hr /> |
| 138 |
|
| 139 |
<h2><a name="examples" id="examples" class="head">Examples</a></h2> |
| 140 |
|
| 141 |
<p>The following example stores and retrieves a phone number, using the name as the key.</p> |
| 142 |
|
| 143 |
<pre>use Depot; |
| 144 |
|
| 145 |
use constant NAME => "mikio"; |
| 146 |
use constant NUMBER => "000-1234-5678"; |
| 147 |
use constant DBNAME => "book"; |
| 148 |
|
| 149 |
sub main { |
| 150 |
my($depot, $val); |
| 151 |
|
| 152 |
# open the database |
| 153 |
if(!($depot = new Depot(&DBNAME, Depot::OWRITER | Depot::OCREAT))){ |
| 154 |
printf(STDERR "new failed: %s\n", $Depot::errmsg); |
| 155 |
return 1; |
| 156 |
} |
| 157 |
|
| 158 |
# store the record |
| 159 |
if(!$depot->put(&NAME, &NUMBER)){ |
| 160 |
printf(STDERR "put failed: %s\n", $Depot::errmsg); |
| 161 |
} |
| 162 |
|
| 163 |
# retrieve the record |
| 164 |
if(!($val = $depot->get(&NAME))){ |
| 165 |
printf(STDERR "get failed: %s\n", $Depot::errmsg); |
| 166 |
} else { |
| 167 |
printf("Name: %s\n", &NAME); |
| 168 |
printf("Number: %s\n", $val); |
| 169 |
} |
| 170 |
|
| 171 |
# close the database |
| 172 |
if(!$depot->close()){ |
| 173 |
printf(STDERR "close failed: %s\n", $Depot::errmsg); |
| 174 |
return 1; |
| 175 |
} |
| 176 |
|
| 177 |
return 0; |
| 178 |
} |
| 179 |
|
| 180 |
exit(main()); |
| 181 |
</pre> |
| 182 |
|
| 183 |
<p>The following example is a transcription of the one above, using tying functions.</p> |
| 184 |
|
| 185 |
<pre>use Depot; |
| 186 |
|
| 187 |
use constant NAME => "mikio"; |
| 188 |
use constant NUMBER => "000-1234-5678"; |
| 189 |
use constant DBNAME => "book"; |
| 190 |
|
| 191 |
sub main { |
| 192 |
my(%hash, $val); |
| 193 |
|
| 194 |
# open the database |
| 195 |
if(!tie(%hash, "Depot", &DBNAME, Depot::OWRITER | Depot::OCREAT)){ |
| 196 |
printf(STDERR "tie failed: %s\n", $Depot::errmsg); |
| 197 |
return 1; |
| 198 |
} |
| 199 |
|
| 200 |
# store the record |
| 201 |
if(!($hash{&NAME} = &NUMBER)){ |
| 202 |
printf(STDERR "store failed: %s\n", $Depot::errmsg); |
| 203 |
} |
| 204 |
|
| 205 |
# retrieve the record |
| 206 |
if(!($val = $hash{&NAME})){ |
| 207 |
printf(STDERR "fetch failed: %s\n", $Depot::errmsg); |
| 208 |
} else { |
| 209 |
printf("Name: %s\n", &NAME); |
| 210 |
printf("Number: %s\n", $val); |
| 211 |
} |
| 212 |
|
| 213 |
# close the record |
| 214 |
if(!untie(%hash)){ |
| 215 |
printf(STDERR "untie failed: %s\n", $Depot::errmsg); |
| 216 |
return 1; |
| 217 |
} |
| 218 |
|
| 219 |
return 0; |
| 220 |
} |
| 221 |
|
| 222 |
exit(main()); |
| 223 |
</pre> |
| 224 |
|
| 225 |
<p>The following example performs forward matching search for strings, using the class `Villa'.</p> |
| 226 |
|
| 227 |
<pre>use Villa; |
| 228 |
|
| 229 |
use constant DBNAME => "words"; |
| 230 |
use constant PREFIX => "apple"; |
| 231 |
|
| 232 |
sub main { |
| 233 |
my($villa, $key, $val); |
| 234 |
|
| 235 |
# open the database |
| 236 |
if(!($villa = new Villa(&DBNAME, Villa::OWRITER | Villa::OCREAT))){ |
| 237 |
printf(STDERR "new failed: %s\n", $Villa::errmsg); |
| 238 |
return 1; |
| 239 |
} |
| 240 |
|
| 241 |
# store the record |
| 242 |
if(!$villa->put("applet", "little application", Villa::DDUP) || |
| 243 |
!$villa->put("aurora", "polar wonderwork", Villa::DDUP) || |
| 244 |
!$villa->put("apple", "delicious fruit", Villa::DDUP) || |
| 245 |
!$villa->put("amigo", "good friend", Villa::DDUP) || |
| 246 |
!$villa->put("apple", "big city", Villa::DDUP)){ |
| 247 |
printf(STDERR "put failed: %s\n", $Villa::errmsg); |
| 248 |
} |
| 249 |
|
| 250 |
# set the cursor at the top of candidates |
| 251 |
$villa->curjump(&PREFIX); |
| 252 |
|
| 253 |
# scan with the cursor |
| 254 |
while($key = $villa->curkey()){ |
| 255 |
my($prefix) = &PREFIX; |
| 256 |
($key =~ m/^$prefix/) || last; |
| 257 |
$val = $villa->curval(); |
| 258 |
printf("%s: %s\n", $key, $val); |
| 259 |
$villa->curnext(); |
| 260 |
} |
| 261 |
|
| 262 |
# close the database |
| 263 |
if(!$villa->close()){ |
| 264 |
printf(STDERR "close failed: %s\n", $Villa::errmsg); |
| 265 |
return 1; |
| 266 |
} |
| 267 |
|
| 268 |
return 0; |
| 269 |
} |
| 270 |
|
| 271 |
exit(main()); |
| 272 |
</pre> |
| 273 |
|
| 274 |
<hr /> |
| 275 |
|
| 276 |
<h2><a name="bugs" id="bugs" class="head">Bugs</a></h2> |
| 277 |
|
| 278 |
<p>So far, this API is not associated with AnyDBM_File.</p> |
| 279 |
|
| 280 |
<p>This API can be implemented more effectively by Perl hackers.</p> |
| 281 |
|
| 282 |
<p>For the sake of simplicity of interface, Curia for Perl does not feature handling large objects, and Villa for Perl can not be binded with a comparing function defined by users.</p> |
| 283 |
|
| 284 |
<hr /> |
| 285 |
|
| 286 |
</body> |
| 287 |
|
| 288 |
</html> |
| 289 |
|
| 290 |
|