From: Phil Perucci
Subject: Database in LISP?
Date: 
Message-ID: <2cddgl$cd5@universe.digex.net>
Has anyone written a simple database in LISP?  Seems like there
would have to be an easy way to keep a database in LISP.  I have
a small database in Microsoft ACCESS that I would really like
to move to LISP for 1) flexibility and 2) the ability to access
my data remotely via Unix.

The user interface (text based - just using a modem here) seems
like the tricky part.

-- 
==============================================================================
 Phil Perucci             | "All postings are my own opinion - all comments
 Systems Programmer       |  are intended for research/educational purposes"
==============================================================================
From: Michael Ernst
Subject: Re: Database in LISP?
Date: 
Message-ID: <MERNST.93Nov18113549@peacock.lcs.mit.edu>
In article <··········@universe.digex.net> ·····@universe.digex.net (Phil Perucci) writes:
> Has anyone written a simple database in LISP?

You might want to check out EDB, the Emacs database, which is written in
Emacs Lisp.  Version 1.18 is compatible with GNU Emacs versions 18 and 19,
and with Lucid Emacs 19.  I wrote EDB for exactly the reasons you cited:
other readily-available database packages don't provide sufficient
extensibility and customizability, nor do they use Emacs editing commands
or interoperate with other Emacs applications.

EDB is available for anonymous ftp from theory.lcs.mit.edu, directory
/pub/emacs/edb.  The package is in a single compressed tar file edb.tar.Z,
and the individual files can also be obtained from the code subdirectory.
Sample databases can be found in the compressed tar file examples.tar.Z or
in the examples subdirectory.  Theory.lcs.mit.edu also has a mail server
for those without ftp access; send email to
··············@theory.lcs.mit.edu with "help" or "index" in the *body*.
EDB also appears in the GNU Emacs Lisp Code Directory as
archive.cis.ohio-state.edu:/pub/gnu/emacs/elisp-archive/packages/edb.tar.Z.

I've included parts of the "Introduction" and "Installation" sections of
the manual below, so you can learn more about EDB's capabilities and how to
install the software.

I think you'll find EDB quite useful; try it, and let me know what you
think.
					-Michael Ernst
					 ······@theory.lcs.mit.edu

Introduction
************

EDB is a database program for GNU Emacs.  It permits users to manipulate
structured (or not-so-structured) data within Emacs and provides many of
the usual database features, including:

   * Flexible, customizable file layouts.  Data may contain any
     character, including those used to delimit fields and records.
     Files read and written by the database may have arbitrary formats.

   * Typed fields (e.g. integer, date, string); fields may also be
     subject to additional constraints (prime number, date before today,
     string that appears in some other record, etc.).

   * Arbitrary data display formats for viewing records.  Multiple
     display formats can be open on a database simultaneously, viewing
     the same or different records.  The data display format can be
     automatically chosen based on the record's field values.

   * Selective display of only those records of interest; others become
     temporarily user-invisible.

   * Standard GNU Emacs editing commands, which work only within data
     fields and not on the surrounding text.

   * Database summaries, which show in a single buffer one or more lines
     of information about each record.

   * Sorting, with an easy-to-use a graphical interface for defining the
     sorting criteria; most sorting orders you would care about are easy
     to specify, but arbitrary ones are also permitted.

   * Merging and reconciliation of databases.

   * Reports generated from database information.

   * Highly customizable via the underlying programming language, Emacs
     Lisp; many hooks and useful variables are provided to make this
     even easier.

   * Documented by a 90-page manual.

EDB is more ambitious--and therefore more complex--than its forerunners
(such as Forms Mode by Johan Vromans <··@mh.nl>).  While other packages
don't provide as much functionality as EDB, they may be more appropriate
for simple needs.


Installation
************

FTP the files from `theory.lcs.mit.edu:/pub/emacs/edb'; the package is
in a single compressed tar file `edb.tar.Z', and the individual files
can also be obtained from the `code' subdirectory.  Install the files in
your Emacs load path (probably in a directory of their own).  You can
add a directory to your Emacs lisp load path by putting something
similar to the following in your `.emacs' file:
     (setq load-path (cons (expand-file-name "~/emacs/edb") load-path))

Finally, cause EDB to be autoloaded by putting the following in your
`.emacs' file:
     (autoload 'db-find-file "database" "EDB database package" t)

Now, when you start up Emacs, you will already be able to execute
`db-find-file'; EDB will be loaded automatically.  See below if you wish
to byte-compile the EDB sources.

Here is one way to arrange to automatically run EDB when you read a
database file via the usual `find-file' command (ordinarily bound to
`C-x C-f'), whether or not you choose to autoload EDB.  This only works
on databases which have been stored in EDB internal file layout (*Note
Internal file layout::).

     (setq find-file-hooks (cons 'after-find-file-edb find-file-hooks))
     (defun after-find-file-edb ()
       "If this is a database file in EDB internal file layout, run EDB."
       ;; When this is called, we are at the beginning of the buffer.
       (if (looking-at ";; Database file written by EDB")
           (progn
             (require 'database)
             (db-this-buffer)
             ;; db-this-buffer kills the current buffer; and an error results
             ;; when Emacs tries to switch back to it.  find-file-noselect
             ;; uses the buf variable to hold the new buffer.
             (setq buf (buffer-name (current-buffer))))))

Naturally, running EDB will do you little good without a database to
manipulate; for information about creating a new database or using an
existing one (EDB can handle nearly any file layout imaginable and many
that aren't), see *Note Designing a database::.  You may also want to
use existing databases as guides, or to help familiarize yourself with
EDB.  A number of examples can be found in the compressed tar file
`examples.tar.Z' or in the `examples' subdirectory of
`theory.lcs.mit.edu:/pub/emacs/edb' (the two locations contain the same
examples).  You can test out function `after-find-file-edb' by
performing `find-file' on `forms-demo2-int.dat'.

It is strongly recommended that you run EDB byte-compiled, as otherwise
it is very sluggish.  To byte-compile EDB, type `M-x
byte-compile-database RET'.  (You may need to load EDB first, by typing
`M-x load-library RET database RET' or `M-x load-file RET database.el
RET', in order to define this function.)  If you perform the
byte-compilation yourself rather than using the `byte-compile-database'
function, you *must* fully load the code before compiling it, by typing
`C-u M-x load-database RET'.  For more details, *Note Compiling EDB::.

The texinfo documentation must be processed using release 2 of texinfo
(which is available via anonymous ftp from `prep.ai.mit.edu'), but the
resulting info files can be read using any info reader.  If you don't
have texinfo version 2, you can get the documentation pre-processed in
info format from `theory.lcs.mit.edu:/pub/emacs/edb', files
`database.info' and `database.info-[12345]' (six files in all).
Similarly, that directory has ready-to-print versions of the manual
(file `database.dvi' or `database.ps').