Developer.com Logo Click here to support our advertisers
Click here to support our advertisers
SHOPPING
JOB BANK
CLASSIFIEDS
DIRECTORIES
REFERENCE
Online Library
LEARNING CENTER
JOURNAL
NEWS CENTRAL
DOWNLOADS
COMMUNITY
CALENDAR
ABOUT US

Journal:

Get the weekly email highlights from the most popular journal for developers!
Current issue
developer.com
developerdirect.com
htmlgoodies.com
javagoodies.com
jars.com
intranetjournal.com
javascripts.com

All Categories : Linux

developer.com - Reference
Developer.com Logo Click here to support our advertisers
Click here to support our advertisers
SHOPPING
JOB BANK
CLASSIFIEDS
DIRECTORIES
REFERENCE
Online Library
LEARNING CENTER
JOURNAL
NEWS CENTRAL
DOWNLOADS
COMMUNITY
CALENDAR
ABOUT US

Journal:

Get the weekly email highlights from the most popular journal for developers!
Current issue
developer.com
developerdirect.com
htmlgoodies.com
javagoodies.com
jars.com
intranetjournal.com
javascripts.com

Linux


- 66 -

Databases

IN THIS CHAPTER

  • What Is xBase?

  • What Is FlagShip?

  • Installing FlagShip

  • Using FlagShip

  • Porting Existing Applications

  • dbMan

  • LINCKS

  • Other Database Products


This chapter covers some common database applications for Linux. The applications we focus on primarily in this chapter are FlagShip and dbMan V. We also briefly look at LINCKS, a free object-oriented database management system (DBMS) for Linux.

