[go: up one dir, main page]

File: curput.html

package info (click to toggle)
db4.3 4.3.29-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 34,368 kB
  • ctags: 26,050
  • sloc: ansic: 111,720; tcl: 39,474; java: 29,503; perl: 11,771; sh: 11,295; cpp: 8,584; makefile: 1,769; awk: 1,312; cs: 457; xml: 114; php: 22; asm: 14
file content (90 lines) | stat: -rw-r--r-- 4,366 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!--$Id: curput.so,v 10.18 2003/10/18 19:15:52 bostic Exp $-->
<!--Copyright 1997-2004 by Sleepycat Software, Inc.-->
<!--All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Storing records with a cursor</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<a name="2"><!--meow--></a><a name="3"><!--meow--></a>
<table width="100%"><tr valign=top>
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Access Methods</dl></h3></td>
<td align=right><a href="../am/curget.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../am/curdel.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p>
<h3 align=center>Storing records with a cursor</h3>
<p>The <a href="../../api_c/dbc_put.html">DBcursor-&gt;c_put</a> method stores records into the database using a cursor.  In
general, <a href="../../api_c/dbc_put.html">DBcursor-&gt;c_put</a> takes a key and inserts the associated data
into the database, at a location controlled by a specified flag.</p>
<p>There are several flags that you can set to customize storage:</p>
<dl compact>
<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
refers.
<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
refers.
<dt><a href="../../api_c/dbc_get.html#DB_CURRENT">DB_CURRENT</a><dd>Replace the data part of the record to which the cursor refers.
<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
supplied key.
<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
key.
</dl>
<p>In all cases, the cursor is repositioned by a <a href="../../api_c/dbc_put.html">DBcursor-&gt;c_put</a> operation
to point to the newly inserted key/data pair in the database.</p>
<p>The following is a code example showing a cursor storing two data items
in a database that supports duplicate data items:</p>
<blockquote><pre>int
store(dbp)
	DB *dbp;
{
	DBC *dbcp;
	DBT key, data;
	int ret;
<p>
	/*
	 * The DB handle for a Btree database supporting duplicate data
	 * items is the argument; acquire a cursor for the database.
	 */
	if ((ret = dbp-&gt;cursor(dbp, NULL, &dbcp, 0)) != 0) {
		dbp-&gt;err(dbp, ret, "DB-&gt;cursor");
		goto err;
	}
<p>
	/* Initialize the key. */
	memset(&key, 0, sizeof(key));
	key.data = "new key";
	key.size = strlen(key.data) + 1;
<p>
	/* Initialize the data to be the first of two duplicate records. */
	memset(&data, 0, sizeof(data));
	data.data = "new key's data: entry #1";
	data.size = strlen(data.data) + 1;
<p>
	/* Store the first of the two duplicate records. */
	if ((ret = dbcp-&gt;c_put(dbcp, &key, &data, DB_KEYFIRST)) != 0)
		dbp-&gt;err(dbp, ret, "DB-&gt;cursor");
<p>
	/* Initialize the data to be the second of two duplicate records. */
	data.data = "new key's data: entry #2";
	data.size = strlen(data.data) + 1;
<p>
	/*
	 * Store the second of the two duplicate records.  No duplicate
	 * record sort function has been specified, so we explicitly
	 * store the record as the last of the duplicate set.
	 */
	if ((ret = dbcp-&gt;c_put(dbcp, &key, &data, DB_KEYLAST)) != 0)
		dbp-&gt;err(dbp, ret, "DB-&gt;cursor");
<p>
err:	if ((ret = dbcp-&gt;c_close(dbcp)) != 0)
		dbp-&gt;err(dbp, ret, "DBcursor-&gt;close");
<p>
	return (0);
}</pre></blockquote>
<table width="100%"><tr><td><br></td><td align=right><a href="../am/curget.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../am/curdel.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1><a href="../../sleepycat/legal.html">Copyright (c) 1996-2004</a> <a href="http://www.sleepycat.com">Sleepycat Software, Inc.</a> - All rights reserved.</font>
</body>
</html>