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::sync()</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="dbstat_print.html" title="Db::stat_print()" /> 12 <link rel="next" href="dbtruncate.html" title="Db::truncate()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Db::sync()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="dbstat_print.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="dbtruncate.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="dbsync"></a>Db::sync()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db_cxx.h> 39 40int 41Db::sync(u_int32_t flags);</pre> 42 <p> 43 The <code class="methodname">Db::sync()</code> method flushes any cached information to disk. 44 </p> 45 <p> 46 If the database is in memory only, the <code class="methodname">Db::sync()</code> method has no 47 effect and will always succeed. 48 </p> 49 <p> 50 <span class="bold"><strong>It is important to understand that flushing 51 cached information to disk only minimizes the window of opportunity 52 for corrupted data.</strong></span> Although unlikely, it is possible for 53 database corruption to happen if a system or application crash occurs 54 while writing data to the database. To ensure that database 55 corruption never occurs, applications must either: use transactions 56 and logging with automatic recovery; use logging and 57 application-specific recovery; or edit a copy of the database, and 58 once all applications using the database have successfully called 59 <a class="xref" href="dbclose.html" title="Db::close()">Db::close()</a>, atomically 60 replace the original database with the updated copy. 61 </p> 62 <p> 63 The <code class="methodname">Db::sync()</code> <span> 64 65 <span> 66 method either returns a non-zero error value or throws an 67 exception that encapsulates a non-zero error value on 68 failure, and returns 0 on success. 69 </span> 70 </span> 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="id1653166"></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="id1653146"></a>flags</h4> 85 </div> 86 </div> 87 </div> 88 <p> 89 The <span class="bold"><strong>flags</strong></span> parameter is currently 90 unused, and must be set to 0. 91 </p> 92 </div> 93 </div> 94 <div class="sect2" lang="en" xml:lang="en"> 95 <div class="titlepage"> 96 <div> 97 <div> 98 <h3 class="title"><a id="id1653268"></a>Errors</h3> 99 </div> 100 </div> 101 </div> 102 <p> 103 The <code class="methodname">Db::sync()</code> <span> 104 105 <span> 106 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter��6.��The DbException Class">DbException</a> 107 exception, encapsulating one of the following non-zero errors, or return one 108 of the following non-zero errors: 109 </span> 110 </span> 111 </p> 112 <div class="sect3" lang="en" xml:lang="en"> 113 <div class="titlepage"> 114 <div> 115 <div> 116 <h4 class="title"><a id="id1653021"></a><span>DbRepHandleDeadException or</span> DB_REP_HANDLE_DEAD</h4> 117 </div> 118 </div> 119 </div> 120 <p> 121 When a client synchronizes with the master, it is possible for committed 122 transactions to be rolled back. This invalidates all the database and cursor 123 handles opened in the replication environment. Once this occurs, an attempt to use 124 such a handle will 125 <span> 126 throw a <a class="xref" href="dbrephandledead.html" title="DbRepHandleDeadException">DbRepHandleDeadException</a> (if 127 your application is configured to throw exceptions), or 128 </span> 129 return <code class="literal">DB_REP_HANDLE_DEAD</code>. 130 The application will need to discard the handle and open a new one in order to 131 continue processing. 132 </p> 133 </div> 134 <div class="sect3" lang="en" xml:lang="en"> 135 <div class="titlepage"> 136 <div> 137 <div> 138 <h4 class="title"><a id="id1653077"></a><span>DbDeadlockException or </span>DB_REP_LOCKOUT</h4> 139 </div> 140 </div> 141 </div> 142 <p> 143 The operation was blocked by client/master synchronization. 144 </p> 145 <p> 146 <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if 147 your Berkeley DB API is configured to throw exceptions. 148 Otherwise, <code class="literal">DB_REP_LOCKOUT</code> is returned. 149 </p> 150 </div> 151 <div class="sect3" lang="en" xml:lang="en"> 152 <div class="titlepage"> 153 <div> 154 <div> 155 <h4 class="title"><a id="id1653305"></a>EINVAL</h4> 156 </div> 157 </div> 158 </div> 159 <p> 160 An invalid flag value or parameter was specified. 161 </p> 162 </div> 163 </div> 164 <div class="sect2" lang="en" xml:lang="en"> 165 <div class="titlepage"> 166 <div> 167 <div> 168 <h3 class="title"><a id="id1653038"></a>Class</h3> 169 </div> 170 </div> 171 </div> 172 <p> 173 <a class="link" href="db.html" title="Chapter��2.�� The Db Handle">Db</a> 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="id1653291"></a>See Also</h3> 181 </div> 182 </div> 183 </div> 184 <p> 185 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 186 </p> 187 </div> 188 </div> 189 <div class="navfooter"> 190 <hr /> 191 <table width="100%" summary="Navigation footer"> 192 <tr> 193 <td width="40%" align="left"><a accesskey="p" href="dbstat_print.html">Prev</a>��</td> 194 <td width="20%" align="center"> 195 <a accesskey="u" href="db.html">Up</a> 196 </td> 197 <td width="40%" align="right">��<a accesskey="n" href="dbtruncate.html">Next</a></td> 198 </tr> 199 <tr> 200 <td width="40%" align="left" valign="top">Db::stat_print()��</td> 201 <td width="20%" align="center"> 202 <a accesskey="h" href="index.html">Home</a> 203 </td> 204 <td width="40%" align="right" valign="top">��Db::truncate()</td> 205 </tr> 206 </table> 207 </div> 208 </body> 209</html> 210