Effable Home ->Public ->Open Source ->DBT


NAME

DBT - DataBase Template CGI


SYNOPSIS

http://hostname/path/DBT[.cgi]/path_to_template_file?query_parameters

http://hostname/path/DBT[.cgi]/path_to_template_file

<!--#config

-->

<!--#include file=``file path''-->

<!--#include cgi=``cgi executable path''-->

<!--#include template=``file path''-->

<!--#echo var=``environment variable''-->

<!--#echo form=``form parameter name''-->

<!--#echo field=``field name''-->

<!--#exec cgi=``cgi executable path''-->

<!--#mktag tag=``a_href | input | img | select`` [ name=''value`` ...]-->

<!--#size file=``file path-->

<!--#flastmod file=``file path''-->


DESCRIPTION

DBT allows elaborate database applications to be built by writing HTML containing a variation on NCSA-style SSI (Server Side Include) tags. Elaborate psuedo-relational database applications are facilitated through the application of nested templates, and a predictable precedence of SSI tag substitutions.

The databases are stored in flat text files, managed by the ``Sprite.pm'' package by Shishir Gundavaram.


TEMPLATE FORMAT

Templates are complete or partial HTML files with an added config block and substitution (SSI) tags. Templates are intended to be nested, so only the overall or outermost template needs to have the main <HEAD> and <BODY> HTML tags.

Config blocks are deleted from the template file once processed and are not visible in the source code delivered to the web browser.

It is recommended that template files be given the extension ``.httml'', for HyperText Template Markup Language. However, this is only necessary if the processing of templates is added as an Action in the http server configuration (see ``Apache Configuration'' in the Notes section below).

The two types of supported HTML tags are the config block and substitution tags. Each one appears as an HTML comment to most browsers and servers, though some of them are identical to standard SSI tags, and would yield the same results if used in that context.


Config block

A config block describes a template's relationship to a database.

<!--#config

A config block begins with the config block ID tag. It is followed by a number of configuration parameters. The configuration parameters are in the form of name-value pairs, as in normal HTML tags. The values must be quoted with double quotes (``). The pairs may be separated by white space or newlines.

-->

A config block ends with a standard HTML end-of-comment string.


Substitution Tags

A substitution tag is modeled on the NSCA/Apache Server Side Include (SSI) tag syntax. They may be used anywhere within a template, even within enclosing HTML tags. They are listed in order of replacement.


CGI QUERY VALUES

Normally, templates will only be called by the submission of HTML forms. A template that identifies a database file (through the DBfile parameter) in its config block defines the CGI parameter names expected and recognized by that template in its DBfields parameter.


Global Parameters

Any CGI parameter name that is exclusively alphanumeric is a global parameter name. Any template in the hierarchy may use this parameter in a search or submission, if it matches a defined field name within that template.


Template-Addressed Parameters

A CGI parameter name constructed from a template name, as defined by the TemplateName config block parameter, followed by a period, followed by field name from that template, is ignored by all templates in the hierarchy except those for which the field and template names match.


Reserved Parameters

Reserved parameters modify the normal processing of templates. Reserved parameter names may not be used as database field names.


Environmental Variables

All standard SSI environmental variables are available to use in within an ECHO or MKTAG substitution tag. Several other environmental tags are available within DBT scripts:


NOTES


Database Design Tips

In general, most applications will include at least one top-level template which calls a number of subsidiary templates using an <!--#include template=``template file path''> tag. The subsidiary templates are used for queries resulting in multi-item reports. Any template capable of action on a database includes the config block that references a database file, and includes the <!--#echo field=``''> substitution tags which are replaced with query results.

Don't forget that the _CMD parameter can address different commands to nested templates than to the top-level templates. In most applications created by the author, many hidden INPUT tags were used to manage the behavior of a template hierarchy.

HREFs within subsidiary templates point to locations relative to the top level template (not to the location of the subsidiary template). However, file paths to the included files and templates within subsidiary templates appear relative to the directory location of the subsidiary template.

A detailed HOWTO document is also included with the package to aid less experienced users.


Apache Server Configuration

The Apache web server permits new types and actions to be configured into it. This can allow ``.httml'' files to be submitted to DBT to be processed without addressing the script within the URL.

To enable this capability, Add the following lines to the srm.conf file:

        AddType text/template-html .httml
        Action text/template-html /cgi-bin/DBT

AddType causes the Apache server daemon to recognize a file with the ``.httml'' suffix as one to require special handling. The Action directive indicates the path, relative to document root, to the handler for this data type.

Using this configuration can enhance security, making it impossible for a client to request an unprocessed template.


Future Enhancements

One requested feature is for BLOBs (Binary Large OBjects) -- binary file upload and retrieval.

It would be desirable to implement the full range of SSI tags, not the subset supported now.

It would also be desirable to allow tieing to other types of databases, not just Sprite (which is relatively slow). This would require a rewrite to support standard PERL DBI -- a desirable goal in any case.

Someday, in a galaxy far, far away, it would be nice to rewrite this into an Apache module.


PREREQUISITES

This script requires Perl version 5.004 or later.

This script requires the Sprite.pm package by Shishir Gundarvaram. It's available at:

        http://www.cpan.org/modules/by-module/Sprite/


COREQUISITES

This script has only been tested with the Apache web server.

DBT has been tested on the Unix variants: Solaris, OpenBSD, LinuxPPC, Linux x86, Irix, MacOS X Server, and MachTen.

DBT is classified as a CGI script in CPAN.


AUTHOR

Bug reports, feature requests, and other comments may be sent to the author:

        stevesgt@effable.com (Steven Sergeant)


COPYRIGHT

©1999 - 2001 by Steven Sergeant.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA =cut


VERSION HISTORY:

        0.5     1998/11/19      Works for select only
        0.6     1999/01/26      Initial working release
        0.7     1999/04/04      Added MKTAG function, _SORT, _MAXRESULT, and _NEXTRESULT commands.
        0.71    1999/04/11      Fixed file pathing bugs.
        0.72    1999/04/12      Added SpriteEsc and SpriteUnEsc functions to fix some SQL errors.
        0.8     1999/05/27      Added support for Apache security, added other security fixes, improved docs.
        0.81    1999/08/20      Documented additional environment variables, added error reporting for access-denied, fixed show/hide bug w/like template names.
        0.82    1999/10/22      Fixed a SpriteEsc/SpriteUnEsc bug
        0.821   2000/05/18      Added REQUEST_SECS
        0.822   2001/01/24      Added _RESULT_COUNT
        0.823   2001/01/26      Added IMG type for mktag
        0.83    2001/05/09      Added limited support for "exec cgi" or "include cgi", IFRESULT parameter for A_HREF mktag, added _NEXTRESULT environment variable, set default template name to template file name.