The Format of dbCGI Files
dbCGI files are just like standard HTML files, except that the
following are recognised:
- <sql subcommand>....</sql>.
- Formatting escapes starting with '%'.
The SQL subcommands are:
- init - Initialise the DBMS
- uninit - uninitialise the DBMS
- connect - connect to a database
- disconnect - disconnect from a database
- query - issue an SQL query to a connection
- execute - issue an SQL command to a connection
- format - format the results of an SQL query
- headings - format the headings of an SQL query
- error - specify a format for errors from the database
- valarg - validate arguments received through the HTTP query string
- valform - validate a value received from a form
The formatting escapes are:
- %% - substitutes to the '%' character
- %$ - substitutes to the process ID
- %# - substitutes to a sequence number, unique per output record produced
since starting dbCGI
- %nd - where n is a number starting at 1 -
substitutes to value of the named column of the output record (used in the
sql format command)
- %nh - where n is a number
starting at 1 - substitutes to the heading of the named column of the
output record (used in the sql format or sql headings commands)
- %na - where n is a number
starting at 1 - substitutes to an argument from the HTTP query string
- %e - substitutes to the current error message text (used in the sql
error command)
- %c - substitutes to the SQL command that caused the current error (used
in the sql error command)
- %n - (A literal n this time) substitutes to the current error number
(used in the sql error command)
- %v - substitutes to the value which failed validation (used in the
sql valarg and sql valform commands)
- %{text%} - generates an escaped representation of the enclosed text.
All non alphanumeric characters are escaped.
- %n(text%) - where n is a
number starting at 1 - only include the
enclosed text if the specified result column is not null.
- %[!n1,n2,n3,...:text%] - where
n1, n2,
n3 and so on are column numbers,
include the text only if the values in the listed columns have not
changed since the previous record.
- %n[@filename%] - where n is
the column number of a BLOB or character
column, store the value of the named column in the named file. This is usually
used in conjunction with %$ and %# to create unique
file names.
- %[|command%] - execute the named command
- %['text%] - double up any single quote characters in the text
- %["text%] - double up any double quote characters in the text
- %[\text%] - double up any backslash characters in the text
- %[-text%] - prevent the enclosed text from being reformatted for
presentation as HTML (stops remappings such as "<" to
< and new lines to <BR>)
- %[=var%] - substitutes the value of the named form variable
- %[=var:text%] - substitutes the value of the named form variable, or if
the variable was not received, substitute the text.
- %[?var:text%] - substitutes the text if the named form variable was
received.
- %[~var:text%] - substitutes the text if the named form variable was
not received.
- %[*var:text%] - sets the value of the named form variable.
The %[...%], %{...%} and %(...%) sequences may all be nested.
Below is the layout of a sample dbCGI file for Informix.
CorVu dbCGI for Informix Test
INFORMIXDIR=/usr/informix
SQLEXEC=/usr/informix/lib/sqlturbo
TBCONFIG=tbconfig
DATABASE=stores
%[!8:%8d
%]
%[!7,8:%7d
%]
%[!7,8,9:%9d
%]
%4d
%3d %2d
%5d
%6(%6d
%)
%10d
select
*
from
customer
order by
state, city, zipcode
The query above accesses the customers table from the Informix sales demonstration
database and prints a list with breaks by state, city and zipcode (columns 8, 7 and
9). Column 6, which contains an optional second address line, is only displayed if
it is populated.