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::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::truncate</b> 14</td> 15<td align=right> 16<a href="../api_cxx/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 <db_cxx.h> 23<p> 24int 25Db::truncate(DbTxn *txnid, u_int32_t *countp, u_int32_t flags); 26</pre></b> 27<hr size=1 noshade> 28<b>Description: Db::truncate</b> 29<p>The Db::truncate method empties the database, discarding all records 30it contains. The number of records discarded from the database is 31returned in <b>countp</b>.</p> 32<p>When called on a database configured with secondary indices using the 33<a href="../api_cxx/db_associate.html">Db::associate</a> method, the Db::truncate method truncates the primary 34database and all secondary indices. A count of the records discarded 35from the primary database is returned.</p> 36<p>It is an error to call the Db::truncate method on a database with open 37cursors.</p> 38<p>The Db::truncate method 39either returns a non-zero error value 40or throws an exception that encapsulates a non-zero error value on 41failure, and returns 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_cxx/txn_begin.html">DbEnv::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_cxx/env_cdsgroup_begin.html">DbEnv::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::truncate method 61may fail and throw 62<a href="../api_cxx/except_class.html">DbException</a>, 63encapsulating one of the following non-zero errors, or return one of 64the following non-zero errors:</p> 65<br> 66<b>EINVAL</b><ul compact><li>If there are open cursors in the database; or if an 67invalid flag value or parameter was specified.</ul> 68<br> 69<p>If a transactional database environment operation was selected to 70resolve a deadlock, the Db::truncate method will fail and 71either return <a href="../ref/program/errorret.html#DB_LOCK_DEADLOCK">DB_LOCK_DEADLOCK</a> or 72throw a <a href="../api_cxx/deadlock_class.html">DbDeadlockException</a> exception.</p> 73<p>If a Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable 74to grant a lock in the allowed time, the Db::truncate method will fail and 75either return <a href="../ref/program/errorret.html#DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a> or 76throw a <a href="../api_cxx/lockng_class.html">DbLockNotGrantedException</a> exception.</p> 77<hr size=1 noshade> 78<br><b>Class</b> 79<a href="../api_cxx/db_class.html">Db</a> 80<br><b>See Also</b> 81<a href="../api_cxx/db_list.html">Databases and Related Methods</a> 82</tt> 83<table width="100%"><tr><td><br></td><td align=right> 84<a href="../api_cxx/api_core.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a> 85</td></tr></table> 86<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 87</body> 88</html> 89