~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/docs/ref/simple_tut/del.html

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!--$Id$-->
2
 
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
3
 
<!--All rights reserved.-->
4
 
<!--See the file LICENSE for redistribution information.-->
5
 
<html>
6
 
<head>
7
 
<title>Berkeley DB Reference Guide: Removing elements from a database</title>
8
 
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
9
 
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
10
 
</head>
11
 
<body bgcolor=white>
12
 
<table width="100%"><tr valign=top>
13
 
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Simple Tutorial</dl></h3></td>
14
 
<td align=right><a href="../../ref/simple_tut/get.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/simple_tut/close.html"><img src="../../images/next.gif" alt="Next"></a>
15
 
</td></tr></table>
16
 
<p>
17
 
<h1 align=center>Removing elements from a database</h1>
18
 
<p>The simplest way to remove elements from a database is the <a href="../../api_c/db_del.html">DB-&gt;del</a>
19
 
interface.
20
 
<p>The <a href="../../api_c/db_del.html">DB-&gt;del</a> interface takes four of the same five arguments that
21
 
the <a href="../../api_c/db_get.html">DB-&gt;get</a> and <a href="../../api_c/db_put.html">DB-&gt;put</a> interfaces take.  The difference
22
 
is that there is no need to specify a data item, as the delete operation
23
 
is only interested in the key that you want to remove.
24
 
<p><dl compact>
25
 
<p><dt>db<dd>The database handle returned by <a href="../../api_c/db_create.html">db_create</a>.
26
 
<p><dt>txnid<dd>A transaction ID.
27
 
In our simple case, we aren't expecting to recover the database after
28
 
application or system crash, so we aren't using transactions, and will
29
 
leave this argument unspecified.
30
 
<p><dt>key<dd>The key item for the key/data pair that we want to delete from the
31
 
database.
32
 
<p><dt>flags<dd>Optional flags modifying the underlying behavior of the <a href="../../api_c/db_del.html">DB-&gt;del</a>
33
 
interface.  There are currently no available flags for this interface,
34
 
so the flags argument should always be set to 0.
35
 
</dl>
36
 
<p>Here's what the code to call <a href="../../api_c/db_del.html">DB-&gt;del</a> looks like:
37
 
<p><blockquote><pre>#include &lt;sys/types.h&gt;
38
 
#include &lt;stdio.h&gt;
39
 
#include &lt;db.h&gt;
40
 
<p>
41
 
#define DATABASE "access.db"
42
 
<p>
43
 
int
44
 
main()
45
 
{
46
 
        DB *dbp;
47
 
        DBT key, data;
48
 
        int ret;
49
 
<p>
50
 
        if ((ret = db_create(&dbp, NULL, 0)) != 0) {
51
 
                fprintf(stderr, "db_create: %s\n", db_strerror(ret));
52
 
                exit (1);
53
 
        }
54
 
        if ((ret = dbp-&gt;open(dbp,
55
 
            NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
56
 
                dbp-&gt;err(dbp, ret, "%s", DATABASE);
57
 
                goto err;
58
 
        }
59
 
<p>
60
 
        memset(&key, 0, sizeof(key));
61
 
        memset(&data, 0, sizeof(data));
62
 
        key.data = "fruit";
63
 
        key.size = sizeof("fruit");
64
 
        data.data = "apple";
65
 
        data.size = sizeof("apple");
66
 
<p>
67
 
        if ((ret = dbp-&gt;put(dbp, NULL, &key, &data, 0)) == 0)
68
 
                printf("db: %s: key stored.\n", (char *)key.data);
69
 
        else {
70
 
                dbp-&gt;err(dbp, ret, "DB-&gt;put");
71
 
                goto err;
72
 
        }
73
 
<p>
74
 
        if ((ret = dbp-&gt;get(dbp, NULL, &key, &data, 0)) == 0)
75
 
                printf("db: %s: key retrieved: data was %s.\n",
76
 
                    (char *)key.data, (char *)data.data);
77
 
        else {
78
 
                dbp-&gt;err(dbp, ret, "DB-&gt;get");
79
 
                goto err;
80
 
        }
81
 
<p><b>  if ((ret = dbp-&gt;del(dbp, NULL, &key, 0)) == 0)
82
 
                printf("db: %s: key was deleted.\n", (char *)key.data);
83
 
        else {
84
 
                dbp-&gt;err(dbp, ret, "DB-&gt;del");
85
 
                goto err;
86
 
        }
87
 
</b></pre></blockquote>
88
 
<p>After the <a href="../../api_c/db_del.html">DB-&gt;del</a> call returns, the entry to which the key
89
 
<b>fruit</b> refers has been removed from the database.
90
 
<table width="100%"><tr><td><br></td><td align=right><a href="../../ref/simple_tut/get.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/simple_tut/close.html"><img src="../../images/next.gif" alt="Next"></a>
91
 
</td></tr></table>
92
 
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>
93
 
</body>
94
 
</html>