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::rename()</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="dbremove.html" title="Db::remove()" /> 12 <link rel="next" href="dbset_alloc.html" title="Db::set_alloc()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Db::rename()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="dbremove.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="dbset_alloc.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="dbrename"></a>Db::rename()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db_cxx.h> 39 40int 41Db::rename(const char *file, 42 const char *database, const char *newname, u_int32_t flags);</pre> 43 <p> 44 The <code class="methodname">Db::rename()</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 incidentally renaming all of the databases it contained. 48 </p> 49 <p> 50 Applications should not rename databases that are currently in use. 51 If an underlying file is being renamed and logging is currently 52 enabled in the database environment, no database in the file may be 53 open when the <code class="methodname">Db::rename()</code> method is called. In particular, some 54 architectures do not permit renaming files with open handles. On 55 these architectures, attempts to rename databases that are currently 56 in use by any thread of control in the system may fail. 57 </p> 58 <p> 59 The <code class="methodname">Db::rename()</code> method should not be called if the rename is 60 intended to be transactionally safe; the 61 <a class="xref" href="envdbrename.html" title="DbEnv::dbrename()">DbEnv::dbrename()</a> method 62 should be used instead. 63 </p> 64 <p> 65 The <code class="methodname">Db::rename()</code> method may not be called after calling the 66 <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> method on any 67 <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> handle. If the 68 <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> method has already 69 been called on a <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> 70 handle, close the existing handle and create a new one before calling 71 <code class="methodname">Db::rename()</code>. 72 </p> 73 <p> 74 The <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> handle may not be 75 accessed again after <code class="methodname">Db::rename()</code> is called, regardless of its 76 return. 77 </p> 78 <p> 79 The <code class="methodname">Db::rename()</code> <span> 80 81 <span> 82 method either returns a non-zero error value or throws an 83 exception that encapsulates a non-zero error value on 84 failure, and returns 0 on success. 85 </span> 86 </span> 87 </p> 88 <div class="sect2" lang="en" xml:lang="en"> 89 <div class="titlepage"> 90 <div> 91 <div> 92 <h3 class="title"><a id="id1642218"></a>Parameters</h3> 93 </div> 94 </div> 95 </div> 96 <div class="sect3" lang="en" xml:lang="en"> 97 <div class="titlepage"> 98 <div> 99 <div> 100 <h4 class="title"><a id="id1642224"></a>database</h4> 101 </div> 102 </div> 103 </div> 104 <p> 105 The <span class="bold"><strong>database</strong></span> parameter is the 106 database to be renamed. 107 </p> 108 </div> 109 <div class="sect3" lang="en" xml:lang="en"> 110 <div class="titlepage"> 111 <div> 112 <div> 113 <h4 class="title"><a id="id1642338"></a>file</h4> 114 </div> 115 </div> 116 </div> 117 <p> 118 The <span class="bold"><strong>file</strong></span> parameter is the physical 119 file which contains the database(s) to be renamed. 120 </p> 121 <p> 122 When using a Unicode build on Windows (the default), the 123 <span class="bold"><strong>file</strong></span> argument will 124 be interpreted as a UTF-8 string, which is equivalent to ASCII for Latin 125 characters. 126 </p> 127 </div> 128 <div class="sect3" lang="en" xml:lang="en"> 129 <div class="titlepage"> 130 <div> 131 <div> 132 <h4 class="title"><a id="id1642364"></a>flags</h4> 133 </div> 134 </div> 135 </div> 136 <p> 137 The <span class="bold"><strong>flags</strong></span> parameter is currently unused, and must 138 be set to 0. 139 </p> 140 </div> 141 <div class="sect3" lang="en" xml:lang="en"> 142 <div class="titlepage"> 143 <div> 144 <div> 145 <h4 class="title"><a id="id1642212"></a>newname</h4> 146 </div> 147 </div> 148 </div> 149 <p> 150 The <span class="bold"><strong>newname</strong></span> parameter is the new name 151 of the database or file. 152 </p> 153 </div> 154 </div> 155 <div class="sect2" lang="en" xml:lang="en"> 156 <div class="titlepage"> 157 <div> 158 <div> 159 <h3 class="title"><a id="id1642241"></a>Environment Variables</h3> 160 </div> 161 </div> 162 </div> 163 <p> 164 If the database was opened within a database environment, the 165 environment variable <code class="literal">DB_HOME</code> may be used as the path of the 166 database environment home. 167 </p> 168 <p> 169 <code class="methodname">Db::rename()</code> is affected by any database directory specified using the 170 <a class="xref" href="envset_data_dir.html" title="DbEnv::set_data_dir()">DbEnv::set_data_dir()</a> 171 method, or by setting the "set_data_dir" string in the environment's 172 <a href="../../programmer_reference/env_db_config.html#env_db_config.DB_CONFIG" class="olink">DB_CONFIG</a> 173 file. 174 </p> 175 </div> 176 <div class="sect2" lang="en" xml:lang="en"> 177 <div class="titlepage"> 178 <div> 179 <div> 180 <h3 class="title"><a id="id1642238"></a>Errors</h3> 181 </div> 182 </div> 183 </div> 184 <p> 185 The <code class="methodname">Db::rename()</code> <span> 186 187 <span> 188 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> 189 exception, encapsulating one of the following non-zero errors, or return one 190 of the following non-zero errors: 191 </span> 192 </span> 193 </p> 194 <div class="sect3" lang="en" xml:lang="en"> 195 <div class="titlepage"> 196 <div> 197 <div> 198 <h4 class="title"><a id="id1642358"></a>EINVAL</h4> 199 </div> 200 </div> 201 </div> 202 <p> 203 If the method was called after <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> 204 was called; or if an invalid flag value or parameter was specified. 205 </p> 206 </div> 207 <div class="sect3" lang="en" xml:lang="en"> 208 <div class="titlepage"> 209 <div> 210 <div> 211 <h4 class="title"><a id="id1642346"></a>ENOENT</h4> 212 </div> 213 </div> 214 </div> 215 <p> 216 The file or directory does not exist. 217 </p> 218 </div> 219 </div> 220 <div class="sect2" lang="en" xml:lang="en"> 221 <div class="titlepage"> 222 <div> 223 <div> 224 <h3 class="title"><a id="id1642131"></a>Class</h3> 225 </div> 226 </div> 227 </div> 228 <p> 229 <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> 230 </p> 231 </div> 232 <div class="sect2" lang="en" xml:lang="en"> 233 <div class="titlepage"> 234 <div> 235 <div> 236 <h3 class="title"><a id="id1642213"></a>See Also</h3> 237 </div> 238 </div> 239 </div> 240 <p> 241 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 242 </p> 243 </div> 244 </div> 245 <div class="navfooter"> 246 <hr /> 247 <table width="100%" summary="Navigation footer"> 248 <tr> 249 <td width="40%" align="left"><a accesskey="p" href="dbremove.html">Prev</a> </td> 250 <td width="20%" align="center"> 251 <a accesskey="u" href="db.html">Up</a> 252 </td> 253 <td width="40%" align="right"> <a accesskey="n" href="dbset_alloc.html">Next</a></td> 254 </tr> 255 <tr> 256 <td width="40%" align="left" valign="top">Db::remove() </td> 257 <td width="20%" align="center"> 258 <a accesskey="h" href="index.html">Home</a> 259 </td> 260 <td width="40%" align="right" valign="top"> Db::set_alloc()</td> 261 </tr> 262 </table> 263 </div> 264 </body> 265</html> 266