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>DbEnv::dbrename()</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="env.html" title="Chapter 5. The DbEnv Handle" /> 11 <link rel="prev" href="envdbremove.html" title="DbEnv::dbremove()" /> 12 <link rel="next" href="enverr.html" title="DbEnv::err()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">DbEnv::dbrename()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="envdbremove.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 5. 23 The DbEnv Handle 24 </th> 25 <td width="20%" align="right"> <a accesskey="n" href="enverr.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="envdbrename"></a>DbEnv::dbrename()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db_cxx.h> 39 40int 41DbEnv::dbrename(DbTxn *txnid, const char *file, 42 const char *database, const char *newname, u_int32_t flags);</pre> 43 <p> 44 The <code class="methodname">DbEnv::dbrename()</code> method renames the database specified by the 45 <span class="bold"><strong>file</strong></span> and <span class="bold"><strong>database</strong></span> parameters to <span class="bold"><strong>newname</strong></span>. If no <span class="bold"><strong>database</strong></span> is specified, the underlying file 46 represented by <span class="bold"><strong>file</strong></span> is renamed 47 using the value supplied to <span class="bold"><strong>newname</strong></span>, 48 incidentally renaming all of the databases it contained. 49 </p> 50 <p> 51 Applications should not rename databases that are currently in use. 52 If an underlying file is being renamed and logging is currently 53 enabled in the database environment, no database in the file may be 54 open when the <code class="methodname">DbEnv::dbrename()</code> method is called. 55 </p> 56 <p> 57 The <code class="methodname">DbEnv::dbrename()</code> <span> 58 59 <span> 60 method either returns a non-zero error value or throws an 61 exception that encapsulates a non-zero error value on 62 failure, and returns 0 on success. 63 </span> 64 </span> 65 </p> 66 <p> 67 <code class="methodname">DbEnv::dbrename()</code> is affected by any database directory specified using the 68 <a class="xref" href="envset_data_dir.html" title="DbEnv::set_data_dir()">DbEnv::set_data_dir()</a> 69 method, or by setting the <code class="literal">set_data_dir</code> string in the environment's 70 <a href="../../programmer_reference/env_db_config.html#env_db_config.DB_CONFIG" class="olink">DB_CONFIG</a> file. 71 </p> 72 <div class="sect2" lang="en" xml:lang="en"> 73 <div class="titlepage"> 74 <div> 75 <div> 76 <h3 class="title"><a id="id1663511"></a>Parameters</h3> 77 </div> 78 </div> 79 </div> 80 <div class="sect3" lang="en" xml:lang="en"> 81 <div class="titlepage"> 82 <div> 83 <div> 84 <h4 class="title"><a id="id1663821"></a>database</h4> 85 </div> 86 </div> 87 </div> 88 <p> 89 The <span class="bold"><strong>database</strong></span> parameter is the 90 database to be renamed. 91 </p> 92 </div> 93 <div class="sect3" lang="en" xml:lang="en"> 94 <div class="titlepage"> 95 <div> 96 <div> 97 <h4 class="title"><a id="id1663533"></a>file</h4> 98 </div> 99 </div> 100 </div> 101 <p> 102 The <span class="bold"><strong>file</strong></span> parameter is the physical 103 file which contains the database(s) to be renamed. 104 </p> 105 <p> 106 When using a Unicode build on Windows (the default), the 107 <span class="bold"><strong>file</strong></span> argument will 108 be interpreted as a UTF-8 string, which is equivalent to ASCII for Latin 109 characters. 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="id1663852"></a>flags</h4> 117 </div> 118 </div> 119 </div> 120 <p> 121 The <span class="bold"><strong>flags</strong></span> parameter 122 must be set to 0 or the following value: 123 </p> 124 <div class="itemizedlist"> 125 <ul type="disc"> 126 <li> 127 <p> 128 <code class="literal">DB_AUTO_COMMIT</code> 129 </p> 130 <p> 131 Enclose the <code class="methodname">DbEnv::dbrename()</code> 132 call within a transaction. If the call 133 succeeds, changes made by the operation will be recoverable. If the 134 call fails, the operation will have made no changes. 135 </p> 136 </li> 137 </ul> 138 </div> 139 </div> 140 <div class="sect3" lang="en" xml:lang="en"> 141 <div class="titlepage"> 142 <div> 143 <div> 144 <h4 class="title"><a id="id1663534"></a>newname</h4> 145 </div> 146 </div> 147 </div> 148 <p> 149 The <span class="bold"><strong>newname</strong></span> parameter is the new name 150 of the database or file. 151 </p> 152 </div> 153 <div class="sect3" lang="en" xml:lang="en"> 154 <div class="titlepage"> 155 <div> 156 <div> 157 <h4 class="title"><a id="id1663853"></a>txnid</h4> 158 </div> 159 </div> 160 </div> 161 <p> 162 If the operation is part of an application-specified transaction, the 163 <span class="bold"><strong>txnid</strong></span> parameter is a transaction 164 handle returned from <a class="xref" href="txnbegin.html" title="DbEnv::txn_begin()">DbEnv::txn_begin()</a>; if the 165 operation is part of a Berkeley DB Concurrent Data Store group, the 166 <span class="bold"><strong>txnid</strong></span> parameter is a handle returned 167 from <a class="xref" href="envcdsgroup_begin.html" title="DbEnv::cdsgroup_begin()">DbEnv::cdsgroup_begin()</a>; 168 otherwise NULL. If no transaction handle is specified, but the 169 <code class="literal">DB_AUTO_COMMIT</code> flag is specified to either this method or the 170 environment handle, the operation will be implicitly 171 transaction protected. 172 </p> 173 </div> 174 </div> 175 <div class="sect2" lang="en" xml:lang="en"> 176 <div class="titlepage"> 177 <div> 178 <div> 179 <h3 class="title"><a id="id1663969"></a>Environment Variables</h3> 180 </div> 181 </div> 182 </div> 183 <p> 184 The environment variable <code class="literal">DB_HOME</code> may be used as the path of 185 the database environment home. 186 </p> 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="id1663984"></a>Errors</h3> 193 </div> 194 </div> 195 </div> 196 <p> 197 The <code class="methodname">DbEnv::dbrename()</code> <span> 198 199 <span> 200 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> 201 exception, encapsulating one of the following non-zero errors, or return one 202 of the following non-zero errors: 203 </span> 204 </span> 205 </p> 206 <div class="sect3" lang="en" xml:lang="en"> 207 <div class="titlepage"> 208 <div> 209 <div> 210 <h4 class="title"><a id="id1664013"></a><span>DbDeadlockException or </span>DB_LOCK_DEADLOCK</h4> 211 </div> 212 </div> 213 </div> 214 <p> 215 A transactional database environment operation was selected to resolve 216 a deadlock. 217 </p> 218 <p> 219 <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if 220 your Berkeley DB API is configured to throw exceptions. 221 Otherwise, <code class="literal">DB_LOCK_DEADLOCK</code> is returned. 222 </p> 223 </div> 224 <div class="sect3" lang="en" xml:lang="en"> 225 <div class="titlepage"> 226 <div> 227 <div> 228 <h4 class="title"><a id="id1664125"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4> 229 </div> 230 </div> 231 </div> 232 <p> 233 A Berkeley DB Concurrent Data Store database environment configured 234 for lock timeouts was unable to grant a lock in the allowed time. 235 </p> 236 <p> 237 <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if 238 your Berkeley DB API is configured to throw exceptions. 239 Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned. 240 </p> 241 </div> 242 <div class="sect3" lang="en" xml:lang="en"> 243 <div class="titlepage"> 244 <div> 245 <div> 246 <h4 class="title"><a id="id1664104"></a>EINVAL</h4> 247 </div> 248 </div> 249 </div> 250 <p> 251 If the method was called before <a class="xref" href="envopen.html" title="DbEnv::open()">DbEnv::open()</a> 252 was called; or if an invalid flag value or parameter was specified. 253 </p> 254 </div> 255 <div class="sect3" lang="en" xml:lang="en"> 256 <div class="titlepage"> 257 <div> 258 <div> 259 <h4 class="title"><a id="id1664133"></a>ENOENT</h4> 260 </div> 261 </div> 262 </div> 263 <p> 264 The file or directory does not exist. 265 </p> 266 </div> 267 </div> 268 <div class="sect2" lang="en" xml:lang="en"> 269 <div class="titlepage"> 270 <div> 271 <div> 272 <h3 class="title"><a id="id1663865"></a>Class</h3> 273 </div> 274 </div> 275 </div> 276 <p> 277 <a class="link" href="env.html" title="Chapter 5. The DbEnv Handle">DbEnv</a> 278 </p> 279 </div> 280 <div class="sect2" lang="en" xml:lang="en"> 281 <div class="titlepage"> 282 <div> 283 <div> 284 <h3 class="title"><a id="id1663805"></a>See Also</h3> 285 </div> 286 </div> 287 </div> 288 <p> 289 <a class="xref" href="env.html#envlist" title="Database Environments and Related Methods">Database Environments and Related Methods</a> 290 </p> 291 </div> 292 </div> 293 <div class="navfooter"> 294 <hr /> 295 <table width="100%" summary="Navigation footer"> 296 <tr> 297 <td width="40%" align="left"><a accesskey="p" href="envdbremove.html">Prev</a> </td> 298 <td width="20%" align="center"> 299 <a accesskey="u" href="env.html">Up</a> 300 </td> 301 <td width="40%" align="right"> <a accesskey="n" href="enverr.html">Next</a></td> 302 </tr> 303 <tr> 304 <td width="40%" align="left" valign="top">DbEnv::dbremove() </td> 305 <td width="20%" align="center"> 306 <a accesskey="h" href="index.html">Home</a> 307 </td> 308 <td width="40%" align="right" valign="top"> DbEnv::err()</td> 309 </tr> 310 </table> 311 </div> 312 </body> 313</html> 314