Debian Codegraph @

docs/api_reference/CXX/dbassociate_foreign.html

raw symbols SCIP
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::associate_foreign()</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="dbassociate.html" title="Db::associate()" />
12 <link rel="next" href="dbclose.html" title="Db::close()" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Db::associate_foreign()</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="dbassociate.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 2. 
26 The Db Handle
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="dbclose.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="dbassociate_foreign"></a>Db::associate_foreign()</h2>
38 </div>
39 </div>
40 </div>
41 <pre class="programlisting">#include &lt;db_cxx.h&gt;
42
43 int
44 DB::associate_foreign(Db *secondary,,
45 int (*callback)(Db *secondary,
46 const Dbt *key, Dbt *data, const Dbt *foreignkey, int *changed),
47 u_int32_t flags); </pre>
48 <p>
49 The <code class="methodname">Db::associate_foreign()</code> function is used to declare one database a
50 foreign constraint for a secondary database. The
51 <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a> handle that you call the
52 <code class="methodname">associate_foreign()</code> method from is the foreign
53 database.
54 </p>
55 <p>
56 After a foreign database has been "associated" with a secondary
57 database, all keys inserted into the secondary must exist in the
58 foreign database. Attempting to add a record with a foreign key
59 that does not exist in the foreign database will cause the put
60 method to fail and return <code class="literal">DB_FOREIGN_CONFLICT</code>.
61 </p>
62 <p>
63 Deletions in the foreign database affect the secondary in a manner
64 defined by the flags parameter. See
65 <a href="../../programmer_reference/am_foreign.html" class="olink">Foreign Indices</a>
66 in the <em class="citetitle">Berkeley DB Programmer's Reference Guide</em> for more information.
67 </p>
68 <p>
69 The <code class="methodname">Db::associate_foreign()</code> <span>
70
71 <span>
72 method either returns a non-zero error value or throws an
73 exception that encapsulates a non-zero error value on
74 failure, and returns 0 on success.
75 </span>
76 </span>
77 </p>
78 <div class="sect2" lang="en" xml:lang="en">
79 <div class="titlepage">
80 <div>
81 <div>
82 <h3 class="title"><a id="idp87016"></a>Parameters</h3>
83 </div>
84 </div>
85 </div>
86 <div class="sect3" lang="en" xml:lang="en">
87 <div class="titlepage">
88 <div>
89 <div>
90 <h4 class="title"><a id="idp113288"></a>secondary</h4>
91 </div>
92 </div>
93 </div>
94 <p>
95 The <span class="bold"><strong>secondary</strong></span> parameter should be an
96 open database handle of a database that contains a secondary index who's
97 keys also exist in the <span class="bold"><strong>foreign</strong></span> database.
98 </p>
99 </div>
100 <div class="sect3" lang="en" xml:lang="en">
101 <div class="titlepage">
102 <div>
103 <div>
104 <h4 class="title"><a id="idm149216"></a>callback</h4>
105 </div>
106 </div>
107 </div>
108 <p>
109 The <span class="bold"><strong>callback</strong></span> parameter is a callback
110 function that nullifies the foreign key portion of a data <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a>.
111 </p>
112 <p>
113 The callback parameter must be NULL if either DB_FOREIGN_ABORT or DB_FOREIGN_CASCADE is set.
114 </p>
115 <p>
116 The callback takes four arguments:
117 </p>
118 <div class="itemizedlist">
119 <ul type="disc">
120 <li>
121 <p>
122 <code class="literal">secondary</code>
123 </p>
124 <p>
125 The <span class="bold"><strong>secondary</strong></span> parameter is the
126 database handle for the secondary.
127 </p>
128 </li>
129 <li>
130 <p>
131 <code class="literal">key</code>
132 </p>
133 <p>
134 The <span class="bold"><strong>key</strong></span> parameter is a
135 <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> referencing the primary key.
136 </p>
137 </li>
138 <li>
139 <p>
140 <code class="literal">data</code>
141 </p>
142 <p>
143 The <span class="bold"><strong>data</strong></span> parameter is a
144 <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> referencing the primary data
145 item to be updated.
146 </p>
147 </li>
148 <li>
149 <p>
150 <code class="literal">foreignkey</code>
151 </p>
152 <p>
153 The <span class="bold"><strong>foreignkey</strong></span> parameter is a
154 <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> referencing the foreign
155 key which is being deleted.
156 </p>
157 </li>
158 <li>
159 <p>
160 <code class="literal">changed</code>
161 </p>
162 <p>
163 The <span class="bold"><strong>changed</strong></span> parameter is a
164 pointer to a boolean value, indicated whether <span class="bold"><strong>data</strong></span>
165 has changed.
166 </p>
167 </li>
168 </ul>
169 </div>
170 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
171 <h3 class="title">Note</h3>
172 <p>
173 Berkeley DB is not re-entrant. Callback functions should not
174 attempt to make library calls (for example, to release locks or
175 close open handles). Re-entering Berkeley DB is not guaranteed
176 to work correctly, and the results are undefined.
177 </p>
178 </div>
179 </div>
180 <div class="sect3" lang="en" xml:lang="en">
181 <div class="titlepage">
182 <div>
183 <div>
184 <h4 class="title"><a id="idm2106272"></a>flags</h4>
185 </div>
186 </div>
187 </div>
188 <p>
189 The <span class="bold"><strong>flags</strong></span> parameter must be set to
190 one of the following values:
191 </p>
192 <div class="itemizedlist">
193 <ul type="disc">
194 <li>
195 <p><a id="associate_foreign_DB_FOREIGN_ABORT"></a>
196 <code class="literal">DB_FOREIGN_ABORT</code>
197 </p>
198 <p>
199 Abort the deletion of a key in the foreign database and return DB_FOREIGN_CONFLICT
200 if that key exists in the secondary database. The deletion should be protected by
201 a transaction to ensure database integrity after the aborted delete.
202 </p>
203 </li>
204 <li>
205 <p><a id="associate_foreign_DB_FOREIGN_CASCADE"></a>
206 <code class="literal">DB_FOREIGN_CASCADE</code>
207 </p>
208 <p>
209 The deletion of a key in the foreign database will also delete that key from the
210 secondary database (and the corresponding entry in the secondary's primary database.)
211 </p>
212 </li>
213 <li>
214 <p><a id="associate_foreign_DB_FOREIGN_NULLIFY"></a>
215 <code class="literal">DB_FOREIGN_NULLIFY</code>
216 </p>
217 <p>
218 The deletion of a key in the foreign database will call the nullification function
219 passed to associate_foreign and update the secondary database with the changed data.
220 </p>
221 </li>
222 </ul>
223 </div>
224 </div>
225 </div>
226 <div class="sect2" lang="en" xml:lang="en">
227 <div class="titlepage">
228 <div>
229 <div>
230 <h3 class="title"><a id="idp719440"></a>Errors</h3>
231 </div>
232 </div>
233 </div>
234 <p>
235 The <code class="methodname">Db::associate_foreign()</code> <span>
236
237 <span>
238 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a>
239 exception, encapsulating one of the following non-zero errors, or return one
240 of the following non-zero errors:
241 </span>
242 </span>
243 </p>
244 <div class="sect3" lang="en" xml:lang="en">
245 <div class="titlepage">
246 <div>
247 <div>
248 <h4 class="title"><a id="idp4471568"></a> <span>DbRepHandleDeadException or</span> DB_REP_HANDLE_DEAD</h4>
249 </div>
250 </div>
251 </div>
252 <p>
253 When a client synchronizes with the master, it is possible for committed
254 transactions to be rolled back. This invalidates all the database and cursor
255 handles opened in the replication environment. Once this occurs, an attempt to use
256 such a handle will
257 <span>
258 throw a <a class="xref" href="dbrephandledead.html" title="DbRepHandleDeadException">DbRepHandleDeadException</a> (if
259 your application is configured to throw exceptions), or
260 </span>
261 return <code class="literal">DB_REP_HANDLE_DEAD</code>.
262 The application will need to discard the handle and open a new one in order to
263 continue processing.
264 </p>
265 </div>
266 <div class="sect3" lang="en" xml:lang="en">
267 <div class="titlepage">
268 <div>
269 <div>
270 <h4 class="title"><a id="idp4064360"></a><span>DbDeadlockException or </span>DB_REP_LOCKOUT</h4>
271 </div>
272 </div>
273 </div>
274 <p>
275 The operation was blocked by client/master synchronization.
276 </p>
277 <p>
278 <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if
279 your Berkeley DB API is configured to throw exceptions.
280 Otherwise, <code class="literal">DB_REP_LOCKOUT</code> is returned.
281 </p>
282 </div>
283 <div class="sect3" lang="en" xml:lang="en">
284 <div class="titlepage">
285 <div>
286 <div>
287 <h4 class="title"><a id="idp3435160"></a>EINVAL</h4>
288 </div>
289 </div>
290 </div>
291 <p>
292 If the foreign database handle is a secondary index; the foreign
293 database handle has been configured to allow duplicates; the foreign
294 database handle is a renumbering recno database; callback is
295 configured and DB_FOREIGN_NULLIFY is not; DB_FOREIGN_NULLIFY is
296 configured and callback is not.
297 </p>
298 </div>
299 </div>
300 <div class="sect2" lang="en" xml:lang="en">
301 <div class="titlepage">
302 <div>
303 <div>
304 <h3 class="title"><a id="idm2353024"></a>Class</h3>
305 </div>
306 </div>
307 </div>
308 <p>
309 <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>
310 </p>
311 </div>
312 <div class="sect2" lang="en" xml:lang="en">
313 <div class="titlepage">
314 <div>
315 <div>
316 <h3 class="title"><a id="idp3385048"></a>See Also</h3>
317 </div>
318 </div>
319 </div>
320 <p>
321 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a>
322 </p>
323 </div>
324 </div>
325 <div class="navfooter">
326 <hr />
327 <table width="100%" summary="Navigation footer">
328 <tr>
329 <td width="40%" align="left"><a accesskey="p" href="dbassociate.html">Prev</a> </td>
330 <td width="20%" align="center">
331 <a accesskey="u" href="db.html">Up</a>
332 </td>
333 <td width="40%" align="right"> <a accesskey="n" href="dbclose.html">Next</a></td>
334 </tr>
335 <tr>
336 <td width="40%" align="left" valign="top">Db::associate() </td>
337 <td width="20%" align="center">
338 <a accesskey="h" href="index.html">Home</a>
339 </td>
340 <td width="40%" align="right" valign="top"> Db::close()</td>
341 </tr>
342 </table>
343 </div>
344 </body>
345 </html>