| 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->del()</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="dbcreate.html" title="db_create" /> |
| 12 | <link rel="next" href="dberr.html" title="DB->err()" /> |
| 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->del()</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="dbcreate.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="dberr.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="dbdel"></a>DB->del()</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <pre class="programlisting">#include <db.h> |
| 42 | |
| 43 | int |
| 44 | DB->del(DB *db, DB_TXN *txnid, DBT *key, u_int32_t flags); </pre> |
| 45 | <p> |
| 46 | The <code class="methodname">DB->del()</code> method removes key/data pairs from the database. The |
| 47 | key/data pair associated with the specified <span class="bold"><strong>key</strong></span> is discarded from the database. In the |
| 48 | presence of duplicate key values, all records associated with the |
| 49 | designated key will be discarded. |
| 50 | </p> |
| 51 | <p> |
| 52 | When called on a database that has been made into a secondary index |
| 53 | using the <a class="xref" href="dbassociate.html" title="DB->associate()">DB->associate()</a> method, the |
| 54 | <code class="methodname">DB->del()</code> method deletes the key/data pair from the primary database |
| 55 | and all secondary indices. |
| 56 | </p> |
| 57 | <p> |
| 58 | The <code class="methodname">DB->del()</code> method will return <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> if the specified key |
| 59 | is not in the database. The <code class="methodname">DB->del()</code> method will return <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_KEYEMPTY" class="olink">DB_KEYEMPTY</a> if the database is a |
| 60 | Queue or Recno database and the specified key exists, but was never explicitly created by |
| 61 | the application or was later deleted. Unless otherwise specified, the |
| 62 | <code class="methodname">DB->del()</code> <span> |
| 63 | <span> |
| 64 | method returns a non-zero error value on failure and 0 on success. |
| 65 | </span> |
| 66 | |
| 67 | </span> |
| 68 | </p> |
| 69 | <div class="sect2" lang="en" xml:lang="en"> |
| 70 | <div class="titlepage"> |
| 71 | <div> |
| 72 | <div> |
| 73 | <h3 class="title"><a id="idp49460064"></a>Parameters</h3> |
| 74 | </div> |
| 75 | </div> |
| 76 | </div> |
| 77 | <div class="sect3" lang="en" xml:lang="en"> |
| 78 | <div class="titlepage"> |
| 79 | <div> |
| 80 | <div> |
| 81 | <h4 class="title"><a id="idp49460568"></a>txnid</h4> |
| 82 | </div> |
| 83 | </div> |
| 84 | </div> |
| 85 | <p> |
| 86 | If the operation is part of an application-specified transaction, the |
| 87 | <span class="bold"><strong>txnid</strong></span> parameter is a transaction |
| 88 | handle returned from <a class="xref" href="txnbegin.html" title="DB_ENV->txn_begin()">DB_ENV->txn_begin()</a>; |
| 89 | if the operation is part of a Berkeley DB Concurrent Data Store group, the |
| 90 | <span class="bold"><strong>txnid</strong></span> parameter is a handle returned |
| 91 | from <a class="xref" href="envcdsgroup_begin.html" title="DB_ENV->cdsgroup_begin()">DB_ENV->cdsgroup_begin()</a>; |
| 92 | otherwise NULL. If no transaction handle is specified, but the |
| 93 | operation occurs in a transactional database, the operation will be |
| 94 | implicitly transaction protected. |
| 95 | </p> |
| 96 | </div> |
| 97 | <div class="sect3" lang="en" xml:lang="en"> |
| 98 | <div class="titlepage"> |
| 99 | <div> |
| 100 | <div> |
| 101 | <h4 class="title"><a id="idp49439848"></a>key</h4> |
| 102 | </div> |
| 103 | </div> |
| 104 | </div> |
| 105 | <p> |
| 106 | The key <a class="link" href="dbt.html" title="Chapter 4. The DBT Handle">DBT</a> operated on. |
| 107 | </p> |
| 108 | </div> |
| 109 | <div class="sect3" lang="en" xml:lang="en"> |
| 110 | <div class="titlepage"> |
| 111 | <div> |
| 112 | <div> |
| 113 | <h4 class="title"><a id="idp49299600"></a>flags</h4> |
| 114 | </div> |
| 115 | </div> |
| 116 | </div> |
| 117 | <p> |
| 118 | The <span class="bold"><strong>flags</strong></span> parameter must be set to 0 |
| 119 | or one of the following values: |
| 120 | </p> |
| 121 | <div class="itemizedlist"> |
| 122 | <ul type="disc"> |
| 123 | <li> |
| 124 | <p><a id="dbput_DB_CONSUME"></a> |
| 125 | <code class="literal">DB_CONSUME</code> |
| 126 | </p> |
| 127 | <p> |
| 128 | If the database is of type DB_QUEUE then this flag may be set to force the head of the queue |
| 129 | to move to the first non-deleted item in the queue. Normally this is only done if the |
| 130 | deleted item is exactly at the head when deleted. |
| 131 | </p> |
| 132 | </li> |
| 133 | <li> |
| 134 | <p><a id="del_DB_MULTIPLE"></a> |
| 135 | <code class="literal">DB_MULTIPLE</code> |
| 136 | </p> |
| 137 | <p> |
| 138 | Delete multiple data items using keys from the buffer to which the |
| 139 | <span class="bold"><strong>key</strong></span> parameter refers. |
| 140 | </p> |
| 141 | <p> |
| 142 | To delete records in bulk by key with the btree or hash access methods, construct a |
| 143 | bulk buffer in the <span class="bold"><strong>key</strong></span> |
| 144 | <a class="link" href="dbt.html" title="Chapter 4. The DBT Handle">DBT</a> using |
| 145 | <a class="xref" href="DB_MULTIPLE_WRITE_INIT.html" title="DB_MULTIPLE_WRITE_INIT">DB_MULTIPLE_WRITE_INIT</a> and |
| 146 | <a class="xref" href="DB_MULTIPLE_WRITE_NEXT.html" title="DB_MULTIPLE_WRITE_NEXT">DB_MULTIPLE_WRITE_NEXT</a>. To |
| 147 | delete records in bulk by record number, construct the |
| 148 | <span class="bold"><strong>key</strong></span> <a class="link" href="dbt.html" title="Chapter 4. The DBT Handle">DBT</a> using |
| 149 | <a class="xref" href="DB_MULTIPLE_RECNO_WRITE_INIT.html" title="DB_MULTIPLE_RECNO_WRITE_INIT">DB_MULTIPLE_RECNO_WRITE_INIT</a> and |
| 150 | <a class="xref" href="DB_MULTIPLE_RECNO_WRITE_NEXT.html" title="DB_MULTIPLE_RECNO_WRITE_NEXT">DB_MULTIPLE_RECNO_WRITE_NEXT</a> |
| 151 | with a data size of zero. |
| 152 | </p> |
| 153 | <p> |
| 154 | A successful bulk delete operation is logically equivalent to a loop through each |
| 155 | key/data pair, performing a <a class="xref" href="dbdel.html" title="DB->del()">DB->del()</a> for each one. |
| 156 | </p> |
| 157 | <p> |
| 158 | See the <a class="xref" href="dbt.html#dbtlist" title="DBT and Bulk Operations">DBT and Bulk Operations</a> for more information on |
| 159 | working with bulk updates. |
| 160 | </p> |
| 161 | <p> |
| 162 | The <code class="literal">DB_MULTIPLE</code> flag may only be used alone. |
| 163 | </p> |
| 164 | </li> |
| 165 | <li> |
| 166 | <p><a id="del_DB_MULTIPLE_KEY"></a> |
| 167 | <code class="literal">DB_MULTIPLE_KEY</code> |
| 168 | </p> |
| 169 | <p> |
| 170 | Delete multiple data items using keys and data from the buffer to which the |
| 171 | <span class="bold"><strong>key</strong></span> parameter refers. |
| 172 | </p> |
| 173 | <p> |
| 174 | To delete records in bulk with the btree or hash access methods, construct a bulk |
| 175 | buffer in the <span class="bold"><strong>key</strong></span> |
| 176 | <a class="link" href="dbt.html" title="Chapter 4. The DBT Handle">DBT</a> using |
| 177 | <a class="xref" href="DB_MULTIPLE_WRITE_INIT.html" title="DB_MULTIPLE_WRITE_INIT">DB_MULTIPLE_WRITE_INIT</a> and |
| 178 | <a class="xref" href="DB_MULTIPLE_KEY_WRITE_NEXT.html" title="DB_MULTIPLE_KEY_WRITE_NEXT">DB_MULTIPLE_KEY_WRITE_NEXT</a>. |
| 179 | To delete records in bulk with the recno or hash access methods, construct |
| 180 | a bulk buffer in the <span class="bold"><strong>key</strong></span> |
| 181 | <a class="link" href="dbt.html" title="Chapter 4. The DBT Handle">DBT</a> using |
| 182 | <a class="xref" href="DB_MULTIPLE_RECNO_WRITE_INIT.html" title="DB_MULTIPLE_RECNO_WRITE_INIT">DB_MULTIPLE_RECNO_WRITE_INIT</a> |
| 183 | and <a class="xref" href="DB_MULTIPLE_RECNO_WRITE_NEXT.html" title="DB_MULTIPLE_RECNO_WRITE_NEXT">DB_MULTIPLE_RECNO_WRITE_NEXT</a>. |
| 184 | </p> |
| 185 | <p> |
| 186 | See the <a class="xref" href="dbt.html#dbtlist" title="DBT and Bulk Operations">DBT and Bulk Operations</a> for more information on |
| 187 | working with bulk updates. |
| 188 | </p> |
| 189 | <p> |
| 190 | The <code class="literal">DB_MULTIPLE_KEY</code> flag may only be used alone. |
| 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="idp49444120"></a>Errors</h3> |
| 202 | </div> |
| 203 | </div> |
| 204 | </div> |
| 205 | <p> |
| 206 | The <code class="methodname">DB->del()</code> <span> |
| 207 | <span> |
| 208 | method may fail and return one of the following non-zero errors: |
| 209 | </span> |
| 210 | |
| 211 | </span> |
| 212 | </p> |
| 213 | <div class="sect3" lang="en" xml:lang="en"> |
| 214 | <div class="titlepage"> |
| 215 | <div> |
| 216 | <div> |
| 217 | <h4 class="title"><a id="idp49454272"></a>DB_FOREIGN_CONFLICT</h4> |
| 218 | </div> |
| 219 | </div> |
| 220 | </div> |
| 221 | <p> |
| 222 | A <a class="link" href="dbassociate_foreign.html" title="DB->associate_foreign()">foreign key constraint violation</a> |
| 223 | has occurred. This can be caused by one of two things: |
| 224 | </p> |
| 225 | <div class="orderedlist"> |
| 226 | <ol type="1"> |
| 227 | <li> |
| 228 | <p> |
| 229 | An attempt was made to add a record to a |
| 230 | constrained database, and the key used for that |
| 231 | record does not exist in the foreign key |
| 232 | database. |
| 233 | </p> |
| 234 | </li> |
| 235 | <li> |
| 236 | <p> |
| 237 | <a class="link" href="dbassociate_foreign.html#associate_foreign_DB_FOREIGN_ABORT">DB_FOREIGN_ABORT</a> |
| 238 | was declared for a foreign key database, and then |
| 239 | subsequently a record was deleted from the |
| 240 | foreign key database without first removing it |
| 241 | from the constrained secondary database. |
| 242 | </p> |
| 243 | </li> |
| 244 | </ol> |
| 245 | </div> |
| 246 | </div> |
| 247 | <div class="sect3" lang="en" xml:lang="en"> |
| 248 | <div class="titlepage"> |
| 249 | <div> |
| 250 | <div> |
| 251 | <h4 class="title"><a id="idp49446232"></a>DB_LOCK_DEADLOCK</h4> |
| 252 | </div> |
| 253 | </div> |
| 254 | </div> |
| 255 | <p> |
| 256 | A transactional database environment operation was selected to resolve |
| 257 | a deadlock. |
| 258 | </p> |
| 259 | </div> |
| 260 | <div class="sect3" lang="en" xml:lang="en"> |
| 261 | <div class="titlepage"> |
| 262 | <div> |
| 263 | <div> |
| 264 | <h4 class="title"><a id="idp49467624"></a>DB_LOCK_NOTGRANTED</h4> |
| 265 | </div> |
| 266 | </div> |
| 267 | </div> |
| 268 | <p> |
| 269 | A Berkeley DB Concurrent Data Store database environment configured |
| 270 | for lock timeouts was unable to grant a lock in the allowed time. |
| 271 | </p> |
| 272 | <p> |
| 273 | You attempted to open a database handle that is configured |
| 274 | for no waiting exclusive locking, but the exclusive lock could not be |
| 275 | immediately obtained. See |
| 276 | <a class="xref" href="dbset_lk_exclusive.html" title="DB->set_lk_exclusive()">DB->set_lk_exclusive()</a> |
| 277 | for more information. |
| 278 | </p> |
| 279 | </div> |
| 280 | <div class="sect3" lang="en" xml:lang="en"> |
| 281 | <div class="titlepage"> |
| 282 | <div> |
| 283 | <div> |
| 284 | <h4 class="title"><a id="idp49478736"></a> DB_REP_HANDLE_DEAD</h4> |
| 285 | </div> |
| 286 | </div> |
| 287 | </div> |
| 288 | <p> |
| 289 | When a client synchronizes with the master, it is possible for committed |
| 290 | transactions to be rolled back. This invalidates all the database and cursor |
| 291 | handles opened in the replication environment. Once this occurs, an attempt to use |
| 292 | such a handle will |
| 293 | |
| 294 | return <code class="literal">DB_REP_HANDLE_DEAD</code>. |
| 295 | The application will need to discard the handle and open a new one in order to |
| 296 | continue processing. |
| 297 | </p> |
| 298 | </div> |
| 299 | <div class="sect3" lang="en" xml:lang="en"> |
| 300 | <div class="titlepage"> |
| 301 | <div> |
| 302 | <div> |
| 303 | <h4 class="title"><a id="idp49422080"></a>DB_REP_LOCKOUT</h4> |
| 304 | </div> |
| 305 | </div> |
| 306 | </div> |
| 307 | <p> |
| 308 | The operation was blocked by client/master synchronization. |
| 309 | </p> |
| 310 | </div> |
| 311 | <div class="sect3" lang="en" xml:lang="en"> |
| 312 | <div class="titlepage"> |
| 313 | <div> |
| 314 | <div> |
| 315 | <h4 class="title"><a id="idp49447088"></a>DB_SECONDARY_BAD</h4> |
| 316 | </div> |
| 317 | </div> |
| 318 | </div> |
| 319 | <p> |
| 320 | A secondary index references a nonexistent primary key. |
| 321 | </p> |
| 322 | </div> |
| 323 | <div class="sect3" lang="en" xml:lang="en"> |
| 324 | <div class="titlepage"> |
| 325 | <div> |
| 326 | <div> |
| 327 | <h4 class="title"><a id="idp49498176"></a>EACCES</h4> |
| 328 | </div> |
| 329 | </div> |
| 330 | </div> |
| 331 | <p> |
| 332 | An attempt was made to modify a read-only database. |
| 333 | </p> |
| 334 | </div> |
| 335 | <div class="sect3" lang="en" xml:lang="en"> |
| 336 | <div class="titlepage"> |
| 337 | <div> |
| 338 | <div> |
| 339 | <h4 class="title"><a id="idp49498584"></a>EINVAL</h4> |
| 340 | </div> |
| 341 | </div> |
| 342 | </div> |
| 343 | <p> |
| 344 | An invalid flag value or parameter was specified. |
| 345 | </p> |
| 346 | </div> |
| 347 | </div> |
| 348 | <div class="sect2" lang="en" xml:lang="en"> |
| 349 | <div class="titlepage"> |
| 350 | <div> |
| 351 | <div> |
| 352 | <h3 class="title"><a id="idp49473040"></a>Class</h3> |
| 353 | </div> |
| 354 | </div> |
| 355 | </div> |
| 356 | <p> |
| 357 | <a class="link" href="db.html" title="Chapter 2. The DB Handle">DB</a> |
| 358 | </p> |
| 359 | </div> |
| 360 | <div class="sect2" lang="en" xml:lang="en"> |
| 361 | <div class="titlepage"> |
| 362 | <div> |
| 363 | <div> |
| 364 | <h3 class="title"><a id="idp49468960"></a>See Also</h3> |
| 365 | </div> |
| 366 | </div> |
| 367 | </div> |
| 368 | <p> |
| 369 | <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> |
| 370 | </p> |
| 371 | </div> |
| 372 | </div> |
| 373 | <div class="navfooter"> |
| 374 | <hr /> |
| 375 | <table width="100%" summary="Navigation footer"> |
| 376 | <tr> |
| 377 | <td width="40%" align="left"><a accesskey="p" href="dbcreate.html">Prev</a> </td> |
| 378 | <td width="20%" align="center"> |
| 379 | <a accesskey="u" href="db.html">Up</a> |
| 380 | </td> |
| 381 | <td width="40%" align="right"> <a accesskey="n" href="dberr.html">Next</a></td> |
| 382 | </tr> |
| 383 | <tr> |
| 384 | <td width="40%" align="left" valign="top">db_create </td> |
| 385 | <td width="20%" align="center"> |
| 386 | <a accesskey="h" href="index.html">Home</a> |
| 387 | </td> |
| 388 | <td width="40%" align="right" valign="top"> DB->err()</td> |
| 389 | </tr> |
| 390 | </table> |
| 391 | </div> |
| 392 | </body> |
| 393 | </html> |