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">
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Secondary Indices with Transaction Applications</title>
7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9 <link rel="start" href="index.html" title="Getting Started with Berkeley DB Transaction Processing" />
10 <link rel="up" href="usingtxns.html" title="Chapter 3. Transaction Basics" />
11 <link rel="prev" href="txncursor.html" title="Transactional Cursors" />
12 <link rel="next" href="maxtxns.html" title="Configuring the Transaction Subsystem" />
15 <div xmlns="" class="navheader">
17 <p>Library Version 11.2.5.3</p>
19 <table width="100%" summary="Navigation header">
21 <th colspan="3" align="center">Secondary Indices with Transaction Applications</th>
24 <td width="20%" align="left"><a accesskey="p" href="txncursor.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 3. Transaction Basics</th>
26 <td width="20%" align="right"> <a accesskey="n" href="maxtxns.html">Next</a></td>
31 <div class="sect1" lang="en" xml:lang="en">
32 <div class="titlepage">
35 <h2 class="title" style="clear: both"><a id="txnindices"></a>Secondary Indices with Transaction Applications</h2>
40 You can use transactions with your secondary indices so long as you
43 open the secondary index so that it supports transactions (that is,
44 you wrap the database open in a transaction, or use auto commit,
45 in the same way as when you open a primary transactional database).
51 In addition, you must make sure that when you associate the
52 secondary index with the primary database, the association is
53 performed using a transaction. The easiest thing to do here is
54 to simply specify <code class="literal">DB_AUTO_COMMIT</code> when you
55 perform the association.
59 All other aspects of using secondary indices with transactions are
60 identical to using secondary indices without transactions. In
61 addition, transaction-protecting
63 cursors opened against secondary indices is performed in
64 exactly the same way as when you use transactional cursors
65 against a primary database.
68 See <a class="xref" href="txncursor.html" title="Transactional Cursors">Transactional Cursors</a> for details.
71 Note that when you use transactions to protect your database writes, your secondary indices are protected from
72 corruption because updates to the primary and the secondaries are performed in a single atomic transaction.
77 <pre class="programlisting">#include <db_cxx.h>
81 // Environment and primary database open omitted
84 Db my_index(&envp, 0); // Secondary
87 my_index.open(NULL, // Transaction pointer
88 "my_secondary.db", // On-disk file that holds the database.
89 NULL, // Optional logical database name
90 DB_BTREE, // Database access method
91 DB_AUTO_COMMIT, // Open flags.
92 0); // File mode (using defaults)
94 // Now associate the primary and the secondary
95 my_database.associate(NULL, // Txn id
96 &my_index, // Associated secondary database
97 get_sales_rep, // Callback used for key
98 // extraction. This is described
99 // in the Getting Started guide.
100 DB_AUTO_COMMIT); // Flags </pre>
102 <div class="navfooter">
104 <table width="100%" summary="Navigation footer">
106 <td width="40%" align="left"><a accesskey="p" href="txncursor.html">Prev</a> </td>
107 <td width="20%" align="center">
108 <a accesskey="u" href="usingtxns.html">Up</a>
110 <td width="40%" align="right"> <a accesskey="n" href="maxtxns.html">Next</a></td>
113 <td width="40%" align="left" valign="top">Transactional Cursors </td>
114 <td width="20%" align="center">
115 <a accesskey="h" href="index.html">Home</a>
117 <td width="40%" align="right" valign="top"> Configuring the Transaction Subsystem</td>