| 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->truncate()</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="dbsync.html" title="DB->sync()" /> |
| 12 | <link rel="next" href="dbupgrade.html" title="DB->upgrade()" /> |
| 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->truncate()</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="dbsync.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="dbupgrade.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="dbtruncate"></a>DB->truncate()</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <pre class="programlisting">#include <db.h> |
| 42 | |
| 43 | int |
| 44 | DB->truncate(DB *db, |
| 45 | DB_TXN *txnid, u_int32_t *countp, u_int32_t flags); </pre> |
| 46 | <p> |
| 47 | The <code class="methodname">DB->truncate()</code> method empties the database, discarding all |
| 48 | records it contains. The number of records discarded from the |
| 49 | database is returned in <span class="bold"><strong>countp</strong></span>. |
| 50 | </p> |
| 51 | <p> |
| 52 | When called on a database configured with secondary indices using the |
| 53 | <a class="xref" href="dbassociate.html" title="DB->associate()">DB->associate()</a> |
| 54 | method, the <code class="methodname">DB->truncate()</code> method truncates the primary database and |
| 55 | all secondary indices. A count of the records discarded from the |
| 56 | primary database is returned. |
| 57 | </p> |
| 58 | <p> |
| 59 | It is an error to call the <code class="methodname">DB->truncate()</code> method on a database with |
| 60 | open cursors. |
| 61 | </p> |
| 62 | <p> |
| 63 | The <code class="methodname">DB->truncate()</code> <span> |
| 64 | <span> |
| 65 | method returns a non-zero error value on failure and 0 on success. |
| 66 | </span> |
| 67 | |
| 68 | </span> |
| 69 | </p> |
| 70 | <div class="sect2" lang="en" xml:lang="en"> |
| 71 | <div class="titlepage"> |
| 72 | <div> |
| 73 | <div> |
| 74 | <h3 class="title"><a id="idp50719552"></a>Parameters</h3> |
| 75 | </div> |
| 76 | </div> |
| 77 | </div> |
| 78 | <div class="sect3" lang="en" xml:lang="en"> |
| 79 | <div class="titlepage"> |
| 80 | <div> |
| 81 | <div> |
| 82 | <h4 class="title"><a id="idp50719744"></a>txnid</h4> |
| 83 | </div> |
| 84 | </div> |
| 85 | </div> |
| 86 | <p> |
| 87 | If the operation is part of an application-specified transaction, the |
| 88 | <span class="bold"><strong>txnid</strong></span> parameter is a transaction |
| 89 | handle returned from <a class="xref" href="txnbegin.html" title="DB_ENV->txn_begin()">DB_ENV->txn_begin()</a>; if the |
| 90 | operation is part of a Berkeley DB Concurrent Data Store group, the |
| 91 | <span class="bold"><strong>txnid</strong></span> parameter is a handle returned |
| 92 | from <a class="xref" href="envcdsgroup_begin.html" title="DB_ENV->cdsgroup_begin()">DB_ENV->cdsgroup_begin()</a>; |
| 93 | otherwise NULL. If no transaction handle is specified, but the |
| 94 | operation occurs in a transactional database, the operation will be |
| 95 | implicitly transaction protected. |
| 96 | </p> |
| 97 | </div> |
| 98 | <div class="sect3" lang="en" xml:lang="en"> |
| 99 | <div class="titlepage"> |
| 100 | <div> |
| 101 | <div> |
| 102 | <h4 class="title"><a id="idp50712192"></a>countp</h4> |
| 103 | </div> |
| 104 | </div> |
| 105 | </div> |
| 106 | <p> |
| 107 | The <span class="bold"><strong>countp</strong></span> parameter references |
| 108 | memory into which the number of records discarded from the database |
| 109 | is copied. |
| 110 | </p> |
| 111 | </div> |
| 112 | <div class="sect3" lang="en" xml:lang="en"> |
| 113 | <div class="titlepage"> |
| 114 | <div> |
| 115 | <div> |
| 116 | <h4 class="title"><a id="idp50708272"></a>flags</h4> |
| 117 | </div> |
| 118 | </div> |
| 119 | </div> |
| 120 | <p> |
| 121 | The <span class="bold"><strong>flags</strong></span> parameter is currently |
| 122 | unused, and must be set to 0. |
| 123 | </p> |
| 124 | </div> |
| 125 | </div> |
| 126 | <div class="sect2" lang="en" xml:lang="en"> |
| 127 | <div class="titlepage"> |
| 128 | <div> |
| 129 | <div> |
| 130 | <h3 class="title"><a id="idp50705504"></a>Errors</h3> |
| 131 | </div> |
| 132 | </div> |
| 133 | </div> |
| 134 | <p> |
| 135 | The <code class="methodname">DB->truncate()</code> <span> |
| 136 | <span> |
| 137 | method may fail and return one of the following non-zero errors: |
| 138 | </span> |
| 139 | |
| 140 | </span> |
| 141 | </p> |
| 142 | <div class="sect3" lang="en" xml:lang="en"> |
| 143 | <div class="titlepage"> |
| 144 | <div> |
| 145 | <div> |
| 146 | <h4 class="title"><a id="idp50727184"></a>DB_LOCK_DEADLOCK</h4> |
| 147 | </div> |
| 148 | </div> |
| 149 | </div> |
| 150 | <p> |
| 151 | A transactional database environment operation was selected to resolve |
| 152 | a deadlock. |
| 153 | </p> |
| 154 | </div> |
| 155 | <div class="sect3" lang="en" xml:lang="en"> |
| 156 | <div class="titlepage"> |
| 157 | <div> |
| 158 | <div> |
| 159 | <h4 class="title"><a id="idp50734968"></a>DB_LOCK_NOTGRANTED</h4> |
| 160 | </div> |
| 161 | </div> |
| 162 | </div> |
| 163 | <p> |
| 164 | A Berkeley DB Concurrent Data Store database environment configured |
| 165 | for lock timeouts was unable to grant a lock in the allowed time. |
| 166 | </p> |
| 167 | <p> |
| 168 | You attempted to open a database handle that is configured |
| 169 | for no waiting exclusive locking, but the exclusive lock could not be |
| 170 | immediately obtained. See |
| 171 | <a class="xref" href="dbset_lk_exclusive.html" title="DB->set_lk_exclusive()">DB->set_lk_exclusive()</a> |
| 172 | for more information. |
| 173 | </p> |
| 174 | </div> |
| 175 | <div class="sect3" lang="en" xml:lang="en"> |
| 176 | <div class="titlepage"> |
| 177 | <div> |
| 178 | <div> |
| 179 | <h4 class="title"><a id="idp50728520"></a>EINVAL</h4> |
| 180 | </div> |
| 181 | </div> |
| 182 | </div> |
| 183 | <p> |
| 184 | If there are open cursors in the database; or if an invalid flag value or parameter was specified. |
| 185 | </p> |
| 186 | </div> |
| 187 | </div> |
| 188 | <div class="sect2" lang="en" xml:lang="en"> |
| 189 | <div class="titlepage"> |
| 190 | <div> |
| 191 | <div> |
| 192 | <h3 class="title"><a id="idp50724984"></a>Class</h3> |
| 193 | </div> |
| 194 | </div> |
| 195 | </div> |
| 196 | <p> |
| 197 | <a class="link" href="db.html" title="Chapter 2. The DB Handle">DB</a> |
| 198 | </p> |
| 199 | </div> |
| 200 | <div class="sect2" lang="en" xml:lang="en"> |
| 201 | <div class="titlepage"> |
| 202 | <div> |
| 203 | <div> |
| 204 | <h3 class="title"><a id="idp50729376"></a>See Also</h3> |
| 205 | </div> |
| 206 | </div> |
| 207 | </div> |
| 208 | <p> |
| 209 | <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> |
| 210 | </p> |
| 211 | </div> |
| 212 | </div> |
| 213 | <div class="navfooter"> |
| 214 | <hr /> |
| 215 | <table width="100%" summary="Navigation footer"> |
| 216 | <tr> |
| 217 | <td width="40%" align="left"><a accesskey="p" href="dbsync.html">Prev</a> </td> |
| 218 | <td width="20%" align="center"> |
| 219 | <a accesskey="u" href="db.html">Up</a> |
| 220 | </td> |
| 221 | <td width="40%" align="right"> <a accesskey="n" href="dbupgrade.html">Next</a></td> |
| 222 | </tr> |
| 223 | <tr> |
| 224 | <td width="40%" align="left" valign="top">DB->sync() </td> |
| 225 | <td width="20%" align="center"> |
| 226 | <a accesskey="h" href="index.html">Home</a> |
| 227 | </td> |
| 228 | <td width="40%" align="right" valign="top"> DB->upgrade()</td> |
| 229 | </tr> |
| 230 | </table> |
| 231 | </div> |
| 232 | </body> |
| 233 | </html> |