WEBBASE INTERFACE AND ODBC CONCEPTS

Click here for audio-text lecture and feed it to the speech agent
WebBaseTM is a Web database server that allows the programmer to easily integrate information from Open Database Connectivity (ODBC) databases into a Web site. It works in cooperation with any browser, allowing the end user to perform database searches through the Web page.

WebBase can be used as a simple Web server to provide easy database access. It can also be used to provide flexible and dynamic presentations to users. The programmer will use the WebBase macro language to develop the htf forms to retrieve and present information. This WebBase macro language, like any other programming language, is made up of variables, macros, expressions and operators.

More Information About WebBase

More information about WebBase can be found at: where you will find a complete user's manual and a free trial version of WebBase which you can download.

For additional information you can contact:
(To do the miniproject using WebBase, it is required that you download the free trial version of WebBase and install it on your PC. Otherwise you should select the SQL compiler miniproject.)

An Example of WebBase Programming

WebBase allows database interaction from web browsers. We will first explain the elements of the WebBase language using a simple example. Suppose we want to search for the address of Denny. The HTML form may look like:


 < FORM METHOD="get" ACTION="http://www.webbase.com/docs/webbase/examples/getname.htf"> 
Please enter the name to search for:  < INPUT NAME="name" SIZE=15 VALUE="Denny"> 
 < INPUT TYPE=SUBMIT value="Enter">  < /FORM> 


The above HTML form as seen by the user looks like this:
Please enter the name to search for:

If you click the ENTER button, this will send a "GET" request to the server that looks like:

The server processes the GET request and a variable name with value 'Denny' is passed to the form getname.htf which looks like this:
 < HTML> ;
 < HEAD> ;
 { sql to answers source 'Primary' user 'Administrator' password 'Secret' max 25  } 
SELECT * FROM Examples WHERE Name LIKE '% { name } %'
 { /sql } 

 { if 0 answers size = } 
 < TITLE> ; I'm sorry!  < /TITLE> ; 
 < /HEAD> ;
 < BODY> ;
 < H2> ; Search results for:  { %search% }   < /H2> ;
 < HR SIZE=8> ;
 < H2> ; I'm sorry, I could not find any records that match in the database. < /H2> ;
 { else } 
 < TITLE>  WebBase Demo Results  < /TITLE> ; 
 < /HEAD> ;
 < BODY> ;
 < H2> ; Search results for:  { %search% }   < /H2> ;
 { forRow aRow on answers }  < HR> ; < PRE> ;
       Name:  < B> ; { Name }  < /B> ;
    Company:  < B> ; { Company }  < /B> ;
       City:  < B> ; { City }  < /B> ;
      State:  < B> ; { State }  < /B> ;
   Zip Code:  < B> ; { Zip }  < /B> ;
         Ph:  < B> ; { Phone }  < /B> ;
 < /PRE> ; { /forRow } 
 { /if } 
 < P> ;
 < /BODY> ; 
 < /HTML> ;  

The WebBase macro language is intermixed with the HTML language. To avoid confusion these WebBase macros and tags are enclosed in curly braces. WebBase will dynamically interpret these macros and tags to generate the presentation.

WebBase automatically creates local variables for each of the command line arguments sent by the browser. Any WebBase variable names specified in the htf file within curly braces, e.g., {name}, are automatically replaced by the value of the variable.

The first WebBase macro encountered is an sql macro. The 'source' tells WebBase where data are to be found. WebBase then replaces { name } with 'Denny' and performs the SQL SELECT as directed from the 'Examples' table of the 'Primary' ODBC source. This will result in zero to N records (max of 25) returned to variable { answers } .

The { if 0 answers size = } tests the size of the answers variable and returns the HTML immediately following the { if } if the test is true (zero answers) and returns the HTML immediately following the { else } if one or more answers exist. The expression { if 0 answers size = } is in reverse Polish notation.

In the { else } clause we loop on the answers with a { forRow aRow on answers } with the variable aRow taking on each of the returned results in turn. The fields from the returned record, { Name } , { Company } , etc. will be substituted where requested.


A More Complex Example

