1<!--$Id: intro.so,v 11.25 2006/06/06 17:21:17 bostic Exp $-->
2<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
3<!--See the file LICENSE for redistribution information.-->
4<html>
5<head>
6<title>Berkeley DB Reference Guide: Loading Berkeley DB with Tcl</title>
7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
8<meta name="keywords" content="embedded,database,programmatic,toolkit,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>
12<table width="100%"><tr valign=top>
13<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Tcl API</dl></b></td>
14<td align=right><a href="../rpc/faq.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../tcl/using.html"><img src="../../images/next.gif" alt="Next"></a>
15</td></tr></table>
16<p align=center><b>Loading Berkeley DB with Tcl</b></p>
17<p>Berkeley DB includes a dynamically loadable Tcl API, which requires that
18Tcl/Tk 8.4 or later already be installed on your system.  You can
19download a copy of Tcl from the <a href="http://www.tcl.tk">Tcl
20Developer Xchange</a> Web site.</p>
21<p>This document assumes that you already configured Berkeley DB for Tcl
22support, and you have built and installed everything where you want it
23to be.  If you have not done so, see
24<a href="../../ref/build_unix/conf.html">Configuring Berkeley DB</a> or
25<a href="../../ref/build_win/intro.html">Building for Windows</a> for more
26information.</p>
27<b>Installing as a Tcl Package</b>
28<p>Once enabled, the Berkeley DB shared library for Tcl is automatically installed
29as part of the standard installation process.  However, if you want to be
30able to dynamically load it as a Tcl package into your script, there are
31several steps that must be performed:</p>
32<ol>
33<p><li>Run the Tcl shell in the install directory.
34<li>Append this directory to your auto_path variable.
35<li>Run the pkg_mkIndex proc, giving the name of the Berkeley DB Tcl library.
36</ol>
37<p>For example:</p>
38<blockquote><pre># tclsh8.4
39% lappend auto_path /usr/local/BerkeleyDB.4.7/lib
40% pkg_mkIndex /usr/local/BerkeleyDB.4.7/lib libdb_tcl-4.7.so</pre></blockquote>
41<p>Note that your Tcl and Berkeley DB version numbers may differ from the
42example, and so your tclsh and library names may be different.</p>
43<b>Loading Berkeley DB with Tcl</b>
44<p>The Berkeley DB package may be loaded into the user's interactive Tcl script
45(or wish session) via the <b>load</b> command. For example:</p>
46<blockquote><pre>load /usr/local/BerkeleyDB.4.7/lib/libdb_tcl-4.7.so</pre></blockquote>
47<p>Note that your Berkeley DB version numbers may differ from the example, and so
48the library name may be different.</p>
49<p>If you installed your library to run as a Tcl package, Tcl application
50scripts should use the <b>package</b> command to indicate to the Tcl
51interpreter that it needs the Berkeley DB package and where to find it. For
52example:</p>
53<blockquote><pre>lappend auto_path "/usr/local/BerkeleyDB.4.7/lib"
54package require Db_tcl</pre></blockquote>
55<p>No matter which way the library gets loaded, it creates a command named
56<b>berkdb</b>.  All the Berkeley DB functionality is accessed via this
57command and additional commands it creates on behalf of the application.
58A simple test to determine whether everything is loaded and ready is to
59display the library version, as follows:</p>
60<blockquote><pre>berkdb version -string</pre></blockquote>
61<p>This should return you the Berkeley DB version in a string format.</p>
62<table width="100%"><tr><td><br></td><td align=right><a href="../rpc/faq.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../tcl/using.html"><img src="../../images/next.gif" alt="Next"></a>
63</td></tr></table>
64<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
65</body>
66</html>
67