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 class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Db::truncate()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="dbsync.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��2.�� 23 The Db Handle 24 </th> 25 <td width="20%" align="right">��<a accesskey="n" href="dbupgrade.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="dbtruncate"></a>Db::truncate()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db_cxx.h> 39 40int 41Db::truncate(DbTxn *txnid, u_int32_t *countp, u_int32_t flags);</pre> 42 <p> 43 The <code class="methodname">Db::truncate()</code> method empties the database, discarding all 44 records it contains. The number of records discarded from the 45 database is returned in <span class="bold"><strong>countp</strong></span>. 46 </p> 47 <p> 48 When called on a database configured with secondary indices using the 49 <a class="xref" href="dbassociate.html" title="Db::associate()">Db::associate()</a> 50 method, the <code class="methodname">Db::truncate()</code> method truncates the primary database and 51 all secondary indices. A count of the records discarded from the 52 primary database is returned. 53 </p> 54 <p> 55 It is an error to call the <code class="methodname">Db::truncate()</code> method on a database with 56 open cursors. 57 </p> 58 <p> 59 The <code class="methodname">Db::truncate()</code> <span> 60 61 <span> 62 method either returns a non-zero error value or throws an 63 exception that encapsulates a non-zero error value on 64 failure, and returns 0 on success. 65 </span> 66 </span> 67 </p> 68 <div class="sect2" lang="en" xml:lang="en"> 69 <div class="titlepage"> 70 <div> 71 <div> 72 <h3 class="title"><a id="id1653358"></a>Parameters</h3> 73 </div> 74 </div> 75 </div> 76 <div class="sect3" lang="en" xml:lang="en"> 77 <div class="titlepage"> 78 <div> 79 <div> 80 <h4 class="title"><a id="id1653375"></a>countp</h4> 81 </div> 82 </div> 83 </div> 84 <p> 85 The <span class="bold"><strong>countp</strong></span> parameter references 86 memory into which the number of records discarded from the database 87 is copied. 88 </p> 89 </div> 90 <div class="sect3" lang="en" xml:lang="en"> 91 <div class="titlepage"> 92 <div> 93 <div> 94 <h4 class="title"><a id="id1653365"></a>flags</h4> 95 </div> 96 </div> 97 </div> 98 <p> 99 The <span class="bold"><strong>flags</strong></span> parameter is currently 100 unused, and must be set to 0. 101 </p> 102 </div> 103 <div class="sect3" lang="en" xml:lang="en"> 104 <div class="titlepage"> 105 <div> 106 <div> 107 <h4 class="title"><a id="id1653514"></a>txnid</h4> 108 </div> 109 </div> 110 </div> 111 <p> 112 If the operation is part of an application-specified transaction, the 113 <span class="bold"><strong>txnid</strong></span> parameter is a transaction 114 handle returned from <a class="xref" href="txnbegin.html" title="DbEnv::txn_begin()">DbEnv::txn_begin()</a>; if the 115 operation is part of a Berkeley DB Concurrent Data Store group, the 116 <span class="bold"><strong>txnid</strong></span> parameter is a handle returned 117 from <a class="xref" href="envcdsgroup_begin.html" title="DbEnv::cdsgroup_begin()">DbEnv::cdsgroup_begin()</a>; 118 otherwise NULL. If no transaction handle is specified, but the 119 operation occurs in a transactional database, the operation will be 120 implicitly transaction protected. 121 </p> 122 </div> 123 </div> 124 <div class="sect2" lang="en" xml:lang="en"> 125 <div class="titlepage"> 126 <div> 127 <div> 128 <h3 class="title"><a id="id1653522"></a>Errors</h3> 129 </div> 130 </div> 131 </div> 132 <p> 133 The <code class="methodname">Db::truncate()</code> <span> 134 135 <span> 136 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter��6.��The DbException Class">DbException</a> 137 exception, encapsulating one of the following non-zero errors, or return one 138 of the following non-zero errors: 139 </span> 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="id1653575"></a><span>DbDeadlockException or </span>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 <p> 155 <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if 156 your Berkeley DB API is configured to throw exceptions. 157 Otherwise, <code class="literal">DB_LOCK_DEADLOCK</code> is returned. 158 </p> 159 </div> 160 <div class="sect3" lang="en" xml:lang="en"> 161 <div class="titlepage"> 162 <div> 163 <div> 164 <h4 class="title"><a id="id1653430"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4> 165 </div> 166 </div> 167 </div> 168 <p> 169 A Berkeley DB Concurrent Data Store database environment configured 170 for lock timeouts was unable to grant a lock in the allowed time. 171 </p> 172 <p> 173 <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if 174 your Berkeley DB API is configured to throw exceptions. 175 Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned. 176 </p> 177 </div> 178 <div class="sect3" lang="en" xml:lang="en"> 179 <div class="titlepage"> 180 <div> 181 <div> 182 <h4 class="title"><a id="id1653366"></a>EINVAL</h4> 183 </div> 184 </div> 185 </div> 186 <p> 187 If there are open cursors in the database; or if an invalid flag value or parameter was specified. 188 </p> 189 </div> 190 </div> 191 <div class="sect2" lang="en" xml:lang="en"> 192 <div class="titlepage"> 193 <div> 194 <div> 195 <h3 class="title"><a id="id1653218"></a>Class</h3> 196 </div> 197 </div> 198 </div> 199 <p> 200 <a class="link" href="db.html" title="Chapter��2.�� The Db Handle">Db</a> 201 </p> 202 </div> 203 <div class="sect2" lang="en" xml:lang="en"> 204 <div class="titlepage"> 205 <div> 206 <div> 207 <h3 class="title"><a id="id1653494"></a>See Also</h3> 208 </div> 209 </div> 210 </div> 211 <p> 212 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 213 </p> 214 </div> 215 </div> 216 <div class="navfooter"> 217 <hr /> 218 <table width="100%" summary="Navigation footer"> 219 <tr> 220 <td width="40%" align="left"><a accesskey="p" href="dbsync.html">Prev</a>��</td> 221 <td width="20%" align="center"> 222 <a accesskey="u" href="db.html">Up</a> 223 </td> 224 <td width="40%" align="right">��<a accesskey="n" href="dbupgrade.html">Next</a></td> 225 </tr> 226 <tr> 227 <td width="40%" align="left" valign="top">Db::sync()��</td> 228 <td width="20%" align="center"> 229 <a accesskey="h" href="index.html">Home</a> 230 </td> 231 <td width="40%" align="right" valign="top">��Db::upgrade()</td> 232 </tr> 233 </table> 234 </div> 235 </body> 236</html> 237