Debian Codegraph @

docs/api_reference/CXX/dbset_flags.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::set_flags()</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="dbset_feedback.html" title="Db::set_feedback()" />
12 <link rel="next" href="dbset_h_compare.html" title="Db::set_h_compare()" />
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::set_flags()</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="dbset_feedback.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="dbset_h_compare.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="dbset_flags"></a>Db::set_flags()</h2>
38 </div>
39 </div>
40 </div>
41 <pre class="programlisting">#include &lt;db_cxx.h&gt;
42
43 int
44 Db::set_flags(u_int32_t flags); </pre>
45 <p>
46 Configure a database. Calling <code class="methodname">Db::set_flags()</code> is additive; there is
47 no way to clear flags.
48 </p>
49 <p>
50 The <code class="methodname">Db::set_flags()</code> method may not be called after the
51 <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> method is called.
52 </p>
53 <p>
54 The <code class="methodname">Db::set_flags()</code> <span>
55
56 <span>
57 method either returns a non-zero error value or throws an
58 exception that encapsulates a non-zero error value on
59 failure, and returns 0 on success.
60 </span>
61 </span>
62 </p>
63 <div class="sect2" lang="en" xml:lang="en">
64 <div class="titlepage">
65 <div>
66 <div>
67 <h3 class="title"><a id="idp4388176"></a>Parameters</h3>
68 </div>
69 </div>
70 </div>
71 <div class="sect3" lang="en" xml:lang="en">
72 <div class="titlepage">
73 <div>
74 <div>
75 <h4 class="title"><a id="idp3117432"></a>flags</h4>
76 </div>
77 </div>
78 </div>
79 <p>
80 The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
81 or by bitwise inclusively <span class="bold"><strong>OR</strong></span>'ing
82 together one or more of the following values:
83
84 </p>
85 <p>
86 <span class="bold"><strong>General</strong></span>
87 </p>
88 <p>
89 The following flags may be specified for any Berkeley DB access
90 method:
91 </p>
92 <div class="itemizedlist">
93 <ul type="disc">
94 <li>
95 <p><a id="dbset_flags_DB_CHKSUM"></a>
96 <code class="literal">DB_CHKSUM</code>
97 </p>
98 <p>
99 Do checksum verification of pages read into the cache from the backing
100 filestore. Berkeley DB uses the SHA1 Secure Hash Algorithm if
101 encryption is configured and a general hash algorithm if it is not.
102 </p>
103 <p>
104 Calling <code class="methodname">Db::set_flags()</code> with the DB_CHKSUM flag only affects the
105 specified <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a> handle (and
106 any other Berkeley DB handles opened within the scope of that handle).
107 </p>
108 <p>
109 If the database already exists when <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a>
110 is called, the DB_CHKSUM flag will be ignored.
111 </p>
112 </li>
113 <li>
114 <p><a id="dbset_flags_DB_ENCRYPT"></a>
115 <code class="literal">DB_ENCRYPT</code>
116 </p>
117 <p>
118 Encrypt the database using the cryptographic password specified to the
119 <a class="xref" href="envset_encrypt.html" title="DbEnv::set_encrypt()">DbEnv::set_encrypt()</a> or
120 <a class="xref" href="dbset_encrypt.html" title="Db::set_encrypt()">Db::set_encrypt()</a>
121 methods.
122 </p>
123 <p>
124 Calling <code class="methodname">Db::set_flags()</code> with the DB_ENCRYPT flag only affects the
125 specified <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a> handle (and
126 any other Berkeley DB handles opened within the scope of that handle).
127 </p>
128 <p>
129 If the database already exists when <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a>
130 is called, the DB_ENCRYPT flag must be the same as the existing database or an error
131 will be returned.
132 </p>
133 <p>
134 Encrypted databases are not portable between machines of different
135 byte orders, that is, encrypted databases created on big-endian
136 machines cannot be read on little-endian machines, and vice versa.
137 </p>
138 </li>
139 <li>
140 <p><a id="dbset_flags_DB_TXN_NOT_DURABLE"></a>
141 <code class="literal">DB_TXN_NOT_DURABLE</code>
142 </p>
143 <p>
144 If set, Berkeley DB will not write log records for this database.
145 This means that updates of this database exhibit the ACI (atomicity,
146 consistency, and isolation) properties, but not D (durability); that
147 is, database integrity will be maintained, but if the application or
148 system fails, integrity will not persist. The database file must be
149 verified and/or restored from backup after a failure. In order to
150 ensure integrity after application shut down, the database handles
151 must be closed without specifying
152 <a class="link" href="dbclose.html#dbclose_DB_NOSYNC">DB_NOSYNC</a>, or all
153 database changes must be flushed from the database environment cache
154 using either the <a class="xref" href="txncheckpoint.html" title="DbEnv::txn_checkpoint()">DbEnv::txn_checkpoint()</a>
155 or <a class="xref" href="mempsync.html" title="DbEnv::memp_sync()">DbEnv::memp_sync()</a>
156 methods. All database handles for a single physical file must set
157 DB_TXN_NOT_DURABLE, including database handles for different databases
158 in a physical file.
159 </p>
160 <p>
161 Calling <code class="methodname">Db::set_flags()</code>
162 with the DB_TXN_NOT_DURABLE flag only affects the
163 specified <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>
164 handle (and any other Berkeley DB handles opened
165 within the scope of that handle).
166 </p>
167 </li>
168 </ul>
169 </div>
170 <p>
171 <span class="bold"><strong>Btree</strong></span>
172 </p>
173 <p>
174 The following flags may be specified for the Btree access method:
175 </p>
176 <div class="itemizedlist">
177 <ul type="disc">
178 <li>
179 <p><a id="dbset_flags_DB_DUP"></a>
180 <code class="literal">DB_DUP</code>
181 </p>
182 <p>
183 Permit duplicate data items in the database; that is, insertion when
184 the key of the key/data pair being inserted already exists in the
185 database will be successful. The ordering of duplicates in the
186 database is determined by the order of insertion, unless the ordering
187 is otherwise specified by use of a cursor operation or a
188 duplicate sort function.
189 </p>
190 <p>
191 The DB_DUPSORT flag is preferred to DB_DUP for performance reasons.
192 The DB_DUP flag should only be used by applications wanting to order
193 duplicate data items manually.
194 </p>
195 <p>
196 Calling <code class="methodname">Db::set_flags()</code>
197 with the DB_DUP flag affects the database,
198 including all threads of control accessing the
199 database.
200 </p>
201 <p>
202 If the database already exists when
203 <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a>
204 is called, the DB_DUP flag must be the same as
205 the existing database or an error will be
206 returned.
207 </p>
208 <p>
209 It is an error to specify both DB_DUP and DB_RECNUM.
210 </p>
211 </li>
212 <li>
213 <p><a id="dbset_flags_DB_DUPSORT"></a>
214 <code class="literal">DB_DUPSORT</code>
215 </p>
216 <p>
217 Permit duplicate data items in the database; that is, insertion when
218 the key of the key/data pair being inserted already exists in the
219 database will be successful. The ordering of duplicates in the
220 database is determined by the duplicate comparison function. If the
221 application does not specify a comparison function using the
222 <a class="xref" href="dbset_dup_compare.html" title="Db::set_dup_compare()">Db::set_dup_compare()</a>
223 method, a default lexical comparison will be used. It is an error to
224 specify both DB_DUPSORT and DB_RECNUM.
225 </p>
226 <p>
227 Calling <code class="methodname">Db::set_flags()</code>
228 with the DB_DUPSORT flag affects the database,
229 including all threads of control accessing the
230 database.
231 </p>
232 <p>
233 If the database already exists when
234 <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a>
235 is called, the DB_DUPSORT flag must be the same
236 as the existing database or an error will be
237 returned.
238 </p>
239 </li>
240 <li>
241 <p><a id="dbset_flags_DB_RECNUM"></a>
242 <code class="literal">DB_RECNUM</code>
243 </p>
244 <p>
245 Support retrieval from the Btree using record numbers. For more
246 information, see the
247 <a class="link" href="dbget.html#dbget_DB_SET_RECNO">DB_SET_RECNO</a>
248 flag to the <a class="xref" href="dbget.html" title="Db::get()">Db::get()</a> and
249 <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a> methods.
250 </p>
251 <p>
252 Logical record numbers in Btree databases are mutable in the face of
253 record insertion or deletion. See the DB_RENUMBER flag in the Recno
254 access method information for further discussion.
255 </p>
256 <p>
257 Maintaining record counts within a Btree introduces a serious point of
258 contention, namely the page locations where the record counts are
259 stored. In addition, the entire database must be locked during both
260 insertions and deletions, effectively single-threading the database
261 for those operations. Specifying DB_RECNUM can result in serious
262 performance degradation for some applications and data sets.
263 </p>
264 <p>
265 It is an error to specify both DB_DUP and DB_RECNUM.
266 </p>
267 <p>
268 Calling <code class="methodname">Db::set_flags()</code> with the DB_RECNUM flag affects the database,
269 including all threads of control accessing the database.
270 </p>
271 <p>
272 If the database already exists when <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a>
273 is called, the DB_RECNUM flag must be the same as the existing database or an error
274 will be returned.
275 </p>
276 </li>
277 <li>
278 <p><a id="dbset_flags_DB_REVSPLITOFF"></a>
279 <code class="literal">DB_REVSPLITOFF</code>
280 </p>
281 <p>
282 Turn off reverse splitting in the Btree. As pages are emptied in a
283 database, the Berkeley DB Btree implementation attempts to coalesce
284 empty pages into higher-level pages in order to keep the database as
285 small as possible and minimize search time. This can hurt performance
286 in applications with cyclical data demands; that is, applications
287 where the database grows and shrinks repeatedly. For example, because
288 Berkeley DB does page-level locking, the maximum level of concurrency
289 in a database of two pages is far smaller than that in a database of
290 100 pages, so a database that has shrunk to a minimal size can cause
291 severe deadlocking when a new cycle of data insertion begins.
292 </p>
293 <p>
294 Calling <code class="methodname">Db::set_flags()</code>
295 with the DB_REVSPLITOFF flag only affects the
296 specified <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>
297 handle (and any other Berkeley DB handles opened
298 within the scope of that handle).
299 </p>
300 </li>
301 </ul>
302 </div>
303 <p>
304 <span class="bold"><strong>Hash</strong></span>
305 </p>
306 <p>
307 The following flags may be specified for the Hash access method:
308 </p>
309 <div class="itemizedlist">
310 <ul type="disc">
311 <li>
312 <p><a id="dbset_flags_h_DB_DUP"></a>
313 <code class="literal">DB_DUP</code>
314 </p>
315 <p>
316 Permit duplicate data items in the database; that is, insertion when
317 the key of the key/data pair being inserted already exists in the
318 database will be successful. The ordering of duplicates in the
319 database is determined by the order of insertion, unless the ordering
320 is otherwise specified by use of a cursor operation.
321 </p>
322 <p>
323 The DB_DUPSORT flag is preferred to DB_DUP for performance reasons.
324 The DB_DUP flag should only be used by applications wanting to order
325 duplicate data items manually.
326 </p>
327 <p>
328 Calling <code class="methodname">Db::set_flags()</code> with the DB_DUP flag affects the database,
329 including all threads of control accessing the database.
330 </p>
331 <p>
332 If the database already exists when <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a>
333 is called, the DB_DUP flag must be the same as the existing database or an error will be
334 returned.
335 </p>
336 </li>
337 <li>
338 <p>
339 <code class="literal">DB_DUPSORT</code>
340 </p>
341 <p>
342 Permit duplicate data items in the database; that is, insertion when
343 the key of the key/data pair being inserted already exists in the
344 database will be successful. The ordering of duplicates in the
345 database is determined by the duplicate comparison function. If the
346 application does not specify a comparison function using the
347 <a class="xref" href="dbset_dup_compare.html" title="Db::set_dup_compare()">Db::set_dup_compare()</a>
348 method, a default lexical comparison will be used.
349 </p>
350 <p>
351 Calling <code class="methodname">Db::set_flags()</code> with the DB_DUPSORT flag affects the
352 database, including all threads of control accessing the database.
353 </p>
354 <p>
355 If the database already exists when <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a>
356 is called, the DB_DUPSORT flag must be the same as the existing database or an error
357 will be returned.
358 </p>
359 </li>
360 <li>
361 <p><a id="dbset_flags_hash_DB_REVSPLITOFF"></a>
362 <code class="literal">DB_REVSPLITOFF</code>
363 </p>
364 <p>
365 Turns off hash bucket compaction. When a hash bucket is
366 emptied, the Berkeley DB Hash implementation will decrease
367 the hash table size, coalescing buckets. This will
368 decrease the number of pages in the database.
369 This can hurt performance in applications with cyclical
370 data demands — that is, applications where the
371 database grows and shrinks repeatedly — because of
372 the cost of resplitting buckets when they grow again.
373 </p>
374 <p>
375 Calling <code class="methodname">Db::set_flags()</code> with the
376 DB_REVSPLITOFF flag only affects the
377 specified <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a> handle (and
378 any other Berkeley DB handles opened within the scope of that handle).
379 </p>
380 </li>
381 </ul>
382 </div>
383 <p>
384 <span class="bold"><strong>Queue</strong></span>
385 </p>
386 <p>
387 The following flags may be specified for the Queue access method:
388 </p>
389 <div class="itemizedlist">
390 <ul type="disc">
391 <li>
392 <p>
393 <code class="literal">DB_INORDER</code>
394 </p>
395 <p>
396 The DB_INORDER flag modifies the operation of the
397 <a class="link" href="dbget.html#dbget_DB_CONSUME">DB_CONSUME</a> or
398 <a class="link" href="dbget.html#dbget_DB_CONSUME_WAIT">DB_CONSUME_WAIT</a>
399 flags to <a class="xref" href="dbget.html" title="Db::get()">Db::get()</a> to
400 return key/data pairs in order. That is, they will always return the
401 key/data item from the head of the queue.
402 </p>
403 <p>
404 The default behavior of queue databases is optimized for multiple
405 readers, and does not guarantee that record will be retrieved in the
406 order they are added to the queue. Specifically, if a writing thread
407 adds multiple records to an empty queue, reading threads may skip some
408 of the initial records when the next <a class="xref" href="dbget.html" title="Db::get()">Db::get()</a>
409 call returns.
410 </p>
411 <p>
412 This flag modifies the <a class="xref" href="dbget.html" title="Db::get()">Db::get()</a>
413 call to verify that the record being returned is in fact the head of the queue. This will
414 increase contention and reduce concurrency when there are many reading threads.
415 </p>
416 <p>
417 Calling <code class="methodname">Db::set_flags()</code> with the DB_INORDER flag only affects the
418 specified <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a> handle (and
419 any other Berkeley DB handles opened within the scope of that handle).
420 </p>
421 </li>
422 </ul>
423 </div>
424 <p>
425 <span class="bold"><strong>Recno</strong></span>
426 </p>
427 <p>
428 The following flags may be specified for the Recno access method:
429 </p>
430 <div class="itemizedlist">
431 <ul type="disc">
432 <li>
433 <p><a id="dbset_flags_DB_RENUMBER"></a>
434 <code class="literal">DB_RENUMBER</code>
435 </p>
436 <p>
437 Specifying the DB_RENUMBER flag causes the logical record numbers to
438 be mutable, and change as records are added to and deleted from the
439 database.
440 </p>
441 <p>
442 Using the <a class="xref" href="dbput.html" title="Db::put()">Db::put()</a> or
443 <a class="xref" href="dbcput.html" title="Dbc::put()">Dbc::put()</a> interfaces
444 to create new records will cause the creation of multiple records if
445 the record number is more than one greater than the largest record
446 currently in the database. For example, creating record 28, when
447 record 25 was previously the last record in the database, will create
448 records 26 and 27 as well as 28. Attempts to retrieve records that
449 were created in this manner will result in an error return of <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_KEYEMPTY" class="olink">DB_KEYEMPTY</a>.
450 </p>
451 <p>
452 If a created record is not at the end of the database, all records
453 following the new record will be automatically renumbered upward by
454 one. For example, the creation of a new record numbered 8 causes
455 records numbered 8 and greater to be renumbered upward by one. If a
456 cursor was positioned to record number 8 or greater before the
457 insertion, it will be shifted upward one logical record, continuing to
458 refer to the same record as it did before.
459 </p>
460 <p>
461 If a deleted record is not at the end of the database, all records
462 following the removed record will be automatically renumbered downward
463 by one. For example, deleting the record numbered 8 causes records
464 numbered 9 and greater to be renumbered downward by one. If a
465 cursor was positioned to record number 9 or greater before the
466 removal, it will be shifted downward one logical record, continuing to
467 refer to the same record as it did before.
468 </p>
469 <p>
470 If a record is deleted, all cursors that were positioned on that record
471 prior to the removal will no longer be positioned on a valid entry.
472 This includes cursors used to delete an item. For example, if
473 a cursor was positioned to record number 8 before the removal of
474 that record, subsequent calls to <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a>
475 with flags of DB_CURRENT will result in an error return of
476 <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_KEYEMPTY" class="olink">DB_KEYEMPTY</a>
477 until the cursor is moved to another record. A call to
478 <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a> with flags of DB_NEXT
479 will return the new record numbered 8 - which is the record that was
480 numbered 9 prior to the delete (if such a record existed).
481 </p>
482 <p>
483 For these reasons, concurrent access to a Recno database with the
484 DB_RENUMBER flag specified may be largely meaningless, although it is
485 supported.
486 </p>
487 <p>
488 Calling <code class="methodname">Db::set_flags()</code> with the DB_RENUMBER flag affects the
489 database, including all threads of control accessing the database.
490 </p>
491 <p>
492 If the database already exists when <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a>
493 is called, the DB_RENUMBER flag must be the same as the existing database or an error
494 will be returned.
495 </p>
496 </li>
497 <li>
498 <p><a id="dbset_flags_DB_SNAPSHOT"></a>
499 <code class="literal">DB_SNAPSHOT</code>
500 </p>
501 <p>
502 This flag specifies that any specified <span class="bold"><strong>re_source</strong></span> file be read in its entirety when
503 <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> is called. If
504 this flag is not specified, the <span class="bold"><strong>re_source</strong></span> file may be read lazily.
505 </p>
506 <p>
507 See the <a class="xref" href="dbset_re_source.html" title="Db::set_re_source()">Db::set_re_source()</a>
508 method for information on the <span class="bold"><strong>re_source</strong></span> file.
509 </p>
510 <p>
511 Calling <code class="methodname">Db::set_flags()</code> with the DB_SNAPSHOT flag only affects the
512 specified <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a> handle (and
513 any other Berkeley DB handles opened within the scope of that handle).
514 </p>
515 </li>
516 </ul>
517 </div>
518 </div>
519 </div>
520 <div class="sect2" lang="en" xml:lang="en">
521 <div class="titlepage">
522 <div>
523 <div>
524 <h3 class="title"><a id="idp3305048"></a>Errors</h3>
525 </div>
526 </div>
527 </div>
528 <p>
529 The <code class="methodname">Db::set_flags()</code> <span>
530
531 <span>
532 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a>
533 exception, encapsulating one of the following non-zero errors, or return one
534 of the following non-zero errors:
535 </span>
536 </span>
537 </p>
538 <div class="sect3" lang="en" xml:lang="en">
539 <div class="titlepage">
540 <div>
541 <div>
542 <h4 class="title"><a id="idm335808"></a>EINVAL</h4>
543 </div>
544 </div>
545 </div>
546 <p>
547 An invalid flag value or parameter was specified.
548 </p>
549 </div>
550 </div>
551 <div class="sect2" lang="en" xml:lang="en">
552 <div class="titlepage">
553 <div>
554 <div>
555 <h3 class="title"><a id="idp5592560"></a>Class</h3>
556 </div>
557 </div>
558 </div>
559 <p>
560 <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>
561 </p>
562 </div>
563 <div class="sect2" lang="en" xml:lang="en">
564 <div class="titlepage">
565 <div>
566 <div>
567 <h3 class="title"><a id="idp5587416"></a>See Also</h3>
568 </div>
569 </div>
570 </div>
571 <p>
572 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a>
573 </p>
574 </div>
575 </div>
576 <div class="navfooter">
577 <hr />
578 <table width="100%" summary="Navigation footer">
579 <tr>
580 <td width="40%" align="left"><a accesskey="p" href="dbset_feedback.html">Prev</a> </td>
581 <td width="20%" align="center">
582 <a accesskey="u" href="db.html">Up</a>
583 </td>
584 <td width="40%" align="right"> <a accesskey="n" href="dbset_h_compare.html">Next</a></td>
585 </tr>
586 <tr>
587 <td width="40%" align="left" valign="top">Db::set_feedback() </td>
588 <td width="20%" align="center">
589 <a accesskey="h" href="index.html">Home</a>
590 </td>
591 <td width="40%" align="right" valign="top"> Db::set_h_compare()</td>
592 </tr>
593 </table>
594 </div>
595 </body>
596 </html>