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