| 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>Db</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="db.html" title="Chapter 2. The Db Handle" /> |
| 11 | <link rel="prev" href="db_copy.html" title="db_copy" /> |
| 12 | <link rel="next" href="dbdel.html" title="Db::del()" /> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div xmlns="" class="navheader"> |
| 16 | <div class="libver"> |
| 17 | <p>Library Version 11.2.5.3</p> |
| 18 | </div> |
| 19 | <table width="100%" summary="Navigation header"> |
| 20 | <tr> |
| 21 | <th colspan="3" align="center">Db</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="db_copy.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 2. |
| 26 | The Db Handle |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="dbdel.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="sect1" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title" style="clear: both"><a id="dbcreate"></a>Db</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <pre class="programlisting">#include <db_cxx.h> |
| 42 | |
| 43 | class Db { |
| 44 | public: |
| 45 | Db(DbEnv *dbenv, u_int32_t flags); |
| 46 | ~Db(); |
| 47 | |
| 48 | DB *Db::get_DB(); |
| 49 | const DB *Db::get_const_DB() const; |
| 50 | static Db *Db::get_Db(DB *db); |
| 51 | static const Db *Db::get_const_Db(const DB *db); |
| 52 | ... |
| 53 | }; </pre> |
| 54 | <p> |
| 55 | The Db handle is the handle for a Berkeley DB database, which may or may not be part of a |
| 56 | database environment. |
| 57 | </p> |
| 58 | <p> |
| 59 | Db handles are free-threaded if the |
| 60 | <a class="link" href="envopen.html#envopen_DB_THREAD">DB_THREAD</a> flag is specified to |
| 61 | the <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> method when the database is opened or |
| 62 | if the database environment in which the database is opened is free-threaded. The handle |
| 63 | should not be closed while any other handle that refers to the database is in use; for |
| 64 | example, database handles must not be closed while cursor handles into the database remain |
| 65 | open, or transactions that include operations on the database have not yet been committed |
| 66 | or aborted. Once the <a class="xref" href="dbclose.html" title="Db::close()">Db::close()</a>, |
| 67 | <a class="xref" href="dbremove.html" title="Db::remove()">Db::remove()</a>, |
| 68 | <a class="xref" href="dbrename.html" title="Db::rename()">Db::rename()</a>, or |
| 69 | <a class="xref" href="dbverify.html" title="Db::verify()">Db::verify()</a> |
| 70 | methods are called, the handle may not be accessed again, regardless of the method's return. |
| 71 | </p> |
| 72 | <p> |
| 73 | The constructor creates a <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> object that is the |
| 74 | handle for a Berkeley DB database. The constructor allocates memory internally; calling |
| 75 | the <a class="xref" href="dbclose.html" title="Db::close()">Db::close()</a>, |
| 76 | <a class="xref" href="dbremove.html" title="Db::remove()">Db::remove()</a>, or |
| 77 | <a class="xref" href="dbrename.html" title="Db::rename()">Db::rename()</a> |
| 78 | methods will free that memory. |
| 79 | </p> |
| 80 | <p> |
| 81 | Note that destroying the <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> |
| 82 | object is synonomous with calling <code class="literal">Db::close(0)</code>. |
| 83 | </p> |
| 84 | <p> |
| 85 | Each <code class="methodname">Db</code> object has an associated <code class="methodname">DB</code> |
| 86 | struct, which is used by the underlying implementation of Berkeley DB and its C-language |
| 87 | API. The <code class="methodname">Db::get_DB()</code> method returns a pointer to this struct. |
| 88 | Given a <code class="methodname">const Db</code> object, |
| 89 | <code class="methodname">Db::get_const_DB()</code> returns a const pointer to the same struct. |
| 90 | </p> |
| 91 | <p> |
| 92 | Given a <code class="literal">DB</code> struct, the <code class="methodname">Db::get_Db()</code> method |
| 93 | returns the corresponding <code class="classname">Db</code> object, if there is |
| 94 | one. If the <code class="literal">DB</code> object was not associated with a |
| 95 | <code class="classname">Db</code> (that is, it was not returned from a call |
| 96 | to the <code class="methodname">Db::get_DB()</code> method), then the result of |
| 97 | <code class="methodname">Db::get_Db()</code> is undefined. Given a |
| 98 | <code class="literal">const DB struct</code>, |
| 99 | <code class="methodname">Db::get_const_Db()</code> returns the associated |
| 100 | <code class="literal">const Db</code>object, if there is one. |
| 101 | </p> |
| 102 | <p> |
| 103 | These methods may be useful for Berkeley DB applications including both C and C++ |
| 104 | language software. It should not be necessary to use these calls in a purely C++ |
| 105 | application. |
| 106 | </p> |
| 107 | <div class="sect2" lang="en" xml:lang="en"> |
| 108 | <div class="titlepage"> |
| 109 | <div> |
| 110 | <div> |
| 111 | <h3 class="title"><a id="idm50360"></a>Parameters</h3> |
| 112 | </div> |
| 113 | </div> |
| 114 | </div> |
| 115 | <div class="sect3" lang="en" xml:lang="en"> |
| 116 | <div class="titlepage"> |
| 117 | <div> |
| 118 | <div> |
| 119 | <h4 class="title"><a id="idp88024"></a>dbenv</h4> |
| 120 | </div> |
| 121 | </div> |
| 122 | </div> |
| 123 | <p> |
| 124 | |
| 125 | <span>If no <span class="bold"><strong>dbenv</strong></span> value is specified,</span> |
| 126 | the database is standalone; that is, it is not part of any Berkeley DB |
| 127 | environment. |
| 128 | </p> |
| 129 | <p> |
| 130 | |
| 131 | <span> |
| 132 | If a <span class="bold"><strong>dbenv</strong></span> value is specified, |
| 133 | </span> |
| 134 | the database is created within the specified Berkeley DB environment. |
| 135 | The database access methods automatically make calls to the other |
| 136 | subsystems in Berkeley DB, based on the enclosing environment. For |
| 137 | example, if the environment has been configured to use locking, the |
| 138 | access methods will automatically acquire the correct locks when |
| 139 | reading and writing pages of the database. |
| 140 | </p> |
| 141 | </div> |
| 142 | <div class="sect3" lang="en" xml:lang="en"> |
| 143 | <div class="titlepage"> |
| 144 | <div> |
| 145 | <div> |
| 146 | <h4 class="title"><a id="idm357600"></a>flags</h4> |
| 147 | </div> |
| 148 | </div> |
| 149 | </div> |
| 150 | <p> |
| 151 | The <span class="bold"><strong>flags</strong></span> parameter must be set to 0 or the following value: |
| 152 | </p> |
| 153 | <div class="itemizedlist"> |
| 154 | <ul type="disc"> |
| 155 | <li> |
| 156 | <p> |
| 157 | <code class="literal">DB_CXX_NO_EXCEPTION</code> |
| 158 | </p> |
| 159 | <p> |
| 160 | The Berkeley DB C++ API supports two different error behaviors. By |
| 161 | default, whenever an error occurs, an exception is thrown that |
| 162 | encapsulates the error information. This generally allows for |
| 163 | cleaner logic for transaction processing because a try block can |
| 164 | surround a single transaction. However, if this flag is |
| 165 | specified, exceptions are not thrown; instead, each individual |
| 166 | function returns an error code. |
| 167 | </p> |
| 168 | <p> |
| 169 | If a <span class="bold"><strong>dbenv</strong></span> value is specified, |
| 170 | this flag is ignored, and the error behavior of the specified |
| 171 | environment is used instead. |
| 172 | </p> |
| 173 | </li> |
| 174 | </ul> |
| 175 | </div> |
| 176 | </div> |
| 177 | </div> |
| 178 | <div class="sect2" lang="en" xml:lang="en"> |
| 179 | <div class="titlepage"> |
| 180 | <div> |
| 181 | <div> |
| 182 | <h3 class="title"><a id="idm1691064"></a>Class</h3> |
| 183 | </div> |
| 184 | </div> |
| 185 | </div> |
| 186 | <p> |
| 187 | <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> |
| 188 | </p> |
| 189 | </div> |
| 190 | <div class="sect2" lang="en" xml:lang="en"> |
| 191 | <div class="titlepage"> |
| 192 | <div> |
| 193 | <div> |
| 194 | <h3 class="title"><a id="idm1672480"></a>See Also</h3> |
| 195 | </div> |
| 196 | </div> |
| 197 | </div> |
| 198 | <p> |
| 199 | <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> |
| 200 | </p> |
| 201 | </div> |
| 202 | </div> |
| 203 | <div class="navfooter"> |
| 204 | <hr /> |
| 205 | <table width="100%" summary="Navigation footer"> |
| 206 | <tr> |
| 207 | <td width="40%" align="left"><a accesskey="p" href="db_copy.html">Prev</a> </td> |
| 208 | <td width="20%" align="center"> |
| 209 | <a accesskey="u" href="db.html">Up</a> |
| 210 | </td> |
| 211 | <td width="40%" align="right"> <a accesskey="n" href="dbdel.html">Next</a></td> |
| 212 | </tr> |
| 213 | <tr> |
| 214 | <td width="40%" align="left" valign="top">db_copy </td> |
| 215 | <td width="20%" align="center"> |
| 216 | <a accesskey="h" href="index.html">Home</a> |
| 217 | </td> |
| 218 | <td width="40%" align="right" valign="top"> Db::del()</td> |
| 219 | </tr> |
| 220 | </table> |
| 221 | </div> |
| 222 | </body> |
| 223 | </html> |