concepts.html   [plain text]


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Berkeley DB Concepts</title>
    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.62.4" />
    <link rel="home" href="index.html" title="Getting Started with Berkeley DB" />
    <link rel="up" href="introduction.html" title="Chapter 1. Introduction to Berkeley DB " />
    <link rel="previous" href="introduction.html" title="Chapter 1. Introduction to Berkeley DB " />
    <link rel="next" href="accessmethods.html" title="Access Methods" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Berkeley DB Concepts</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="introduction.html">Prev</a> </td>
          <th width="60%" align="center">Chapter 1. Introduction to Berkeley DB </th>
          <td width="20%" align="right"> <a accesskey="n" href="accessmethods.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both"><a id="concepts"></a>Berkeley DB Concepts</h2>
          </div>
        </div>
        <div></div>
      </div>
      <p>
        Before continuing, it is useful to describe some of the larger concepts
        that you will encounter when building a DB application.
    </p>
      <p>
        Conceptually, DB databases contain <span class="emphasis"><em>records</em></span>.
        Logically each record represents a single entry in the database. 
        Each such record contains two pieces of information: a key and a data.
        This manual will on occasion describe a <span class="emphasis"><em>a record's
        key</em></span> or a <span class="emphasis"><em>record's data</em></span> when it is
        necessary to speak to one or the other portion of a database
        record.
    </p>
      <p>
        Because of the key/data pairing used for DB databases, they are
        sometimes thought of as a two-column table.  However, data (and
        sometimes keys, depending on the access method) can hold arbitrarily
        complex data. Frequently, C structures and other such mechanisms are
        stored in the record. This effectively turns a 2-column table
        into a table with <span class="emphasis"><em>n</em></span> columns, where
        <span class="emphasis"><em>n-1</em></span> of those columns are provided by the structure's
        fields.
    </p>
      <p>
        Note that a DB database is very much like a table in a relational
        database system in that most DB applications use more than one 
        database (just as most relational databases use more than one table). 
    </p>
      <p>
        Unlike relational systems, however, a DB database contains a single 
        collection of records organized according to a given access method 
        (BTree, Queue, Hash, and so forth). In a relational database system,
        the underlying access method is generally hidden from you. 
     </p>
      <p>
        In any case, frequently DB
        applications are designed so that a single database stores a specific 
        type of data (just as in a relational database system, a single table
        holds entries containing a specific set of fields). Because most applications 
        are required to manage multiple kinds of data, a DB application will 
        often use multiple databases.
    </p>
      <p>
        For example, consider an accounting application. This kind of an
        application may manage data based on bank accounts, checking
        accounts, stocks, bonds, loans, and so forth. An accounting application
        will also have to manage information about people, banking institutions,
        customer accounts, and so on. In a traditional relational database, all
        of these different kinds of information would be stored and managed
        using a (probably very) complex series of tables. In a DB
        application, all of this information would instead be divided out and 
        managed using multiple databases.
    </p>
      <p>
        DB applications can efficiently use multiple databases using an
        optional mechanism called an <span class="emphasis"><em>environment</em></span>.
        For more information, see <a href="environments.html">Environments</a>.
     </p>
      <p>
        You interact with most DB APIs using special structures that
        contain pointers to functions. These callbacks are
        called <span class="emphasis"><em>methods</em></span> because they look so much like a
        method on a C++ class. The variable that you use to access these
        methods is often referred to as a
        <span class="emphasis"><em>handle</em></span>. For example, to use a database you will
        obtain a handle to that database.
     </p>
      <p>
        Retrieving a record from a database is sometimes called
        <span class="emphasis"><em>getting the record</em></span> because the method that you use
        to retrieve the records is called <tt class="methodname">get()</tt>.
        Similarly, storing database records is sometimes called
        <span class="emphasis"><em>putting the record</em></span> because you use the
        <tt class="methodname">put()</tt> method to do this.
     </p>
      <p>
        When you store, or put, a record to a database using its handle, the
        record is stored according to whatever sort order is in use by the
        database. Sorting is mostly performed based on the key, but sometimes
        the data is considered too. If you put a record using a key that already
        exists in the database, then the existing record is replaced with the
        new data.  However, if the database supports
        duplicate records (that is, records with identical keys but
        different data), then that new record is stored as a duplicate record and
        any existing records are not overwritten.
     </p>
      <p>
        If a database supports duplicate records, then you can use a database
        handle to retrieve only the first record in a set of duplicate records.
     </p>
      <p>
        In addition to using a database handle, you can also read and write data using a
        special mechanism called a <span class="emphasis"><em>cursor</em></span>. Cursors are
        essentially iterators that you can use to walk over the records in a
        database. You can use cursors to iterate over a database from the first
        record to the last, and from the last to the first. You can also use
        cursors to seek to a record. In the event that a database supports
        duplicate records, cursors are the only way you can access all the
        records in a set of duplicates.
     </p>
      <p>
        Finally, DB provides a special kind of a database called a
        <span class="emphasis"><em>secondary database</em></span>. Secondary databases serve as an
        index into normal databases (called primary database to distinguish them
        from secondaries). Secondary databases are interesting because DB
        records can hold complex data types, but seeking to a given record is
        performed only based on that record's key. If you wanted to be able to
        seek to a record based on some piece of information that is not the key,
        then you enable this through the use of secondary databases.
     </p>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="introduction.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="introduction.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="accessmethods.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Chapter 1. Introduction to Berkeley DB  </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> Access Methods</td>
        </tr>
      </table>
    </div>
  </body>
</html>