We need to harvest the various parameters delivered to GUFE via CGI. Since we made these parameters up ourselves, we know what we need to collect. In the above passage, we retrieve a string of field names to return from SQL queries, the table name to query, whether to sort the table, and what type of sort -- ascending or descending.
We also want to collect the criteria parameters which
customize the SQL query and determine what view of the
table we receive. For instance, a user may use the criteria
form fields to request a table in which we see only
those records where the Total is greater than 100. These
parameters are a bit more tricky because the parameter
names are generated on-the-fly by GUFE based on the field
labels contained in a particular table. To help standardize
things, the criteria parameters are named
In the code above, we retrieve from the CGI object all
parameters which conform to these names and we push those
values onto a list named
@allcriteria. It looks
messy, but at the end we construct a single string by using
join(), which might look something like:
Total > 100 AND Paid = 1
When all is said and done, we now have a variety of variables which contain the various parameters passed to GUFE. Basically, this is all about setting up the pins. Now we need to get the ball rolling.
The database connection is established, and the handle
$dbh. Next, a main
determines whether the page request specified a table to
view, via the
table CGI parameter.
If yes, we continue processing by constructing an SQL
statement using portions of CGI parameters we have harvested
earlier. The SQL statement is then passed onto and
executed by our
&sendSQL subroutine and the statement
handle is passed onto
$sth. We'll need to use
this handle to access the results of the query.
We end this
if clause with a compound statement,
one which executes our
using the results of the
We pass several parameters to
including the database and SQL statement handles, the name
of the table being queried, and the fields to be returned.
This subroutine, which we'll see shortly, actually creates
the entire HTML output of GUFE, which is then passed
&createPage in this case. For its part,
&createPage takes the HTML produced by
and shoves it into the HTML template. Finally, the
results of that are output to the screen by the containing
print() function. Whoa!
In case the user did not specify a table to query (namely
by visiting gufe.cgi with no additional parameters),
else clause skips construction of the SQL
statement and proceeds directly to building and outputting
the result table, which itself will alert the user to
select a table to view.