About a decade ago, there was only one database system in widespread use, Ashton-Tate's dBASE. Before Windows came along, practically every database under DOS was written in dBASE. As UNIX developed on the small platforms, ports of the dBASE system emerged there too. Although the ownership of the dBASE package was transferred several times, a Windows-based version didn't appear fast enough (and wasn't stable enough) to keep the popularity of the dBASE system alive. Soon, other databases began to be used in place of dBASE.

Along with the development of faster and more powerful versions of dBASE, several companies introduced compatible products that extended the capabilities of the dBASE language. These products, written to the dBASE language set, were generically called xBase to show their ties to dBASE. A few of these xBase systems became very popular with programmers, in particular Clipper, a dBASE-compatible language compiler that accelerated the execution speed of dBASE applications enormously.

Although many programmers think of dBASE as a vintage database system now, there are still thousands (if not millions) of applications that were written using that relational database package. Many of these packages are still in use today, either in the same format as originally developed or ported to newer xBase versions and newer operating systems. Because it is unlikely that xBase languages and applications will ever go away, it is perhaps no surprise that an xBase port for Linux was introduced.

The company that offers FlagShip, the dBASE- and Clipper-compatible database system, offers versions for many operating systems, mostly UNIX based. Their Linux version is a commercial product, selling for about $199 in the United States. However, several FlagShip demo versions are available that expire after 10 or 30 days, allowing you to see whether your existing dBASE or Clipper applications will run under Linux. If they will, and if you want to move them over, you can then purchase a full copy of FlagShip.


NOTE: Because of copyright restrictions, we could not get a demo version of FlagShip on the CD-ROM accompanying this book. You can download the FlagShip demos from various Web sites, and you can find them through a search engine such as AltaVista (http://www.altavista.digital.com) or Yahoo! (http://www.yahoo.com), or directly from the vendor of FlagShip, Multisoft Datentechnik Gmbh, at http://www.fship.com. There is also an FTP server for the company at ftp://fship.com/pub/multisoft. The demo versions are quite large (about 4.5MB), so if you want to try FlagShip, you might want to find it on a sampler Linux CD-ROM to save connect time.

What Is xBase?

xBase is a generic term for various implementations of what was originally the dBASE programming language. The main players in the DOS version of this database are FoxPro (now owned by Microsoft), dBASE V (now owned by Borland), and Clipper (owned by Computer Associates).

xBase is a language that has statements normally found in programming languages, such as IF, ELSE, ENDIF, and WHILE. The programming language structure is designed for accessing records in databases and not for general-purpose programming. For example, the GOTO statement in xBase refers to a record in a database, not a location in the program code. xBase has some powerful statements for processing files and getting data from forms and screens.

In addition, setting up relations between files is easy with xBase. The names of all fields in a file, and their types and lengths, are recorded in the file header. New fields can be added to a file without changing programs that use the file. The scheme allows for having different, disjointed programs all accessing the database file in their own way and all using the fields in the header.

The three major manufacturers of xBase databases have largely ignored Linux as a platform for their products. What we have for Linux are FlagShip and dbMan (from Versasoft Corporation). Both of these products run on several implementations of UNIX.

Comparing the two products is like comparing apples and oranges. FlagShip is patterned after Clipper Version 5. The dbMan package resembles dBASE III+ or FoxPlus. FlagShip, like Clipper, is a compiler. dbMan is primarily an interpreter, although it is possible to "compile" dbMan programs. FlagShip is also an object-oriented language, which makes it philosophically different from dbMan, as well as from FoxPro and dBASE. Clipper and FlagShip have several C-like features. Actually, the resemblance is a plus for Linux users.

The target markets of the two products are also different. dbMan is targeted primarily at individual users. If you want a program you can run on your desk to keep track of time billed to clients or to maintain a phone list of customers or your sales record, dbMan can do the job.

By contrast, FlagShip might be overkill for simple database operations such as mailing or customer-tracking lists--in other words, for the casual user, not the programmer. This is not to say that you cannot use it for simple applications, but you might have to learn a bit of programming to really use FlagShip's powerful features. FlagShip is more realistically aimed at people who want to develop or port software packages. Traditionally, dBASE files always have separate data (.DBF) and index files. The format of data files is pretty much uniform for all xBases. It is hard to find two products that use the same index file formats, but you can use the same .DBF files with both FlagShip and dbMan.

What Is FlagShip?

FlagShip is a compiler, meaning it produces executable code with no intermediary pseudo-code. There is no interpretive version of FlagShip, so you might need an interpreter such as FoxPro or dBASE to develop complex applications. FlagShip was designed to allow existing xBase applications to run without modification (or a minimum of modification, in some cases, to correct filename problems) under Linux and other UNIX versions. There are no runtime or user royalty fees, so after an application has been developed and compiled, it can be distributed anywhere without royalties being paid to the authors.


NOTE: Several documents are available for FlagShip from FTP and Web sites. Take care to download the English files, because most sites have both English and German documents available (the company that offers FlagShip is based in Germany).

FlagShip is fully compatible with dBASE and Clipper, as well as most other xBase versions, such as Fox, FoxPlus, FoxPro, dbMan, and QuickSilver. It includes all the really neat features of the xBase compatibles, such as these:

  • Macro support

  • Arrays, objects, and code blocks

  • User-defined functions and user-defined commands

  • Index and array sorts

  • Compatibility with most xBase file formats, including .dbf, .dbt, .mem, .lbl, .frm, and .fmt


  • A C API for interfacing C code and FlagShip code in one application

FlagShip has no equivalent of the dBASE dot prompt or interactive command interface found in other xBase products. There is, however, a public-domain program called dbu that provides the capability to create files and indexes; add, change, or locate records; and browse files interactively. dbu is available from several sites on the Web (use AltaVista or another search engine to locate current sites).

FlagShip uses the curses toolkit for its user interface. During installation, you get a set of terminfo files specifically for FlagShip. When running a FlagShip program in an xterm, you might get hieroglyphics rather than line-drawing characters. Fiddling with the acsc parameter in the fslinxterm terminfo entry might not help. Try using the vga font that comes with the DOSemu package.

FlagShip doesn't have a function specifically for managing pull-down menus. FlagShip and Clipper programmers normally use @PROMPT/MENU TO statements to create the horizontal menu, and use a function called ACHOICE() for the vertical menus. You can set hot keys with the statement SET KEY keyid TO statement. Normally, the statement would be a function invocation. Within this function, you can call the function READVAR() to find out which field the cursor was in when the key was pressed. An input field can be validated by the addition of the VALID statement parameter to the @SAY/GET statement. Again, the statement would normally be a function invocation. Within the function, the value the user typed could be looked up in a database file.

FlagShip has functions for managing windows that work very nicely, but the functions are not part of the basic package. You have to buy the FStools library. As the name suggests, the FStools library is a clone of the Clipper Tools library. There are also windowing functions in the NanForum library (containing mathematical and statistics functions), which is public domain.

A key feature of FlagShip is the TBROWSE() object. You use this in place of the BROWSE command that exists in other languages. If you don't have any previous experience with object-oriented programming, setting up TBROWSE() for the first time is not easy. The best course of action is to use the examples and samples in the fsman pages. FlagShip is picky about reserved words. If you have a filename such as browse, you are likely to run into problems running programs. Keep a list of all the reserved words in FlagShip, and avoid using these as file or program names. Check the list of reserved words in the fsman pages.

FlagShip programs can be attached to WWW pages. This makes it possible for Net surfers to access and update databases. This feature, plus the capability to link in your C and C++ programs, makes FlagShip a very powerful data management tool.

FlagShip has an online reference program called fsman. fsman contains the entire FlagShip manual of more than 1000 pages. This means that you won't have thick manuals all over your desk. The samples of code in the manual can be saved as text files on disk. This makes it easy to incorporate programming examples in the manual into whatever program you are working on. Of course, you could also use the mouse to copy text from fsman into your program by cutting and pasting between windows.

FlagShip isn't just a port of a DOS-based compiler. It has been designed to provide full functionality under UNIX. Source code runs faster under Linux than under DOS (compiler with Clipper, for example) because of the better operating system design of Linux. FlagShip also removes many of the limitations of DOS- and Windows-based xBase applications.

If you have any requirement to port dBASE or Clipper applications to Linux, or if you are looking for a simple relational database system, FlagShip is an excellent choice.

Installing FlagShip

Most people obtain FlagShip from a CD-ROM collection, a Web site, or an FTP archive. In most cases, two versions of FlagShip will be available, and the choice of the correct one for your system depends on the version of Linux you are running. Typically, the files are contained in a tar archive called fsdemo.tar (if you are obtaining the restricted demo version). One version is optimized for more recent releases of Linux and uses ELF. An older version, usually designated with the name aout (for a.out) at the end of the filename, works on any Linux system. The ELF version is much more flexible and powerful, but in most cases the demo files are the older version.

After you have the fsdemo.tar file on your Linux system in a suitable (preferably new and empty other than the fsdemo file) directory, you need to unpack the tar file with this command:

tar xvf fsdemo.tar

This command creates several files, two of which are usually called FSinstall.set and FSinstall. The FSinstall.set file sets environment variables for the installation routine. You should run it first by typing its name at the command line. You won't see anything when you do this. After running the .set file, type the FSinstall filename and let it install FlagShip for you.

If the installation process loads properly, you will probably be asked whether there is enough room on your file system, as shown in Figure 66.1.

FIGURE 66.1. The FlagShip installation routine checks whether you have enough room on your hard drive.

You are asked where you want to FlagShip program to be stored, and you should in most cases accept the default values suggested by the installation routine. If you want to change the defaults, a menu prompt lets you do so and then enter the new values, as shown in Figure 66.2. After the installation routine has finished, you are returned to the shell prompt. FlagShip is now ready to be used.

FIGURE 66.2. You can override the default FlagShip installation settings if you want to.

Using FlagShip

If you have used Clipper or one of the other xBase compilers, you will know most of the commands you need for FlagShip. A few modifications have been made because of the UNIX environment, but otherwise, using FlagShip is pretty simple. Keep in mind that FlagShip is not an interactive development product: it doesn't help you design your code. FlagShip is a compiler. You can use it to develop applications if you are familiar with the dBASE language, but FlagShip is not designed to teach you dBASE, or to help you develop applications.

After you have your .prg source files ready to go, you can invoke the FlagShip compiler. In general, the command line looks like

FlagShip app_name.prg -ocompiled_name -Mstart

where app_name.prg is the name of the main program file (which calls all the others) and compiled_name is the name of the compiled executable (C defaults to a.out as the compiled executable name). If your main program file doesn't call all the other program files that need to be linked together, you will have to compile them separately and link them together.

When compiled, the application runs as though it were on DOS or any other operating system. For example, Figure 66.3 shows a DOS application that has been ported to Linux and recompiled with FlagShip, then executed. The only changes necessary to the source code were changes in path names from DOS's structure to Linux's. As you can see, even the fundamental ASCII graphics are retained and can be used on any terminal supported by Linux.

FIGURE 66.3. A FlagShip-compiled application runs under Linux just as it would under DOS.

Porting Existing Applications

What do you have to worry about if you have some existing dBASE or Clipper code you want to run under Linux? To start with, you need the .prg (program) source code. Move those files to Linux using any means you want, such as a network connection or floppy disk. FlagShip is clever enough to ignore case, which might seem trivial but isn't. Because most DOS programmers write in mixed case, converting applications to run under UNIX's case-significant environment is a major problem with other dBASE tools.

Complete instructions on modifying code to run cleanly under FlagShip are included with the software (or available through the FlagShip Web page), but essentially, most applications can run straightaway.

FlagShip converts dBASE code into C source code and then compiles it with a C compiler. That means you need a C compiler, which luckily is part of almost every UNIX and Linux system available. If you want to use FlagShip and haven't installed the C development system from the CD-ROM, you should do so; otherwise, you will see error messages from FlagShip. You don't need C++, only the standard C compilers that are on the CD-ROM (including the one at the back of this book). The procedure FlagShip goes through to run an application is straightforward:

1. Preprocesses the code to ensure that no syntax errors or other common errors are present. If there are errors, it issues error messages and terminates the compilation.

2.
Converts to C code.

3.
Compiles with the system's C compiler to produce an object file.

4.
Links the object file with FlagShip's libraries and produces an executable.

The executable thus produced can be run at the Linux command-line prompt.

A quick word for dBASE and Clipper veterans: You needn't bother with overlays, because UNIX has no need of them. Linux uses the virtual memory on your system to allow you to load any size application (although there are limits, they can be changed). Therefore, don't bother with overlays as you would with Clipper or other xBase compilers, and instead link your code into a single, large executable. Let Linux worry about loading it.

dbMan

The dbMan program is an interpreter. When you start dbMan, you get a CMD: prompt. This is where you enter all your commands to dbMan. You can think of this as a . prompt in dBASE. For starters, you can type ASSIST at the CMD: prompt. ASSIST starts a menu-driven interface similar to those available with FoxPro or dBASE.

The menu-driven interface is not very elaborate. ASSIST enables only one file to be open at a time. This means that it is not possible to set up relations. It is possible to start a simple program generator from ASSIST. Again, it has a single-file limitation.

You can compile programs in dbMan. Compiling a program does not produce an executable binary. It produces a .run file, which still requires dbMan to execute it. It is also possible to enter CREATE REPORT or MODIFY REPORT at the CMD: prompt. This puts you in dbMan's report writer. The report writer enables display of data by using the relational operators. dbMan provides a function called PMENU() to create pull-down menus. PMENU doesn't have any mechanism for temporarily disabling a menu choice.

dbMan handles windows differently from other xBase products. Before defining a window, you call PUSHWIND() to push the current window onto a stack. When a program is in its initial state, the entire screen is considered to be a window. You then call WINDOW() to create the window. When you are finished with it, you call POPWIND(), which removes the window and makes the previous window active.

dbMan enables you to define only one hot key. You do so by invoking the ONKEY() function. This has no effect until you execute the ON KEY statement. The statement normally is DO hot-key-handler.

The BROWSE command has a long list of options. You can browse only specified fields, and you can specify the width of each field and whether it is editable. The list of fields can include fields in other files, which is great if you have relationships set up.

dbMan does not use either termcap or terminfo. Instead, it includes a file named dbmterm.dbm. This file looks similar to termcap. There are no entries for either xterm or console. You have to create your own entries using the existing entries.

dbMan has no facility for executing functions written in C or assembler, so you have to use what they offer. A couple of nasty bugs were in the version of dbMan I evaluated, which was version 5.32. The main bug I found was that procedure files simply didn't work if the procedure file was a .prg. When I compiled the procedure file into a .run file, it worked OK.


NOTE: You can get dbMan from the following source: VERSASOFT Corp. 4340 Alamaden Expressway, #110 San Jose, CA 95118 (408) 268-8396

LINCKS

LINCKS is an object-oriented database management system. LINCKS is a good system if you intend to use it on a network and share data via RPC calls. You need to have some experience with networks, as well as an existing network, to fully benefit from this package. This package is not for a single-node system just because it would be overkill for such a platform.


NOTE: You can get LINCKS from sunsite.unc.edu in the /pub/linux/apps/database/lincks directory.

LINCKS is based on an append-only object-oriented structure. Objects are derived from other objects. Links can be set between objects to define relationships. You define views to an object. A view is used to specify how the data in the object is presented to a user. Multiple views can exist for the same object. Views can be inherited.

The main interface is the xlincks program. Using commands similar to those in emacs, you can interactively browse through databases. The interface resembles the hypertext functions of a Web page. You click on a highlighted item, and the program leads to a page with more information about the topic.

Help is available in two forms: context sensitive or as a browsable database. The help file is always a button away--to access help, simply press the Help button. The contents of the help file are well organized and are a good starting place to learn about LINCKS. The manual is also available in PostScript for the sunsite archives.

LINCKS comes with a few programs in its distribution package. You can create new databases using the dbroot command. To prune databases of unreferenced objects, use the cutoff command. The main server for the application is the netserv program, which fires off a dbs process for each connected client.

Other Database Products

Of course, the xBase tools we've looked at are not the only databases available for Linux. Many non-dBASE-compatible tools are out there. Following is a quick overview of some other database management systems for Linux. Most of these are free and can be found on the Internet. mbase v5.0 is a relational database system originally written for the Amiga and ported to other platforms. It uses a language format similar to C to do the database programming. To compile using mbase, you need ncurses and time. There are several problems with the makefile that might require manual editing on your part. If you really want cheap, C-like access to a DBMS, you can use this package. Otherwise, get FlagShip or dbMan because they are more stable and mature.

onyx is a database prototype program based on a language format like C. The make config command starts the process, and a series of questions pops up. Answering all these questions results in configuring the database properly for Linux.

DBF is an xBase manipulation package and is a collection of utility programs that manipulate .dbf files. Some of the utilities, such as dbfadd, add a record or layer of information in the database. dbflist lists the records in the database, and dbft lists the structure of each database and its items.

typhoon is yet another RDBMS. The most notable feature of this RDBMS (depending on your point of view) is that it's entirely like C. The problem is that the product still has to mature before being considered a viable RDBMS.

Summary

FlagShip and dbMan are excellent means of porting existing dBASE and dBASE-compatible programs to Linux, where they run without modification in most cases, and a lot faster in almost all cases. A version of FlagShip is being developed for X to run under XFree86 or other Linux-based X versions, and that should be available in 1997. For now, though, the demo version of FlagShip lets xBase developers continue to work with their database system under Linux. The commercial product, with its hefty documentation, is $199 and well worth it for developers. dbMan is a logical alternative for those who don't need FlagShip's compiler features and extended capabilities. Ruler image
Contact
[email protected] with questions or comments.
Copyright 1998 EarthWeb Inc., All rights reserved.
PLEASE READ THE ACCEPTABLE USAGE STATEMENT.
Copyright 1998 Macmillan Computer Publishing. All rights reserved.

Click here for more info

Click here for more info