intro.html   [plain text]


<!--$Id: intro.so,v 11.25 2006/06/06 17:21:17 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Loading Berkeley DB with Tcl</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>
<table width="100%"><tr valign=top>
<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Tcl API</dl></b></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>
</td></tr></table>
<p align=center><b>Loading Berkeley DB with Tcl</b></p>
<p>Berkeley DB includes a dynamically loadable Tcl API, which requires that
Tcl/Tk 8.4 or later already be installed on your system.  You can
download a copy of Tcl from the <a href="http://www.tcl.tk">Tcl
Developer Xchange</a> Web site.</p>
<p>This document assumes that you already configured Berkeley DB for Tcl
support, and you have built and installed everything where you want it
to be.  If you have not done so, see
<a href="../../ref/build_unix/conf.html">Configuring Berkeley DB</a> or
<a href="../../ref/build_win/intro.html">Building for Windows</a> for more
information.</p>
<b>Installing as a Tcl Package</b>
<p>Once enabled, the Berkeley DB shared library for Tcl is automatically installed
as part of the standard installation process.  However, if you want to be
able to dynamically load it as a Tcl package into your script, there are
several steps that must be performed:</p>
<ol>
<p><li>Run the Tcl shell in the install directory.
<li>Append this directory to your auto_path variable.
<li>Run the pkg_mkIndex proc, giving the name of the Berkeley DB Tcl library.
</ol>
<p>For example:</p>
<blockquote><pre># tclsh8.4
% lappend auto_path /usr/local/BerkeleyDB.4.7/lib
% pkg_mkIndex /usr/local/BerkeleyDB.4.7/lib libdb_tcl-4.7.so</pre></blockquote>
<p>Note that your Tcl and Berkeley DB version numbers may differ from the
example, and so your tclsh and library names may be different.</p>
<b>Loading Berkeley DB with Tcl</b>
<p>The Berkeley DB package may be loaded into the user's interactive Tcl script
(or wish session) via the <b>load</b> command. For example:</p>
<blockquote><pre>load /usr/local/BerkeleyDB.4.7/lib/libdb_tcl-4.7.so</pre></blockquote>
<p>Note that your Berkeley DB version numbers may differ from the example, and so
the library name may be different.</p>
<p>If you installed your library to run as a Tcl package, Tcl application
scripts should use the <b>package</b> command to indicate to the Tcl
interpreter that it needs the Berkeley DB package and where to find it. For
example:</p>
<blockquote><pre>lappend auto_path "/usr/local/BerkeleyDB.4.7/lib"
package require Db_tcl</pre></blockquote>
<p>No matter which way the library gets loaded, it creates a command named
<b>berkdb</b>.  All the Berkeley DB functionality is accessed via this
command and additional commands it creates on behalf of the application.
A simple test to determine whether everything is loaded and ready is to
display the library version, as follows:</p>
<blockquote><pre>berkdb version -string</pre></blockquote>
<p>This should return you the Berkeley DB version in a string format.</p>
<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>
</td></tr></table>
<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
</body>
</html>