INFORMIX-ESQL/C CGI Interface Examples

Version 1.00.UE1 Mar. 6, 1996

The following examples were designed with a single source file each and are intended to be used with the Informix demonstration database stores.

Table of Contents

  1. Example #1: customer
  2. Example #2: getcatpic
  3. Example #3: catalog
  4. Building the Examples Yourself

Back to TOC = back to this Table of Contents


Back to TOC Example #1: customer

The customer example shows how HTML can be used as a QBE form to query a single table from the database. The example is "stand-alone" in that no external HTML files are required.

When the executable is called the first time from the Web browser, the CGI REQUEST_METHOD variable is set to "GET" and the QUERY_STRING is empty (because it has not been called from a form). In this case, the executable will send out a "default" query form, then exit. At this point, the user can enter QBE data in the fields and click on the "submit" button.

The executable is run again, this time the REQUEST_METHOD is set to "POST" and the form entries contain the data from the QBE fields. Using the cgi_get_form_entry() function, the QBE data is constructed into an SQL WHERE clause which is prepared with a SELECT clause and executed against the database. The resulting customer listing is output with HTML formatting using cgi_print_text() along with the original form so the user can continue to view and query customer data.

[ Execute ] [ Source code ] [ Make File ] [ Kit Documentation ]


Back to TOC Example #2: getcatpic

The getcatpic example is a "helper" CGI executable that fetches the GIF image BLOB from the catalog table of the stores database and prints it to the Web browser. (TEXT and BYTE BLOB's are available with Informix's OnLine database engines).

This example is designed to accept the primary key value for a single catalog row (catalog_num column) from the command line. Since the information required comes from a command line argument value, the cgi_start(), cgi_get_form_entry() and cgi_free() functions are not used. The primary key value is parsed into a SELECT statement, the BLOB is fetched into a host variable and then printed to CGI using the cgi_printblob() function. This function is called with the MIME-type image/gif as its first parameter, the BLOB locator (loc_t structure) as its second parameter. The BLOB may be located in memory or a file. If a file is used, the program cleans up by deleting the temporary file.

This executable is meant to be used as an image source within other HTML pages (example #3 illustrates this). For instance, the image HTML might be:

 <IMG SRC="[unarchived-media]" ALIGN = "MIDDLE">

(Notice a question mark is placed between the executable name and the command line parameter for a valid URL.)

[ Execute (baseball mitt) ] [ Execute (volleyball) ] [ Source code ] [ Make File ] [ Kit Documentation ]


Back to TOC Example #3: catalog

The catalog example allows the Web surfer to pick a catalog item from an HTML select box and display the detailed information about the item including its photograph. This example uses a join of 3 tables and shows how HTML is used to format TEXT, VARCHAR, MONEY and INTERVAL data types.

The design is similar to the first example, in that a "default" form is sent the first time the browser sends the URL ("GET" REQUEST_METHOD). Once the user selects an item from the list and clicks on "More Info", the specific item information is selected from the tables and printed to CGI as HTML. The getcatpic "helper" executable from example #2 fetches the GIF image.

[ Execute ] [ Source code ] [ Make File ] [ Kit Documentation ]


Back to TOC Building the Examples Yourself

Build the ESQL/C demo

The ESQL/C demo builder is found in $INFORMIXDIR/bin (for version 7.10, the executable is esqldemo7). This will create and load the stores database (stores7 for 7.10) and copy the standard ESQL/C examples to your current directory. For complete information on installing the demo, refer to "The Demonstration Database" section of the "Introduction" chapter in the INFORMIX-ESQL/C Programmer's Manual.

Load GIF Images

A utility has been provided with the examples to load GIF versions of the catalog table images:

cd /myworkdir/esqlcgi/examples/loadgif
loadgif.sh

The script will compile the ESQL/C blobload utility and load some images into the table (every row will not necessarily have an image).

Build the CGI Examples

Generate a make file from the make file template, for instance:

cd /myworkdir/esqlcgi/examples/example1
make

Use the generated make file provided to build the example:

make -f customer.mak customer

NOTE: If you are not developing on one of the 4 certified platforms (Sun Solaris, Hewlett Packard HP-UX, Silicon Graphics IRIX or IBM AIX), you may have to make modifications to the generated make file to get it to work. Refer to the documentation on the make utility provided with your C development software.

Once built, the executable will have to be copied to a valid CGI directory on your Web server (typically cgi-bin). To run, open the correct URL from your Web browser, for example:

http://grimmy/cgi-bin/customer



[ Home ] [ Search ] [ Comments ] [ WWW Databases ] [ Download Free Software ] [ CGI Kit FAQ ]