We now use a more complex example to illustrate WebBase programming. A Student Information System implemented using WebBase language can be found at: http://halley.ksi.edu/ex5/ (Please note the slash at the end is significant and cannot be omitted). This system's functions are the same as what you implemented in Exercise 5.

The test files are in halley.ksi.edu and you can use anonymous ftp to download them. For password you can enter your e-mail address.

The main menu page is at: http//halley.ksi.edu/ex5/
This will in effect become: http://halley.ksi.edu/ex5/Default.htf
The retrieval program is: http://halley.ksi.edu/ex5/exercise5.htf
Two inserted program pieces are: Defaults.hti and Footer.hti
The Access database file is: http://halley.ksi.edu/ex5/Student.mdb
The 'source' corresponding to Student.mdb is also called 'Student'


The Student Information System works as follows. When the end user clicks on the different options of the main menu page Default.htf, this information is passed to the retrieval program exercise5.htf. Based upon what the user selects, the corresponding SQL query is executed and the retrieved information from the 'source' (which corresponds to the Access database Student.mdb) is displayed. The user can return to the main menu page to select another query.

The two program pieces Defaults.hti and Footer.hti are included into the main program using a macro not dissimilar to 'include' in C programming language. These are program pieces often used by main programs. Defaults.hti specifies the background colors, and Footer.hti provides some common footnotes on ownership, copyright and contact person.

The main forms have the suffix htf (hypertext form) and the inserted program pieces have the suffix hti.

How the WebBase Program Works

Although it is called a hypertext form (htf), a WebBase program is essentially a Web page in html (hypertext markup language) format enhanced by certain macros so that you can deal with databases. Therefore, you can first create the html pages, and then add the WebBase macros to provide database retrieval and presentation capabilities.

