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>Berkeley DB Concepts</title> 7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.62.4" /> 9 <link rel="home" href="index.html" title="Getting Started with Berkeley DB" /> 10 <link rel="up" href="introduction.html" title="Chapter 1. Introduction to Berkeley DB " /> 11 <link rel="previous" href="introduction.html" title="Chapter 1. Introduction to Berkeley DB " /> 12 <link rel="next" href="accessmethods.html" title="Access Methods" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Berkeley DB Concepts</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="introduction.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 1. Introduction to Berkeley DB </th> 23 <td width="20%" align="right"> <a accesskey="n" href="accessmethods.html">Next</a></td> 24 </tr> 25 </table> 26 <hr /> 27 </div> 28 <div class="sect1" lang="en" xml:lang="en"> 29 <div class="titlepage"> 30 <div> 31 <div> 32 <h2 class="title" style="clear: both"><a id="concepts"></a>Berkeley DB Concepts</h2> 33 </div> 34 </div> 35 <div></div> 36 </div> 37 <p> 38 Before continuing, it is useful to describe some of the larger concepts 39 that you will encounter when building a DB application. 40 </p> 41 <p> 42 Conceptually, DB databases contain <span class="emphasis"><em>records</em></span>. 43 Logically each record represents a single entry in the database. 44 Each such record contains two pieces of information: a key and a data. 45 This manual will on occasion describe a <span class="emphasis"><em>a record's 46 key</em></span> or a <span class="emphasis"><em>record's data</em></span> when it is 47 necessary to speak to one or the other portion of a database 48 record. 49 </p> 50 <p> 51 Because of the key/data pairing used for DB databases, they are 52 sometimes thought of as a two-column table. However, data (and 53 sometimes keys, depending on the access method) can hold arbitrarily 54 complex data. Frequently, C structures and other such mechanisms are 55 stored in the record. This effectively turns a 2-column table 56 into a table with <span class="emphasis"><em>n</em></span> columns, where 57 <span class="emphasis"><em>n-1</em></span> of those columns are provided by the structure's 58 fields. 59 </p> 60 <p> 61 Note that a DB database is very much like a table in a relational 62 database system in that most DB applications use more than one 63 database (just as most relational databases use more than one table). 64 </p> 65 <p> 66 Unlike relational systems, however, a DB database contains a single 67 collection of records organized according to a given access method 68 (BTree, Queue, Hash, and so forth). In a relational database system, 69 the underlying access method is generally hidden from you. 70 </p> 71 <p> 72 In any case, frequently DB 73 applications are designed so that a single database stores a specific 74 type of data (just as in a relational database system, a single table 75 holds entries containing a specific set of fields). Because most applications 76 are required to manage multiple kinds of data, a DB application will 77 often use multiple databases. 78 </p> 79 <p> 80 For example, consider an accounting application. This kind of an 81 application may manage data based on bank accounts, checking 82 accounts, stocks, bonds, loans, and so forth. An accounting application 83 will also have to manage information about people, banking institutions, 84 customer accounts, and so on. In a traditional relational database, all 85 of these different kinds of information would be stored and managed 86 using a (probably very) complex series of tables. In a DB 87 application, all of this information would instead be divided out and 88 managed using multiple databases. 89 </p> 90 <p> 91 DB applications can efficiently use multiple databases using an 92 optional mechanism called an <span class="emphasis"><em>environment</em></span>. 93 For more information, see <a href="environments.html">Environments</a>. 94 </p> 95 <p> 96 You interact with most DB APIs using special structures that 97 contain pointers to functions. These callbacks are 98 called <span class="emphasis"><em>methods</em></span> because they look so much like a 99 method on a C++ class. The variable that you use to access these 100 methods is often referred to as a 101 <span class="emphasis"><em>handle</em></span>. For example, to use a database you will 102 obtain a handle to that database. 103 </p> 104 <p> 105 Retrieving a record from a database is sometimes called 106 <span class="emphasis"><em>getting the record</em></span> because the method that you use 107 to retrieve the records is called <tt class="methodname">get()</tt>. 108 Similarly, storing database records is sometimes called 109 <span class="emphasis"><em>putting the record</em></span> because you use the 110 <tt class="methodname">put()</tt> method to do this. 111 </p> 112 <p> 113 When you store, or put, a record to a database using its handle, the 114 record is stored according to whatever sort order is in use by the 115 database. Sorting is mostly performed based on the key, but sometimes 116 the data is considered too. If you put a record using a key that already 117 exists in the database, then the existing record is replaced with the 118 new data. However, if the database supports 119 duplicate records (that is, records with identical keys but 120 different data), then that new record is stored as a duplicate record and 121 any existing records are not overwritten. 122 </p> 123 <p> 124 If a database supports duplicate records, then you can use a database 125 handle to retrieve only the first record in a set of duplicate records. 126 </p> 127 <p> 128 In addition to using a database handle, you can also read and write data using a 129 special mechanism called a <span class="emphasis"><em>cursor</em></span>. Cursors are 130 essentially iterators that you can use to walk over the records in a 131 database. You can use cursors to iterate over a database from the first 132 record to the last, and from the last to the first. You can also use 133 cursors to seek to a record. In the event that a database supports 134 duplicate records, cursors are the only way you can access all the 135 records in a set of duplicates. 136 </p> 137 <p> 138 Finally, DB provides a special kind of a database called a 139 <span class="emphasis"><em>secondary database</em></span>. Secondary databases serve as an 140 index into normal databases (called primary database to distinguish them 141 from secondaries). Secondary databases are interesting because DB 142 records can hold complex data types, but seeking to a given record is 143 performed only based on that record's key. If you wanted to be able to 144 seek to a record based on some piece of information that is not the key, 145 then you enable this through the use of secondary databases. 146 </p> 147 </div> 148 <div class="navfooter"> 149 <hr /> 150 <table width="100%" summary="Navigation footer"> 151 <tr> 152 <td width="40%" align="left"><a accesskey="p" href="introduction.html">Prev</a> </td> 153 <td width="20%" align="center"> 154 <a accesskey="u" href="introduction.html">Up</a> 155 </td> 156 <td width="40%" align="right"> <a accesskey="n" href="accessmethods.html">Next</a></td> 157 </tr> 158 <tr> 159 <td width="40%" align="left" valign="top">Chapter 1. Introduction to Berkeley DB </td> 160 <td width="20%" align="center"> 161 <a accesskey="h" href="index.html">Home</a> 162 </td> 163 <td width="40%" align="right" valign="top"> Access Methods</td> 164 </tr> 165 </table> 166 </div> 167 </body> 168</html> 169