1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>Chapter 2. The DB Handle</title> 7 <link rel="stylesheet" href="apiReference.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> 9 <link rel="start" href="index.html" title="Berkeley DB C API Reference" /> 10 <link rel="up" href="index.html" title="Berkeley DB C API Reference" /> 11 <link rel="prev" href="introduction.html" title="Chapter 1. Introduction to Berkeley DB APIs" /> 12 <link rel="next" href="dbassociate.html" title="DB->associate()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Chapter 2. 19 The DB Handle 20 </th> 21 </tr> 22 <tr> 23 <td width="20%" align="left"><a accesskey="p" href="introduction.html">Prev</a> </td> 24 <th width="60%" align="center"> </th> 25 <td width="20%" align="right"> <a accesskey="n" href="dbassociate.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="chapter" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title"><a id="db"></a>Chapter 2. 35 The DB Handle 36 </h2> 37 </div> 38 </div> 39 </div> 40 <p> 41 The DB is the handle for a single Berkeley DB database. A Berkeley DB database 42 provides a mechanism for organizing key-data pairs of information. From the 43 perspective of some database systems, a Berkeley DB database could be thought of as 44 a single table within a larger database. 45 </p> 46 <p> 47 You create a DB handle using the <a class="xref" href="dbcreate.html" title="db_create">db_create</a> 48 <span>function.</span> 49 50 For most database activities, you must then open the handle using the 51 <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> 52 method. When you are done with them, handles must be closed using the 53 <a class="xref" href="dbclose.html" title="DB->close()">DB->close()</a> method. 54 </p> 55 <p> 56 Alternatively, you can create a DB and then rename, remove or verify the database 57 without performing an open. See <a class="xref" href="dbrename.html" title="DB->rename()">DB->rename()</a>, 58 <a class="xref" href="dbremove.html" title="DB->remove()">DB->remove()</a> or 59 <a class="xref" href="dbverify.html" title="DB->verify()">DB->verify()</a> for information on these 60 activities. 61 </p> 62 <p> 63 It is possible to create databases such that they are organized within a 64 <span class="emphasis"><em>database environment</em></span>. Environments are optional for simple Berkeley 65 DB applications that do not use transactions, recovery, replication or any other 66 advanced features. For simple Berkeley DB applications, environments still offer some 67 advantages. For example, they provide some organizational 68 benefits on-disk (all databases are located on disk relative to the environment). Also, 69 if you are using multiple databases, then environments allow your databases to share a 70 common in-memory cache, which makes for more efficient usage of your hardware's 71 resources. 72 </p> 73 <p> 74 See <a class="link" href="env.html" title="Chapter 5. The DB_ENV Handle">DB_ENV</a> for information on using database 75 environments. 76 </p> 77 <p> 78 You specify the underlying organization of the data in the database (e.g. BTree, Hash, 79 Queue, and Recno) when you open the database. When you create a database, 80 you are free to specify any of the available database types. On subsequent opens, 81 you must either specify the access method used when you first opened the database, or 82 you can specify <code class="literal">DB_UNKNOWN</code> in order to have this information 83 retrieved for you. See the <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> 84 method for information on specifying database types. 85 </p> 86 <div class="sect1" lang="en" xml:lang="en"> 87 <div class="titlepage"> 88 <div> 89 <div> 90 <h2 class="title" style="clear: both"><a id="dblist"></a>Database and Related Methods</h2> 91 </div> 92 </div> 93 </div> 94 <div class="navtable"> 95 <table border="1" width="80%"> 96 <thead> 97 <tr> 98 <th>Database Operations</th> 99 <th>Description</th> 100 </tr> 101 </thead> 102 <tbody> 103 <tr> 104 <td> 105 <a class="xref" href="dbassociate.html" title="DB->associate()">DB->associate()</a> 106 </td> 107 <td>Associate a secondary index</td> 108 </tr> 109 <tr> 110 <td> 111 <a class="xref" href="dbassociate_foreign.html" title="DB->associate_foreign()">DB->associate_foreign()</a> 112 </td> 113 <td>Associate a foreign index</td> 114 </tr> 115 <tr> 116 <td> 117 <a class="xref" href="dbclose.html" title="DB->close()">DB->close()</a> 118 </td> 119 <td>Close a database</td> 120 </tr> 121 <tr> 122 <td> 123 <a class="xref" href="dbcreate.html" title="db_create">db_create</a> 124 </td> 125 <td>Create a database handle</td> 126 </tr> 127 <tr> 128 <td> 129 <a class="xref" href="dbcompact.html" title="DB->compact()">DB->compact()</a> 130 </td> 131 <td>Compact a database</td> 132 </tr> 133 <tr> 134 <td> 135 <a class="xref" href="dbdel.html" title="DB->del()">DB->del()</a> 136 </td> 137 <td>Delete items from a database</td> 138 </tr> 139 <tr> 140 <td> 141 <a class="xref" href="dberr.html" title="DB->err()">DB->err()</a> 142 </td> 143 <td>Error message</td> 144 </tr> 145 <tr> 146 <td> 147 <a class="xref" href="dbexists.html" title="DB->exists()">DB->exists()</a> 148 </td> 149 <td>Return if an item appears in a database</td> 150 </tr> 151 <tr> 152 <td> 153 <a class="xref" href="dbfd.html" title="DB->fd()">DB->fd()</a> 154 </td> 155 <td>Return a file descriptor from a database</td> 156 </tr> 157 <tr> 158 <td> 159 <a class="xref" href="dbget.html" title="DB->get()">DB->get()</a> 160 </td> 161 <td>Get items from a database</td> 162 </tr> 163 <tr> 164 <td> 165 <a class="xref" href="dbget_byteswapped.html" title="DB->get_byteswapped()">DB->get_byteswapped()</a> 166 </td> 167 <td>Return if the underlying database is in host order</td> 168 </tr> 169 <tr> 170 <td> 171 <a class="xref" href="dbget_dbname.html" title="DB->get_dbname()">DB->get_dbname()</a> 172 </td> 173 <td>Return the file and database name</td> 174 </tr> 175 <tr> 176 <td> 177 <a class="xref" href="dbget_multiple.html" title="DB->get_multiple()">DB->get_multiple()</a> 178 </td> 179 <td>Return if the database handle references multiple databases</td> 180 </tr> 181 <tr> 182 <td> 183 <a class="xref" href="dbget_open_flags.html" title="DB->get_open_flags()">DB->get_open_flags()</a> 184 </td> 185 <td>Returns the flags specified to DB->open</td> 186 </tr> 187 <tr> 188 <td> 189 <a class="xref" href="dbget_type.html" title="DB->get_type()">DB->get_type()</a> 190 </td> 191 <td>Return the database type</td> 192 </tr> 193 <tr> 194 <td> 195 <a class="xref" href="dbjoin.html" title="DB->join()">DB->join()</a> 196 </td> 197 <td>Perform a database join on cursors</td> 198 </tr> 199 <tr> 200 <td> 201 <a class="xref" href="dbkey_range.html" title="DB->key_range()">DB->key_range()</a> 202 </td> 203 <td>Return estimate of key location</td> 204 </tr> 205 <tr> 206 <td> 207 <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> 208 </td> 209 <td>Open a database</td> 210 </tr> 211 <tr> 212 <td> 213 <a class="xref" href="dbput.html" title="DB->put()">DB->put()</a> 214 </td> 215 <td>Store items into a database</td> 216 </tr> 217 <tr> 218 <td> 219 <a class="xref" href="dbremove.html" title="DB->remove()">DB->remove()</a> 220 </td> 221 <td>Remove a database</td> 222 </tr> 223 <tr> 224 <td> 225 <a class="xref" href="dbrename.html" title="DB->rename()">DB->rename()</a> 226 </td> 227 <td>Rename a database</td> 228 </tr> 229 <tr> 230 <td><a class="xref" href="dbset_priority.html" title="DB->set_priority()">DB->set_priority()</a>, <a class="xref" href="dbget_priority.html" title="DB->get_priority()">DB->get_priority()</a></td> 231 <td>Set/get cache page priority</td> 232 </tr> 233 <tr> 234 <td> 235 <a class="xref" href="dbstat.html" title="DB->stat()">DB->stat()</a> 236 </td> 237 <td>Database statistics</td> 238 </tr> 239 <tr> 240 <td> 241 <a class="xref" href="dbstat_print.html" title="DB->stat_print()">DB->stat_print()</a> 242 </td> 243 <td>Display database statistics</td> 244 </tr> 245 <tr> 246 <td> 247 <a class="xref" href="dbsync.html" title="DB->sync()">DB->sync()</a> 248 </td> 249 <td>Flush a database to stable storage</td> 250 </tr> 251 <tr> 252 <td> 253 <a class="xref" href="dbtruncate.html" title="DB->truncate()">DB->truncate()</a> 254 </td> 255 <td>Empty a database</td> 256 </tr> 257 <tr> 258 <td> 259 <a class="xref" href="dbupgrade.html" title="DB->upgrade()">DB->upgrade()</a> 260 </td> 261 <td>Upgrade a database</td> 262 </tr> 263 <tr> 264 <td> 265 <a class="xref" href="dbverify.html" title="DB->verify()">DB->verify()</a> 266 </td> 267 <td>Verify/salvage a database</td> 268 </tr> 269 <tr> 270 <td> 271 <a class="xref" href="dbcursor.html" title="DB->cursor()">DB->cursor()</a> 272 </td> 273 <td>Create a cursor handle</td> 274 </tr> 275 <tr> 276 <td colspan="2"> 277 <span class="bold"> 278 <strong>Database Configuration</strong> 279 </span> 280 </td> 281 </tr> 282 <tr> 283 <td> 284 <a class="xref" href="dbset_alloc.html" title="DB->set_alloc()">DB->set_alloc()</a> 285 </td> 286 <td>Set local space allocation functions</td> 287 </tr> 288 <tr> 289 <td><a class="xref" href="dbset_cachesize.html" title="DB->set_cachesize()">DB->set_cachesize()</a>, <a class="xref" href="dbget_cachesize.html" title="DB->get_cachesize()">DB->get_cachesize()</a></td> 290 <td>Set/get the database cache size</td> 291 </tr> 292 <tr> 293 <td><a class="xref" href="dbset_create_dir.html" title="DB->set_create_dir()">DB->set_create_dir()</a>, <a class="xref" href="dbget_create_dir.html" title="DB->get_create_dir()">DB->get_create_dir()</a></td> 294 <td>Set/get the directory in which a database is placed</td> 295 </tr> 296 <tr> 297 <td> 298 <a class="xref" href="dbset_dup_compare.html" title="DB->set_dup_compare()">DB->set_dup_compare()</a> 299 </td> 300 <td>Set a duplicate comparison function</td> 301 </tr> 302 <tr> 303 <td><a class="xref" href="dbset_encrypt.html" title="DB->set_encrypt()">DB->set_encrypt()</a>, <a class="xref" href="dbget_encrypt_flags.html" title="DB->get_encrypt_flags()">DB->get_encrypt_flags()</a></td> 304 <td>Set/get the database cryptographic key</td> 305 </tr> 306 <tr> 307 <td> 308 <a class="xref" href="dbset_errcall.html" title="DB->set_errcall()">DB->set_errcall()</a> 309 </td> 310 <td>Set error message callback</td> 311 </tr> 312 <tr> 313 <td><a class="xref" href="dbset_errfile.html" title="DB->set_errfile()">DB->set_errfile()</a>, <a class="xref" href="dbget_errfile.html" title="DB->get_errfile()">DB->get_errfile()</a></td> 314 <td>Set/get error message FILE</td> 315 </tr> 316 <tr> 317 <td><a class="xref" href="dbset_errpfx.html" title="DB->set_errpfx()">DB->set_errpfx()</a>, <a class="xref" href="dbget_errpfx.html" title="DB->get_errpfx()">DB->get_errpfx()</a></td> 318 <td>Set/get error message prefix</td> 319 </tr> 320 <tr> 321 <td> 322 <a class="xref" href="dbset_feedback.html" title="DB->set_feedback()">DB->set_feedback()</a> 323 </td> 324 <td>Set feedback callback</td> 325 </tr> 326 <tr> 327 <td><a class="xref" href="dbset_flags.html" title="DB->set_flags()">DB->set_flags()</a>, <a class="xref" href="dbget_flags.html" title="DB->get_flags()">DB->get_flags()</a></td> 328 <td>Set/get general database configuration</td> 329 </tr> 330 <tr> 331 <td><a class="xref" href="dbset_lorder.html" title="DB->set_lorder()">DB->set_lorder()</a>, <a class="xref" href="dbget_lorder.html" title="DB->get_lorder()">DB->get_lorder()</a></td> 332 <td>Set/get the database byte order</td> 333 </tr> 334 <tr> 335 <td> 336 <a class="xref" href="dbset_msgcall.html" title="DB->set_msgcall()">DB->set_msgcall()</a> 337 </td> 338 <td>Set informational message callback</td> 339 </tr> 340 <tr> 341 <td><a class="xref" href="dbset_msgfile.html" title="DB->set_msgfile()">DB->set_msgfile()</a>, <a class="xref" href="dbget_msgfile.html" title="DB->get_msgfile()">DB->get_msgfile()</a></td> 342 <td>Set/get informational message FILE</td> 343 </tr> 344 <tr> 345 <td><a class="xref" href="dbset_pagesize.html" title="DB->set_pagesize()">DB->set_pagesize()</a>, <a class="xref" href="dbget_pagesize.html" title="DB->get_pagesize()">DB->get_pagesize()</a></td> 346 <td>Set/get the underlying database page size</td> 347 </tr> 348 <tr> 349 <td> 350 <a class="xref" href="dbset_partition.html" title="DB->set_partition()">DB->set_partition()</a> 351 </td> 352 <td>Set database partitioning</td> 353 </tr> 354 <tr> 355 <td><a class="xref" href="dbset_partition_dirs.html" title="DB->set_partition_dirs()">DB->set_partition_dirs()</a>, <a class="xref" href="dbget_partition_dirs.html" title="DB->get_partition_dirs()">DB->get_partition_dirs()</a></td> 356 <td>Set/get the directories used for database partitions</td> 357 </tr> 358 <tr> 359 <td colspan="2"> 360 <span class="bold"> 361 <strong>Btree/Recno Configuration</strong> 362 </span> 363 </td> 364 </tr> 365 <tr> 366 <td> 367 <a class="xref" href="dbset_append_recno.html" title="DB->set_append_recno()">DB->set_append_recno()</a> 368 </td> 369 <td>Set record append callback</td> 370 </tr> 371 <tr> 372 <td> 373 <a class="xref" href="dbset_bt_compare.html" title="DB->set_bt_compare()">DB->set_bt_compare()</a> 374 </td> 375 <td>Set a Btree comparison function</td> 376 </tr> 377 <tr> 378 <td> 379 <a class="xref" href="dbset_bt_compress.html" title="DB->set_bt_compress()">DB->set_bt_compress()</a> 380 </td> 381 <td>Set Btree compression functions</td> 382 </tr> 383 <tr> 384 <td><a class="xref" href="dbset_bt_minkey.html" title="DB->set_bt_minkey()">DB->set_bt_minkey()</a>, <a class="xref" href="dbget_bt_minkey.html" title="DB->get_bt_minkey()">DB->get_bt_minkey()</a></td> 385 <td>Set/get the minimum number of keys per Btree page</td> 386 </tr> 387 <tr> 388 <td> 389 <a class="xref" href="dbset_bt_prefix.html" title="DB->set_bt_prefix()">DB->set_bt_prefix()</a> 390 </td> 391 <td>Set a Btree prefix comparison function</td> 392 </tr> 393 <tr> 394 <td><a class="xref" href="dbset_re_delim.html" title="DB->set_re_delim()">DB->set_re_delim()</a>, <a class="xref" href="dbget_re_delim.html" title="DB->get_re_delim()">DB->get_re_delim()</a></td> 395 <td>Set/get the variable-length record delimiter</td> 396 </tr> 397 <tr> 398 <td><a class="xref" href="dbset_re_len.html" title="DB->set_re_len()">DB->set_re_len()</a>, <a class="xref" href="dbget_re_len.html" title="DB->get_re_len()">DB->get_re_len()</a></td> 399 <td>Set/get the fixed-length record length</td> 400 </tr> 401 <tr> 402 <td><a class="xref" href="dbset_re_pad.html" title="DB->set_re_pad()">DB->set_re_pad()</a>, <a class="xref" href="dbget_re_pad.html" title="DB->get_re_pad()">DB->get_re_pad()</a></td> 403 <td>Set/get the fixed-length record pad byte</td> 404 </tr> 405 <tr> 406 <td><a class="xref" href="dbset_re_source.html" title="DB->set_re_source()">DB->set_re_source()</a>, <a class="xref" href="dbget_re_source.html" title="DB->get_re_source()">DB->get_re_source()</a></td> 407 <td>Set/get the backing Recno text file</td> 408 </tr> 409 <tr> 410 <td colspan="2"> 411 <span class="bold"> 412 <strong>Hash Configuration</strong> 413 </span> 414 </td> 415 </tr> 416 <tr> 417 <td> 418 <a class="xref" href="dbset_h_compare.html" title="DB->set_h_compare()">DB->set_h_compare()</a> 419 </td> 420 <td>Set a Hash comparison function</td> 421 </tr> 422 <tr> 423 <td><a class="xref" href="dbset_h_ffactor.html" title="DB->set_h_ffactor()">DB->set_h_ffactor()</a>, <a class="xref" href="dbget_h_ffactor.html" title="DB->get_h_ffactor()">DB->get_h_ffactor()</a></td> 424 <td>Set/get the Hash table density</td> 425 </tr> 426 <tr> 427 <td> 428 <a class="xref" href="dbset_h_hash.html" title="DB->set_h_hash()">DB->set_h_hash()</a> 429 </td> 430 <td>Set a hashing function</td> 431 </tr> 432 <tr> 433 <td><a class="xref" href="dbset_h_nelem.html" title="DB->set_h_nelem()">DB->set_h_nelem()</a>, <a class="xref" href="dbget_h_nelem.html" title="DB->get_h_nelem()">DB->get_h_nelem()</a></td> 434 <td>Set/get the Hash table size</td> 435 </tr> 436 <tr> 437 <td colspan="2"> 438 <span class="bold"> 439 <strong>Queue Configuration</strong> 440 </span> 441 </td> 442 </tr> 443 <tr> 444 <td><a class="xref" href="dbset_q_extentsize.html" title="DB->set_q_extentsize()">DB->set_q_extentsize()</a>, <a class="xref" href="dbget_q_extentsize.html" title="DB->get_q_extentsize()">DB->get_q_extentsize()</a></td> 445 <td>Set/get Queue database extent size</td> 446 </tr> 447 </tbody> 448 </table> 449 </div> 450 </div> 451 </div> 452 <div class="navfooter"> 453 <hr /> 454 <table width="100%" summary="Navigation footer"> 455 <tr> 456 <td width="40%" align="left"><a accesskey="p" href="introduction.html">Prev</a> </td> 457 <td width="20%" align="center"> </td> 458 <td width="40%" align="right"> <a accesskey="n" href="dbassociate.html">Next</a></td> 459 </tr> 460 <tr> 461 <td width="40%" align="left" valign="top">Chapter 1. Introduction to Berkeley DB APIs </td> 462 <td width="20%" align="center"> 463 <a accesskey="h" href="index.html">Home</a> 464 </td> 465 <td width="40%" align="right" valign="top"> DB->associate()</td> 466 </tr> 467 </table> 468 </div> 469 </body> 470</html> 471