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.h> 39 40int 41DB->rename(DB *db, 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="DB_ENV->dbrename()">DB_ENV->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 <span> 81 method returns a non-zero error value on failure and 0 on success. 82 </span> 83 84 </span> 85 </p> 86 <div class="sect2" lang="en" xml:lang="en"> 87 <div class="titlepage"> 88 <div> 89 <div> 90 <h3 class="title"><a id="id1641954"></a>Parameters</h3> 91 </div> 92 </div> 93 </div> 94 <div class="sect3" lang="en" xml:lang="en"> 95 <div class="titlepage"> 96 <div> 97 <div> 98 <h4 class="title"><a id="id1641962"></a>database</h4> 99 </div> 100 </div> 101 </div> 102 <p> 103 The <span class="bold"><strong>database</strong></span> parameter is the 104 database to be renamed. 105 </p> 106 </div> 107 <div class="sect3" lang="en" xml:lang="en"> 108 <div class="titlepage"> 109 <div> 110 <div> 111 <h4 class="title"><a id="id1642048"></a>file</h4> 112 </div> 113 </div> 114 </div> 115 <p> 116 The <span class="bold"><strong>file</strong></span> parameter is the physical 117 file which contains the database(s) to be renamed. 118 </p> 119 <p> 120 When using a Unicode build on Windows (the default), the 121 <span class="bold"><strong>file</strong></span> argument will 122 be interpreted as a UTF-8 string, which is equivalent to ASCII for Latin 123 characters. 124 </p> 125 </div> 126 <div class="sect3" lang="en" xml:lang="en"> 127 <div class="titlepage"> 128 <div> 129 <div> 130 <h4 class="title"><a id="id1642073"></a>flags</h4> 131 </div> 132 </div> 133 </div> 134 <p> 135 The <span class="bold"><strong>flags</strong></span> parameter is currently unused, and must 136 be set to 0. 137 </p> 138 </div> 139 <div class="sect3" lang="en" xml:lang="en"> 140 <div class="titlepage"> 141 <div> 142 <div> 143 <h4 class="title"><a id="id1642087"></a>newname</h4> 144 </div> 145 </div> 146 </div> 147 <p> 148 The <span class="bold"><strong>newname</strong></span> parameter is the new name 149 of the database or file. 150 </p> 151 </div> 152 </div> 153 <div class="sect2" lang="en" xml:lang="en"> 154 <div class="titlepage"> 155 <div> 156 <div> 157 <h3 class="title"><a id="id1642100"></a>Environment Variables</h3> 158 </div> 159 </div> 160 </div> 161 <p> 162 If the database was opened within a database environment, the 163 environment variable <code class="literal">DB_HOME</code> may be used as the path of the 164 database environment home. 165 </p> 166 <p> 167 <code class="methodname">DB->rename()</code> is affected by any database directory specified using the 168 <a class="xref" href="envset_data_dir.html" title="DB_ENV->set_data_dir()">DB_ENV->set_data_dir()</a> 169 method, or by setting the "set_data_dir" string in the environment's 170 <a href="../../programmer_reference/env_db_config.html#env_db_config.DB_CONFIG" class="olink">DB_CONFIG</a> 171 file. 172 </p> 173 </div> 174 <div class="sect2" lang="en" xml:lang="en"> 175 <div class="titlepage"> 176 <div> 177 <div> 178 <h3 class="title"><a id="id1642025"></a>Errors</h3> 179 </div> 180 </div> 181 </div> 182 <p> 183 The <code class="methodname">DB->rename()</code> <span> 184 <span> 185 method may fail and return one of the following non-zero errors: 186 </span> 187 188 </span> 189 </p> 190 <div class="sect3" lang="en" xml:lang="en"> 191 <div class="titlepage"> 192 <div> 193 <div> 194 <h4 class="title"><a id="id1641969"></a>EINVAL</h4> 195 </div> 196 </div> 197 </div> 198 <p> 199 If the method was called after <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> 200 was called; or if an invalid flag value or parameter was specified. 201 </p> 202 </div> 203 <div class="sect3" lang="en" xml:lang="en"> 204 <div class="titlepage"> 205 <div> 206 <div> 207 <h4 class="title"><a id="id1641965"></a>ENOENT</h4> 208 </div> 209 </div> 210 </div> 211 <p> 212 The file or directory does not exist. 213 </p> 214 </div> 215 </div> 216 <div class="sect2" lang="en" xml:lang="en"> 217 <div class="titlepage"> 218 <div> 219 <div> 220 <h3 class="title"><a id="id1641947"></a>Class</h3> 221 </div> 222 </div> 223 </div> 224 <p> 225 <a class="link" href="db.html" title="Chapter 2. The DB Handle">DB</a> 226 </p> 227 </div> 228 <div class="sect2" lang="en" xml:lang="en"> 229 <div class="titlepage"> 230 <div> 231 <div> 232 <h3 class="title"><a id="id1642089"></a>See Also</h3> 233 </div> 234 </div> 235 </div> 236 <p> 237 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 238 </p> 239 </div> 240 </div> 241 <div class="navfooter"> 242 <hr /> 243 <table width="100%" summary="Navigation footer"> 244 <tr> 245 <td width="40%" align="left"><a accesskey="p" href="dbremove.html">Prev</a> </td> 246 <td width="20%" align="center"> 247 <a accesskey="u" href="db.html">Up</a> 248 </td> 249 <td width="40%" align="right"> <a accesskey="n" href="dbset_alloc.html">Next</a></td> 250 </tr> 251 <tr> 252 <td width="40%" align="left" valign="top">DB->remove() </td> 253 <td width="20%" align="center"> 254 <a accesskey="h" href="index.html">Home</a> 255 </td> 256 <td width="40%" align="right" valign="top"> DB->set_alloc()</td> 257 </tr> 258 </table> 259 </div> 260 </body> 261</html> 262