~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/docs/ref/am/curput.html

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!--$Id: curput.so,v 10.15 2001/05/19 14:51:30 bostic Exp $-->
 
2
<!--Copyright 1997-2001 by Sleepycat Software, Inc.-->
 
3
<!--All rights reserved.-->
 
4
<html>
 
5
<head>
 
6
<title>Berkeley DB Reference Guide: Storing records with a cursor</title>
 
7
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
 
8
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
 
9
</head>
 
10
<body bgcolor=white>
 
11
<a name="2"><!--meow--></a><a name="3"><!--meow--></a>
 
12
<table width="100%"><tr valign=top>
 
13
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Access Methods</dl></h3></td>
 
14
<td align=right><a href="../../ref/am/curget.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/am/curdel.html"><img src="../../images/next.gif" alt="Next"></a>
 
15
</td></tr></table>
 
16
<p>
 
17
<h1 align=center>Storing records with a cursor</h1>
 
18
<p>The <a href="../../api_c/dbc_put.html">DBcursor-&gt;c_put</a> function is the standard interface for storing records into
 
19
the database with a cursor.  In general, <a href="../../api_c/dbc_put.html">DBcursor-&gt;c_put</a> takes a key and
 
20
inserts the associated data into the database, at a location controlled
 
21
by a specified flag.
 
22
<p>There are several flags that you can set to customize storage:
 
23
<p><dl compact>
 
24
<p><dt><a href="../../api_c/dbc_put.html#DB_AFTER">DB_AFTER</a><dd>Create a new record, immediately after the record to which the cursor
 
25
refers.
 
26
<p><dt><a href="../../api_c/dbc_put.html#DB_BEFORE">DB_BEFORE</a><dd>Create a new record, immediately before the record to which the cursor
 
27
refers.
 
28
<p><dt><a href="../../api_c/dbc_put.html#DB_CURRENT_PUT">DB_CURRENT</a><dd>Replace the data part of the record to which the cursor refers.
 
29
<p><dt><a href="../../api_c/dbc_put.html#DB_KEYFIRST">DB_KEYFIRST</a><dd>Create a new record as the first of the duplicate records for the
 
30
supplied key.
 
31
<p><dt><a href="../../api_c/dbc_put.html#DB_KEYLAST">DB_KEYLAST</a><dd>Create a new record, as the last of the duplicate records for the supplied
 
32
key.
 
33
</dl>
 
34
<p>In all cases, the cursor is repositioned by a <a href="../../api_c/dbc_put.html">DBcursor-&gt;c_put</a> operation
 
35
to point to the newly inserted key/data pair in the database.
 
36
<p>The following is a code example showing a cursor storing two data items
 
37
in a database that supports duplicate data items:
 
38
<p><blockquote><pre>int
 
39
store(dbp)
 
40
        DB *dbp;
 
41
{
 
42
        DBC *dbcp;
 
43
        DBT key, data;
 
44
        int ret;
 
45
<p>
 
46
        /*
 
47
         * The DB handle for a Btree database supporting duplicate data
 
48
         * items is the argument; acquire a cursor for the database.
 
49
         */
 
50
        if ((ret = dbp-&gt;cursor(dbp, NULL, &dbcp, 0)) != 0) {
 
51
                dbp-&gt;err(dbp, ret, "DB-&gt;cursor");
 
52
                goto err;
 
53
        }
 
54
<p>
 
55
        /* Initialize the key. */
 
56
        memset(&key, 0, sizeof(key));
 
57
        key.data = "new key";
 
58
        key.size = strlen(key.data) + 1;
 
59
<p>
 
60
        /* Initialize the data to be the first of two duplicate records. */
 
61
        memset(&data, 0, sizeof(data));
 
62
        data.data = "new key's data: entry #1";
 
63
        data.size = strlen(data.data) + 1;
 
64
<p>
 
65
        /* Store the first of the two duplicate records. */
 
66
        if ((ret = dbcp-&gt;c_put(dbcp, &key, &data, DB_KEYFIRST)) != 0)
 
67
                dbp-&gt;err(dbp, ret, "DB-&gt;cursor");
 
68
<p>
 
69
        /* Initialize the data to be the second of two duplicate records. */
 
70
        data.data = "new key's data: entry #2";
 
71
        data.size = strlen(data.data) + 1;
 
72
<p>
 
73
        /*
 
74
         * Store the second of the two duplicate records.  No duplicate
 
75
         * record sort function has been specified, so we explicitly
 
76
         * store the record as the last of the duplicate set.
 
77
         */
 
78
        if ((ret = dbcp-&gt;c_put(dbcp, &key, &data, DB_KEYLAST)) != 0)
 
79
                dbp-&gt;err(dbp, ret, "DB-&gt;cursor");
 
80
<p>
 
81
err:    if ((ret = dbcp-&gt;c_close(dbcp)) != 0)
 
82
                dbp-&gt;err(dbp, ret, "DBcursor-&gt;close");
 
83
<p>
 
84
        return (0);
 
85
}</pre></blockquote>
 
86
<table width="100%"><tr><td><br></td><td align=right><a href="../../ref/am/curget.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/am/curdel.html"><img src="../../images/next.gif" alt="Next"></a>
 
87
</td></tr></table>
 
88
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>
 
89
</body>
 
90
</html>