1<!--$Id: db_truncate.so,v 1.29 2006/09/13 14:30:52 mjc Exp $-->
2<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
3<!--See the file LICENSE for redistribution information.-->
4<html>
5<head>
6<title>Berkeley DB: DB-&gt;truncate</title>
7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
9</head>
10<body bgcolor=white>
11<table width="100%"><tr valign=top>
12<td>
13<b>DB-&gt;truncate</b>
14</td>
15<td align=right>
16<a href="/api_c/api_core.html"><img src="/images/api.gif" alt="API"></a>
17<a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a></td>
18</tr></table>
19<hr size=1 noshade>
20<tt>
21<b><pre>
22#include &lt;db.h&gt;
23<p>
24int
25DB-&gt;truncate(DB *db,
26    DB_TXN *txnid, u_int32_t *countp, u_int32_t flags);
27</pre></b>
28<hr size=1 noshade>
29<b>Description: DB-&gt;truncate</b>
30<p>The DB-&gt;truncate method empties the database, discarding all records
31it contains.  The number of records discarded from the database is
32returned in <b>countp</b>.</p>
33<p>When called on a database configured with secondary indices using the
34<a href="/api_c/db_associate.html">DB-&gt;associate</a> method, the DB-&gt;truncate method truncates the primary
35database and all secondary indices.  A count of the records discarded
36from the primary database is returned.</p>
37<p>It is an error to call the DB-&gt;truncate method on a database with open
38cursors.</p>
39<p>The DB-&gt;truncate method
40returns a non-zero error value on failure
41and 0 on success.
42</p>
43<b>Parameters</b> <br>
44 <b>countp</b><ul compact><li>The <b>countp</b> parameter references memory into which
45 the number of records discarded from the database is copied.</ul> 
46 <b>flags</b><ul compact><li>The <b>flags</b> parameter is currently unused, and must be set to 0.</ul>
47 <b>txnid</b><ul compact><li>If the operation is part of an application-specified transaction, the
48<b>txnid</b> parameter is a transaction handle returned from
49<a href="/api_c/txn_begin.html">DB_ENV-&gt;txn_begin</a>; if the operation is part of a Berkeley DB Concurrent Data Store group, the
50<b>txnid</b> parameter is a handle returned from
51<a href="/api_c/env_cdsgroup_begin.html">DB_ENV-&gt;cdsgroup_begin</a>; otherwise NULL.
52If no transaction handle is
53specified, but the
54operation occurs in a transactional
55database,
56the operation will be implicitly transaction protected.
57</ul>
58<br>
59<br><b>Errors</b>
60<p>The DB-&gt;truncate method
61may fail and return one of the following non-zero errors:</p>
62<br>
63<b>DB_LOCK_DEADLOCK</b><ul compact><li>A transactional database environment operation was selected to resolve
64a deadlock.</ul>
65<b>DB_LOCK_NOTGRANTED</b><ul compact><li>A Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable
66to grant a lock in the allowed time.</ul>
67<br>
68<br>
69<b>EINVAL</b><ul compact><li>If there are open cursors in the database; or if an
70invalid flag value or parameter was specified.</ul>
71<br>
72<hr size=1 noshade>
73<br><b>Class</b>
74<a href="/api_c/db_class.html">DB</a>
75<br><b>See Also</b>
76<a href="/api_c/db_list.html">Databases and Related Methods</a>
77</tt>
78<table width="100%"><tr><td><br></td><td align=right>
79<a href="/api_c/api_core.html"><img src="/images/api.gif" alt="API"></a><a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a>
80</td></tr></table>
81<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
82</body>
83</html>
84