| 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::cursor()</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="dbc.html" title="Chapter 3. The Dbc Handle" /> |
| 11 | <link rel="prev" href="dbc.html" title="Chapter 3. The Dbc Handle" /> |
| 12 | <link rel="next" href="dbcclose.html" title="Dbc::close()" /> |
| 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::cursor()</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="dbc.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 3. |
| 26 | The Dbc Handle |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="dbcclose.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="dbcursor"></a>Db::cursor()</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <pre class="programlisting">#include <db_cxx.h> |
| 42 | |
| 43 | int |
| 44 | Db::cursor(DbTxn *txnid, Dbc **cursorp, u_int32_t flags);</pre> |
| 45 | <p> |
| 46 | The <code class="methodname">Db::cursor()</code> method returns a created database cursor. |
| 47 | </p> |
| 48 | <p> |
| 49 | Cursors may span threads, but only serially, that is, the application |
| 50 | must serialize access to the cursor handle. |
| 51 | </p> |
| 52 | <p> |
| 53 | The <code class="methodname">Db::cursor()</code> <span> |
| 54 | |
| 55 | <span> |
| 56 | method either returns a non-zero error value or throws an |
| 57 | exception that encapsulates a non-zero error value on |
| 58 | failure, and returns 0 on success. |
| 59 | </span> |
| 60 | </span> |
| 61 | </p> |
| 62 | <div class="sect2" lang="en" xml:lang="en"> |
| 63 | <div class="titlepage"> |
| 64 | <div> |
| 65 | <div> |
| 66 | <h3 class="title"><a id="idm2293120"></a>Parameters</h3> |
| 67 | </div> |
| 68 | </div> |
| 69 | </div> |
| 70 | <div class="sect3" lang="en" xml:lang="en"> |
| 71 | <div class="titlepage"> |
| 72 | <div> |
| 73 | <div> |
| 74 | <h4 class="title"><a id="idm2293768"></a>txnid</h4> |
| 75 | </div> |
| 76 | </div> |
| 77 | </div> |
| 78 | <p> |
| 79 | To transaction-protect cursor operations, cursors must be |
| 80 | opened and closed within the context of a transaction. The |
| 81 | <span class="bold"><strong>txnid</strong></span> parameter specifies the |
| 82 | transaction context in which the cursor may be used. |
| 83 | </p> |
| 84 | <p> |
| 85 | Cursor operations are not automatically transaction-protected, even if the |
| 86 | <a class="link" href="envset_flags.html#envset_flags_DB_AUTO_COMMIT">DB_AUTO_COMMIT</a> |
| 87 | flag is specified to the |
| 88 | <a class="xref" href="envset_flags.html" title="DbEnv::set_flags()">DbEnv::set_flags()</a> or |
| 89 | <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> methods. If |
| 90 | cursor operations are to be transaction-protected, the <span class="bold"><strong>txnid</strong></span> parameter must be a transaction handle |
| 91 | returned from <a class="xref" href="txnbegin.html" title="DbEnv::txn_begin()">DbEnv::txn_begin()</a>; otherwise, |
| 92 | NULL. |
| 93 | </p> |
| 94 | </div> |
| 95 | <div class="sect3" lang="en" xml:lang="en"> |
| 96 | <div class="titlepage"> |
| 97 | <div> |
| 98 | <div> |
| 99 | <h4 class="title"><a id="idp6095680"></a>cursorp</h4> |
| 100 | </div> |
| 101 | </div> |
| 102 | </div> |
| 103 | <p> |
| 104 | The <span class="bold"><strong>cursorp</strong></span> parameter references |
| 105 | memory into which a pointer to the allocated cursor is copied. |
| 106 | </p> |
| 107 | </div> |
| 108 | <div class="sect3" lang="en" xml:lang="en"> |
| 109 | <div class="titlepage"> |
| 110 | <div> |
| 111 | <div> |
| 112 | <h4 class="title"><a id="idp6085968"></a>flags</h4> |
| 113 | </div> |
| 114 | </div> |
| 115 | </div> |
| 116 | <p> |
| 117 | The <span class="bold"><strong>flags</strong></span> parameter must be set to 0 |
| 118 | or by bitwise inclusively <span class="bold"><strong>OR</strong></span>'ing |
| 119 | together one or more of the following values: |
| 120 | </p> |
| 121 | <div class="itemizedlist"> |
| 122 | <ul type="disc"> |
| 123 | <li> |
| 124 | <p><a id="cursor_DB_BULK"></a> |
| 125 | <code class="literal">DB_CURSOR_BULK</code> |
| 126 | </p> |
| 127 | <p> |
| 128 | Configure a cursor to optimize for bulk operations. Each |
| 129 | successive operation on a cursor configured with this flag |
| 130 | attempts to continue on the same database page as the previous |
| 131 | operation, falling back to a search if a different page is |
| 132 | required. This avoids searching if there is a high degree of |
| 133 | locality between cursor operations. This flag is currently |
| 134 | only effective with the btree access method. For other access |
| 135 | methods, this flag is ignored. |
| 136 | </p> |
| 137 | </li> |
| 138 | <li> |
| 139 | <p><a id="cursor_DB_READ_COMMITTED"></a> |
| 140 | <code class="literal">DB_READ_COMMITTED</code> |
| 141 | </p> |
| 142 | <p> |
| 143 | Configure a transactional cursor to have degree 2 isolation. This |
| 144 | ensures the stability of the current data item read by this cursor but |
| 145 | permits data read by this cursor to be modified or deleted prior to |
| 146 | the commit of the transaction for this cursor. |
| 147 | </p> |
| 148 | </li> |
| 149 | <li> |
| 150 | <p><a id="cursor_DB_READ_UNCOMMITTED"></a> |
| 151 | <code class="literal">DB_READ_UNCOMMITTED</code> |
| 152 | </p> |
| 153 | <p> |
| 154 | Configure a transactional cursor to have degree 1 isolation. Read |
| 155 | operations performed by the cursor may return modified but not yet |
| 156 | committed data. Silently ignored if the |
| 157 | <a class="link" href="dbopen.html#dbopen_DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a> |
| 158 | flag was not specified when the underlying database was opened. |
| 159 | </p> |
| 160 | </li> |
| 161 | <li> |
| 162 | <p><a id="cursor_DB_WRITECURSOR"></a> |
| 163 | <code class="literal">DB_WRITECURSOR</code> |
| 164 | </p> |
| 165 | <p> |
| 166 | Specify that the cursor will be used to update the database. The |
| 167 | underlying database environment must have been opened using the |
| 168 | <a class="link" href="envopen.html#envopen_DB_INIT_CDB">DB_INIT_CDB</a> flag. |
| 169 | </p> |
| 170 | </li> |
| 171 | <li> |
| 172 | <p><a id="cursor_DB_TXN_SNAPSHOT"></a> |
| 173 | <code class="literal">DB_TXN_SNAPSHOT</code> |
| 174 | </p> |
| 175 | <p> |
| 176 | Configure a transactional cursor to operate with read-only <a href="../../programmer_reference/transapp_read.html" class="olink">snapshot isolation</a>. For |
| 177 | databases with the |
| 178 | <a class="link" href="dbopen.html#dbopen_DB_MULTIVERSION">DB_MULTIVERSION</a> |
| 179 | flag set, data values will be read as they are when the cursor is |
| 180 | opened, without taking read locks. |
| 181 | </p> |
| 182 | <p> |
| 183 | This flag implicitly begins a transaction that is committed when the cursor is |
| 184 | closed. |
| 185 | </p> |
| 186 | <p> |
| 187 | This flag is silently ignored if |
| 188 | <a class="link" href="dbopen.html#dbopen_DB_MULTIVERSION">DB_MULTIVERSION</a> |
| 189 | is not set on the underlying database or if a transaction is supplied in |
| 190 | the <span class="bold"><strong>txnid</strong></span> parameter. |
| 191 | </p> |
| 192 | </li> |
| 193 | </ul> |
| 194 | </div> |
| 195 | </div> |
| 196 | </div> |
| 197 | <div class="sect2" lang="en" xml:lang="en"> |
| 198 | <div class="titlepage"> |
| 199 | <div> |
| 200 | <div> |
| 201 | <h3 class="title"><a id="idp6102504"></a>Errors</h3> |
| 202 | </div> |
| 203 | </div> |
| 204 | </div> |
| 205 | <p> |
| 206 | The <code class="methodname">Db::cursor()</code> <span> |
| 207 | |
| 208 | <span> |
| 209 | method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> |
| 210 | exception, encapsulating one of the following non-zero errors, or return one |
| 211 | of the following non-zero errors: |
| 212 | </span> |
| 213 | </span> |
| 214 | </p> |
| 215 | <div class="sect3" lang="en" xml:lang="en"> |
| 216 | <div class="titlepage"> |
| 217 | <div> |
| 218 | <div> |
| 219 | <h4 class="title"><a id="idp6094264"></a> <span>DbRepHandleDeadException or</span> DB_REP_HANDLE_DEAD</h4> |
| 220 | </div> |
| 221 | </div> |
| 222 | </div> |
| 223 | <p> |
| 224 | When a client synchronizes with the master, it is possible for committed |
| 225 | transactions to be rolled back. This invalidates all the database and cursor |
| 226 | handles opened in the replication environment. Once this occurs, an attempt to use |
| 227 | such a handle will |
| 228 | <span> |
| 229 | throw a <a class="xref" href="dbrephandledead.html" title="DbRepHandleDeadException">DbRepHandleDeadException</a> (if |
| 230 | your application is configured to throw exceptions), or |
| 231 | </span> |
| 232 | return <code class="literal">DB_REP_HANDLE_DEAD</code>. |
| 233 | The application will need to discard the handle and open a new one in order to |
| 234 | continue processing. |
| 235 | </p> |
| 236 | </div> |
| 237 | <div class="sect3" lang="en" xml:lang="en"> |
| 238 | <div class="titlepage"> |
| 239 | <div> |
| 240 | <div> |
| 241 | <h4 class="title"><a id="idp6087152"></a><span>DbDeadlockException or </span>DB_REP_LOCKOUT</h4> |
| 242 | </div> |
| 243 | </div> |
| 244 | </div> |
| 245 | <p> |
| 246 | The operation was blocked by client/master synchronization. |
| 247 | </p> |
| 248 | <p> |
| 249 | <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if |
| 250 | your Berkeley DB API is configured to throw exceptions. |
| 251 | Otherwise, <code class="literal">DB_REP_LOCKOUT</code> is returned. |
| 252 | </p> |
| 253 | </div> |
| 254 | <div class="sect3" lang="en" xml:lang="en"> |
| 255 | <div class="titlepage"> |
| 256 | <div> |
| 257 | <div> |
| 258 | <h4 class="title"><a id="idp6087600"></a>EINVAL</h4> |
| 259 | </div> |
| 260 | </div> |
| 261 | </div> |
| 262 | <p> |
| 263 | An invalid flag value or parameter was specified. |
| 264 | </p> |
| 265 | </div> |
| 266 | </div> |
| 267 | <div class="sect2" lang="en" xml:lang="en"> |
| 268 | <div class="titlepage"> |
| 269 | <div> |
| 270 | <div> |
| 271 | <h3 class="title"><a id="idp6105992"></a>Class</h3> |
| 272 | </div> |
| 273 | </div> |
| 274 | </div> |
| 275 | <p> |
| 276 | <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> |
| 277 | </p> |
| 278 | </div> |
| 279 | <div class="sect2" lang="en" xml:lang="en"> |
| 280 | <div class="titlepage"> |
| 281 | <div> |
| 282 | <div> |
| 283 | <h3 class="title"><a id="idp6088712"></a>See Also</h3> |
| 284 | </div> |
| 285 | </div> |
| 286 | </div> |
| 287 | <p> |
| 288 | <a class="xref" href="dbc.html#dbclist" title="Database Cursors and Related Methods">Database Cursors and Related Methods</a> |
| 289 | </p> |
| 290 | </div> |
| 291 | </div> |
| 292 | <div class="navfooter"> |
| 293 | <hr /> |
| 294 | <table width="100%" summary="Navigation footer"> |
| 295 | <tr> |
| 296 | <td width="40%" align="left"><a accesskey="p" href="dbc.html">Prev</a> </td> |
| 297 | <td width="20%" align="center"> |
| 298 | <a accesskey="u" href="dbc.html">Up</a> |
| 299 | </td> |
| 300 | <td width="40%" align="right"> <a accesskey="n" href="dbcclose.html">Next</a></td> |
| 301 | </tr> |
| 302 | <tr> |
| 303 | <td width="40%" align="left" valign="top">Chapter 3. |
| 304 | The Dbc Handle |
| 305 | </td> |
| 306 | <td width="20%" align="center"> |
| 307 | <a accesskey="h" href="index.html">Home</a> |
| 308 | </td> |
| 309 | <td width="40%" align="right" valign="top"> Dbc::close()</td> |
| 310 | </tr> |
| 311 | </table> |
| 312 | </div> |
| 313 | </body> |
| 314 | </html> |