File: open.html

package info (click to toggle)
evolution-data-server 1.0.4-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 39,504 kB
  • ctags: 26,423
  • sloc: ansic: 175,347; tcl: 30,499; sh: 20,699; perl: 11,320; xml: 9,039; java: 7,653; cpp: 6,029; makefile: 4,866; awk: 1,338; yacc: 1,103; sed: 772; cs: 505; lex: 134; asm: 14
file content (66 lines) | stat: -rw-r--r-- 3,239 bytes parent folder | download | duplicates (3)
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
<!--$Id: open.html,v 1.1.1.1 2003/11/20 22:14:14 toshok Exp $-->
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
<!--All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Opening databases within the environment</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
</head>
<body bgcolor=white>
<table width="100%"><tr valign=top>
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Environment</dl></h3></td>
<td align=right><a href="../../ref/env/create.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/env/error.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p>
<h1 align=center>Opening databases within the environment</h1>
<p>Once the environment has been created, database handles may be created
and then opened within the environment.  This is done by calling the
<a href="../../api_c/db_create.html">db_create</a> interface and specifying the appropriate environment
as an argument.
<p>File naming, database operations, and error handling will all be done as
specified for the environment.  For example, if the <a href="../../api_c/env_open.html#DB_INIT_LOCK">DB_INIT_LOCK</a>
or <a href="../../api_c/env_open.html#DB_INIT_CDB">DB_INIT_CDB</a> flags were specified when the environment was
created or joined, database operations will automatically perform all
necessary locking operations for the application.
<p>The following is a simple example of opening two databases within a
database environment:
<p><blockquote><pre>	DB_ENV *dbenv;
	DB *dbp1, *dbp2;
	int ret;
</pre></blockquote>
<p><blockquote><pre>	/* Open an environment with just a memory pool. */
	if ((ret =
	    dbenv-&gt;open(dbenv, home, DB_CREATE | DB_INIT_MPOOL, 0)) != 0) {
		dbenv-&gt;err(dbenv, ret, "environment open: %s", home);
		return (ret);
	}
<p>
	/* Open database #1. */
	if ((ret = db_create(&dbp1, dbenv, 0)) != 0) {
		dbenv-&gt;err(dbenv, ret, "database create");
		return (ret);
	}
	if ((ret = dbp1-&gt;open(dbp1,
	    NULL, DATABASE1, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
		dbenv-&gt;err(dbenv, ret, "DB-&gt;open: %s", DATABASE1);
		return (ret);
	}
<p>
	/* Open database #2. */
	if ((ret = db_create(&dbp2, dbenv, 0)) != 0) {
		dbenv-&gt;err(dbenv, ret, "database create");
		return (ret);
	}
	if ((ret = dbp2-&gt;open(dbp2,
	    NULL, DATABASE2, NULL, DB_HASH, DB_CREATE, 0664)) != 0) {
		dbenv-&gt;err(dbenv, ret, "DB-&gt;open: %s", DATABASE2);
		return (ret);
	}
</pre></blockquote>
<table width="100%"><tr><td><br></td><td align=right><a href="../../ref/env/create.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/env/error.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>
</body>
</html>