old-www/LDP/LG/issue33/kunkel.html

167 lines
7.1 KiB
HTML

<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<title>Using the Xbase DBMS in a Linux Environment LG #33</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#A000A0"
ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Using the Xbase DBMS in a Linux Environment</font></H1>
<H4>By <a href="mailto:gkunkel@startech.keller.tx.us">Gary Kunkel</a></H4>
</center>
<P> <HR> <P>
<H4>Introduction</H4>
<P>
The Xbase file structure has been around quite a while and was one of the first
widely available DBMS tools for micro computers. It has become a de-facto
industry standard for text based databases and is supported by many vendors to
include the Borland Database Engine, Microsoft's FoxPro, Clipper, Sequitor's
Codebase and others. Xbase type datafiles will be with us for a while.
<P>
The Startech Web Server at http://www.startech.keller.tx.us/xbase/xbase.html
maintains a public domain, open source C++ library for accessing Xbase
type datafiles in a multi-user environment. The library supports automatic
record locking, memo fields (both dBase III and IV versions), and .NDX style
indices. There is also an API for interfacing the library to an Apache
Web Server and providing database access to web pages. Several example programs
provide a framework for creating, browsing and updating databases. There
are examples which demonstrate how to use the library with an Apache Web Server
and using the library in conjunction with the wxWindows library. Some readers
of this article will recognize the wxWindows library as a cross platform
GUI C++ library.
<P><HR> <P>
<H4>System Requirements</H4>
<P>
In order to use the Xbase DBMS library, you'll need to have a C/C++ compiler. The original
library was built on a Slackware distribution with the GNU public domain compiler, but
there are examples on the site for using the library on other platforms including
Windows, SUN, and VMS.
<P><HR> <P>
<H4>Getting Sources</H4>
<P>
To downloading the library sources, point your web browser to
http://www.startech.keller.tx.us/xbase/xbase.html and select the latest
version, which at the time of this writing is version 1.7.4 dated 6/18/98.
There are a couple of flavors available, but for the purpose of this article,
download the UNIX tar version. Also, you may want to grab the HTML
documentation for using the library at the same time. Alternatively, you
can get the software via ftp ftp.startech.keller.tx.us and retrieve the
software from the pub/xbase directory.
<P><HR> <P>
<H4>Installing Sources</H4>
<P>
To install the Xbase library under the /usr/local directory, execute the
following commands: cd /usr/local and mkdir xbase. The next step is to
set up access rights to the Xbase directory tree. Your site may have specific
protocols on directory access rights which you may need to address at this
point. If not, then the commands "chown YOURUSERID.users xbase", then
"chmod 775 xbase" will get you going.
<P>
Now create a source directory and copy the source code into it: "cd xbase",
"mkdir src", "cp /home/of/xbase.tar.gz /usr/local/xbase/src", "cd
/usr/local/xbase/src", "gunzip xbase.tar.gz" and lastly "tar -xvf
xbase.tar". At this point the Xbase source code should be in the
/usr/local/xbase/src directory and be ready to build the library.
<P><HR> <P>
<H4>Building the Library</H4>
<P>
Before building the library, review the options.h file. This file contains
any of the Xbase configuration switches you may want or need to change
depending on what you are trying to do. To build a DLL library, type
"make dll". To build a static library, type "make all".
<P>
It should compile cleanly. Errors at this point can often be traced to
the .h header files currently in use at your site. If you run into errors at
this point, notify xbase@startech.keller.tx.us for help building the library.
<P><HR> <P>
<H4>Building a Sample Program</H4>
<P>
This sample program demonstrates a simple program which creates a sample
database and index.
<PRE>
/* sample1.cpp */
#include "xbase.h"
main()
{
Schema MyRecord[] =
{
{ "FIRSTNAME", CHAR_FLD, 15, 0 },
{ "LASTNAME", CHAR_FLD, 20, 0 },
{ "BIRTHDATE", DATE_FLD, 8, 0 },
{ "AMOUNT", NUMERIC_FLD, 9, 2 },
{ "SWITCH", LOGICAL_FLD, 1, 0 },
{ "FLOAT1", FLOAT_FLD, 9, 2 },
{ 0,0,0,0 }
};
/* define the classes */
XBASE x; /* initialize xbase */
DBF MyFile( &x ); /* class for table */
NDX MyIndex( &MyFile ); /* class for index 1 */
SHORT rc; /* return code */
if(( rc = MyFile.CreateDatabase( "MYFILE.DBF", MyRecord, OVERLAY )) != NO_ERROR )
cout << "\nError creating database = " << rc << "\n";
else
{
/* define a simple index */
if(( rc = MyIndex1.CreateIndex(
"MYINDEX.NDX", "LASTNAME", 0, 1 )) != NO_ERROR )
cout << "\nError creating index 1 = " << rc << "\n";
}
MyFile.CloseDatabase(); /* Close database and associated indexes */
return 0;
}
</PRE>
Assuming you keyed the program source into directory /usr/local/xbase/myproj,
type "g++ -c -I/usr/include -I/usr/src/linux/include/asm-i386 -I../src
sample1.cpp" to compile the program and type "g++ -o sample1 sample1.o
../src/xbase.a" to link edit the program. The asm-i386 directory in the
above include line is for Linux running on the Intel
platform. Other platforsm require the correct include directory.
<P><HR> <P>
<H4>Conclusion</H4>
<P>
In conclusion, I'd like to say that although the Xbase library is not a 100%
complete Xbase solution, it is a stable and reliable library capable of
handling various database requirements. If you are looking for database
libraries in general, or need access to Xbase files in particular, give Xbase
DBMS a try. If you are a C programmer and new to C++ object oriented
programming, the Xbase DBMS is easy to learn and will help transition you to
the world of object oriented programming. If you have never programmed
in C or C++ before, this library should provide complete enough examples to
get you started programming in C/C++ with confidence.
<P>
<!--===================================================================-->
<P> <hr> <P>
<center><H5>Copyright &copy; 1998, Gary Kunkel <BR>
Published in Issue 33 of <i>Linux Gazette</i>, October 1998</H5></center>
<!--===================================================================-->
<P> <hr> <P>
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./defurne.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./johnson.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
<!--startcut ==========================================================-->
</BODY>
</HTML>
<!--endcut ============================================================-->