The form Default.htf is the main menu. The following WebBase tags and macros are used: (For detailed discussion of macros, read Chapter 8 of WebBase User's Guide)

Comment Tags let the programmer create comments within the Web pages that will be invisible to the web browser. There are two types of comments: the {comment} and closing tag, which will NOT limit the comment, and the {! ... !} commment. You cannot put WebBase tags inside the {! ... !} comment.

{insert filename} lets you take a file from the server and place its contents within the current WebBase file. This is very much like the #include filename in C and C++.

{BackColor} is a user defined variable. It is defined in the file default.hti. It contains the color to be used as background. Since it is defined in defaults.hti you only need to change it in there and any page that calls defaults.hti and uses BackColor will change.

{LinkColor} is similar to BackColor, but this is the link color.

{VLinkColor} is similar to BackColor, but this is the visited link color.

The Default.htf form looks like this:


{insert 'defaults.hti'}	{! insert is like the include in C and C++ !}	

 < HTML> 

 < TITLE> Student Information System < /TITLE> 

{! The variables BackColor, LinkColor, and VLinkColor are defined in defaults.hti !}
 < BODY BGCOLOR={BackColor} LINK={LinkColor} VLINK={VLinkColor}> 

 < CENTER>  < H1> Student Information System < /H1>  < /CENTER> 

 < HR SIZE=2>  < !---------------------------------------------------------> 

 < h2> Select one of the queries: < /h2> 
 < OL> 
   < LI>  < A HREF="Exercise5.htf?Item=A"> List the name of students who have
    completed any course module. < /A> 
   < LI>  < A HREF="Exercise5.htf?Item=B"> List the name of students who have
    completed course module A1. < /A> 
   < LI>  < A HREF="Exercise5.htf?Item=C"> List the name of students who have
    completed at least two course modules. < /A> 
   < LI>  < A HREF="Exercise5.htf?Item=D"> List the name of students who have
   who have completed any course module during the period 1/1/90 to 6/30/90. < /A> 
 < /OL> 

{insert 'Footer.hti'}  {! Inserts The generic footer for all pages !}

 < /BODY> 
 < /HTML> 

The database retrieval and presentation are done in the WebBase form exercise5.htf. Again we will first explain the WebBase macros and tags used in this form:

{case 'variable'} is the Select clause for WebBase. Takes a variable and matches to one of the values. If {match 'value'} do what follows. {otherwise} if nothing matches then do otherwise. {/case} is end of the case macro.

{set 'variable' 'expression'} is the assignment operation in WebBase. The expression must be in RPN Reverse Polish Notation. This will also create variables if they aren't already created.

{if 'expression'} is the if clause for WebBase. The expression must be in reverse polish notation. {/if} ends the if macro.

{sql [to 'recSet'] source 'dataSourceName' [[user 'userid'] [password 'password']] SQLSstatement is the way to embedded sql into your WebBase pages. The 'recSet' is required for any queries that return records. {/sql} ends the SQL macro.

{forRow 'rec' on 'recSet'} is the for loop in WebBase. It works with the 'recSet' for the size of the 'recSet'. Inside the loop any variables in a record can be directly accessed. {/forRow} ends the loop.

{Item} is a variable defined by the search string in the URL. The format for the search string is http:// < host> / < file> ? < var> = < value> .

{SQLStatement} is the SELECT statement to be used in the query.

The form exercise5.htf looks like this:


{insert 'defaults.hti'}	{! insert is like the include in C and C++ !}

 < HTML> 

 < TITLE> Student Information System < /TITLE> 

{! The variables BackColor, LinkColor, and VLinkColor are defined in defaults.hti !}
 < BODY BGCOLOR={BackColor} LINK={LinkColor} VLINK={VLinkColor}> 

 < CENTER>  < H1> Student Information System < /H1> 

   < HR SIZE=2>  < !---------------------------------------------------------> 
		 {! Note: how the variable was passed...   Through the command line !}
    {case Item}  {! Determines which Item was selected and queries on that item !}
      {match 'A'}
         < H3> List the name of students who have completed any course module < /H3> 
        {set SQLStatement 'SELECT DISTINCT NAME FROM Student WHERE COURSE_MOD is Not null'}
      {match 'B'}
         < H3> List the name of students who have completed course module A1 < /H3> 
        {set SQLStatement 'SELECT DISTINCT NAME FROM Student WHERE COURSE_MOD =''A1'''}
      {match 'C'}
         < H3> List the name of students who have completed at least two course modules < /H3> 
        {set SQLStatement 'SELECT DISTINCT NAME FROM Student AS A WHERE 2  < = (SELECT COUNT(*) FROM Student B Where A.SSN=B.SSN)'}
      {match 'D'}
         < H3> List the name of students who have completed any course module during the period 1/1/90 to 6/30/90 < /H3> 
        {set SQLStatement 'SELECT DISTINCT NAME FROM Student WHERE COMP_DATE> =#1/1/90# AND COMP_DATE < =#6/30/90# AND COURSE_MOD is not Null'}
      {otherwise}	{! If the page was opened without using the menu page !}
         < H3> Nothing was selected from the menu. < /H2> 
        {set SQLStatement ''}
    {/case}

   < HR SIZE=2>  < !---------------------------------------------------------> 

  {if SQLStatement '' = not}   {! If the SQLStatement is not '' Then !}
    {sql to recs source 'Student'}	{! The sql- Record Set variable "recs"      !}
      {SQLStatement}  			{!          The Data Source 'Student'       !}
    {/sql}				{!          The SQL Statement "SQLStatement !}

     < TABLE BORDER=1>  < TR>  < TH> Student`s Name < /TH>  < /TR> 
    {forRow curRec on recs}		{! Output each row of the record set !}
       < TR>  < TD> {NAME} < /TD>  < /TR> 
    {/forRow}
     < /TABLE> 
  {/if}
   < BR> 
   < A HREF="default.htf"> Try again. < /A>  < BR> 
 < /CENTER>  
{insert 'Footer.hti'}  {! Inserts The generic footer for all pages !}

 < /BODY> 
 < /HTML> 


In the form Defaults.hti, {%output%} is a Global Variable that tells WebBase whether it should be outputting data to the browser. The form looks like this:


{set %output% false}	{! %output% is used to display information to the browser !}
{set BackColor "#FFFFFF"}  {! These are user defined variables "Global Like" !}
{set LinkColor "#8C0029"}
{set VLinkColor "#8C0029"}
{set %output% true}

Finally, the form Footer.hti generates a common footnote. No WebBase Macros or variables used or defined in this form. The form looks like this.


 < P> 
 < HR>  < !----------------------------------------------------------------> 
 < CENTER>  < FONT SIZE="-1"> 
	Copyright © 1997 ksi.edu All rights reserved.
 < /FONT>  < /CENTER> 
 < HR>  < !----------------------------------------------------------------> 
 < TABLE BORDER=0 WIDTH=100%> 
   < TR>  < TD> 
    Questions can be addressed to the Webmaster -- 
     < I>  < A HREF="mailto:ksiwww@ksi.edu"> ksiwww@ksi.edu < /A>  < /I> 
   < /TD>  < TD ALIGN=RIGHT> 
    Last modified:  < I> 10/29/1997 < /I> 
   < /TD>  < /TR> 
 < /TABLE> 


Open Database Connectivity

Open Database Connectivity (ODBC) is a standard devised by Microsoft to enable any application to communicate with any database manager. ODBC is based upon SQL as a standard for accessing data. The interface provides maximum interoperability: a single application can access different SQL Database Management Systems through a common set of code. This enables us to build a client/server application without pre-selecting a specific DBMS. Database drivers can be added later to link the application to our choice of DBMS.

The ODBC driver is the interface program via which the end-user has access to the database. Microsoft provides a set of ODBC drivers on the web site. The sql macro within the WebBase form is used to generate a database query. WebBase translates this query into an ODBC function call and pass it to the ODBC driver. The driver accepts the ODBC request, translates it into internal format recognizable by the specific database system (e.g., ODBC to Microsoft Access), manages the communications with the database itself, and provides the results back to WebBase. WebBase in turn completes the processing of the results which are made available in the WebBase form for subsequent use.

The advantage of this approach is that it allows WebBase to support any ODBC compliant database without the knowledge about the specifics of a particular DBMS. Therefore it is possible to retrieve information from a Microsoft Access database and use it to generate a new record in an Oracle database. In the future, if the Oracle database is replaced by another DBMS, no change in the WebBase forms are required.

In order for WebBase to access a database, an ODBC source for that database must be created. An ODBC source assigns a name and optionally a username and password to a particular database file. This ODBC source name, username and password are then used by WebBase to access the database. A data source must be created for EACH database that you will be accessing using WebBase.


Programming Tips

  • The form submit methods are post and get....
    'get' displays all the info in the location of the next page. 'post' hides that data from the form...

  • If you make a change to the database or to the htf files and look it will appear if nothing has changed unless you hit reload. This can be frustrating so in the form you pass the time variable so that it will differ every time you load the page and it won't be loaded from cache.

  • Other errors with webbase... a protection violation occurs after just about any error so when you think you fixed the error you get a protection violation. This generally just means the last process was incomplete and when you hit reload it will go away....

  • Be cautious when using two or more queries on a page. If you try to access one's data it might fail if you don't reference the proper data.

  • When using URL, always put the '/' at the end. If you don't put the '/' at the end it will look in the root directory for the file when they are actually in the sub directory.
  • If you are debugging your WebBase forms on a local PC, the first form C:\whatever.html can be accessed by Netscape. Keep in mind that any subsequent access to htf forms should be done using http://127.0.0.1:80/whatever.htf. This IP address is what actually connects Webbase to your .htf forms. If you just use the URL C:\whatever.htf, it will not work.

    Installation Tips

    The detailed information about WebBase installation can be found in Chapter 3 of WebBase User's Guide.

    To install the free trial version of WebBase you must have a PC with:

  • an Intel processor
  • Windows NT 3.51 or greater, Windows 95, Windows 3.1 (with Win32s) or Windows for Workgroups 3.11 (with Win32s)
  • TCP/IP software installed and properly configured
  • At least 16MB of memory (32 MB recommended)
  • A network connection (for testing, you don't need the network connection, but you MUST have a browser and the TCP/IP software to simulate network connection)
  • An ODBC compliant database and appropriate ODBC driver(s)

    The installation, documentation and ODBC driver files are available as downloads from the WebBase web site.

    The proper ODBC drivers for the operating system MUST be used. The majority of problems that users encounter with ODBC and WebBase are the results of an incorrect match between ODBC database driver and operating system version.

    Acknowledgement: The second programming example and programming tips are from Brian Kirk (E-mail: bekst9@pitt.edu). The rest can be found from the WebBase User's Guide.