[Top] [Prev] [Next] [Bottom] [Contents]

The Table Component Object

The HTML Table Component Object manages HTML interfaces that can Insert, Update, Delete, and provide complex Search capability for a database table. This application is also fully customizable through options strings specified in the create function call or through an HTML template file. Read about SaVaHtmlTable in Chapter 2 for expanded details of this functionality.

Currently, a lot of data is being stored in flat files for Web applications. In some cases this is a good idea, because not all data fits into a relational model. However, the hierarchical structure of the UNIX file system may be combined with the use of powerful UNIX file system commands to simulate a "database" which isn't easily expressed in a relational model. The absence of tools to hook databases to Web applications has forced the use of flat files in cases where a relational database would be more appropriate.

A problem with using flat files is the lack of a high-level, industry standard language like SQL. Without such a language, you lose data independence; you must write functions to support each additional query capability, and you have no index capability for searching large tables. In these cases you are building a legacy.

Suppose you wish to query for all employees who live in Utah, or all employees who earn more than $30,000, or all employees who live in Utah and earn more than $30,000, etc. The table component provides a tool for such needs.

The following sketch example shows how to use the Table Component.

1. Start Sapphire. Either use an existing project or make a new one.
2. Choose a start-up HTML file with either an Anchor or Form for an Activator with at least an Input Element and a Submit Button. The directory, contrib/table_ex, in the Sapphire/Web distribution, contains an example start-up HTML file with both an Anchor, a Form, and customization files.
3. Add the start-up HTML file to the project.
4. Bind that Anchor Activator to the NULL object using the Object Bind Editor. Choose Apply.
5. Choose Edit|Activator Code ... Enter the following code in the "Function Initialization Code" text box:
For Sybase:

SaVaHtmlTable("SERVERNAME", "pubs2", 
	"dbo.titles", SGESYBASE,
	SA_TABLE_TEMPLATE,
	NULL);
return;
where SERVERNAME is the name of your Sybase server, and dbo is assumed to be the table owner.

For Oracle:

SaVaHtmlTable("ORACLE", "DATABASENAME", 
	"SCOTT.TITLES", SGEORACLE,
	SA_TABLE_TEMPLATE,
	NULL);
return;
where DATABASENAME is the name of your Oracle database and SCOTT is assumed to be the table owner.

For Informix:

SaVaHtmlTable("SERVERNAME", "pubs2",
	"informix.titles", SGEINFORMIX,
	SA_TABLE_TEMPLATE,
	NULL);
return;
where SERVERNAME is the name of your Informix server and informix is assumed to be the table owner.

The SaVaHtmlTable function takes a variable argument list of options which MUST BE null terminated. The constant SA_TABLE_TEMPLATE is defined to be the option string:

"SaHtmlTable.Template : True"
This option allows this particular Table Component to be customized by an HTML template file as described later.

Now choose OK in the activator code window and then OK in the Object Bind Editor. Next choose the Edit|Options menu from the project window. Set your start-up document in the Project Category. Also set the username and password for your database in your Test category, if not already set appropriately. Save your options as well as your project. Now Save, Build and Test your project. Click on the anchor. You will note that the Notes textbox is rather long. It is defined to be varchar 255. Also notice that the hotlist strings are too long. Your table may be customized to remedy these problems as follows:

Add the HTML customization file

titles_tab.html 
to your project for Sybase and Informix.

or
TITLES_tab.html 
for Oracle.

The differences between Sybase, Oracle, and Informix are in case sensitivity. Bind the Form Activator to the NULL object using the Object Bind Editor; choose Apply. Now choose Edit |Activator Code... Enter the following code in the Function Initialization Code text box:

For Sybase:

SaVaHtmlTable("SERVERNAME", "pubs2",
	SaGetInputValue("TABLE_NAME"), SGESYBASE,
	SA_TABLE_TEMPLATE,
	NULL);
return;
where SERVERNAME is the name of your Sybase server.

For Oracle:

SaVaHtmlTable("ORACLE", "DATABASENAME",
	SaGetInputValue("TABLE_NAME"), SGEORACLE,
	SA_TABLE_TEMPLATE,
	NULL);
return;
where DATABASENAME is the name of your Oracle database.

For Informix:

SaVaHtmlTable("SERVERNAME", "pubs2",
	SaGetInputValue("TABLE_NAME"), SGEINFORMIX,
	SA_TABLE_TEMPLATE,
	NULL);
return;
where SERVERNAME is the name of your Informix server. The difference between this code and the Anchor code is that the third parameter is not a hard-coded table name, but rather the input from a Form Element with the name, "TABLE_NAME". Choose Ok in the activator code window, then Ok in the Object Bind Editor. Now Save, Build and Test your project. Enter your Table Name in the textbox and click OK. If you choose the Titles Table as in the hard-coded case, you get the same customization as before. You can add selective customization files for other tables.

The Table Component has some limitations. It does not work with BLOB data. It also assumes that the table exists without relations to other tables. If you have set up certain integrity rules, then this may not be a problem. The source code for the Table Component can be found in the client/src directory of the Sapphire/Web distribution, and the include files are found in the include directory. The source code shows how you can use the Sapphire/Web API to deliver powerful components to your developers/user and other parts of your organization.

If you wish to learn more about the Table Component and how to make wide use of it, see the Bluestone demo at:

http://www.bluestone.com/sapphire/table/tdemo.html
Note: Make sure you read Instructions, on the demo Web page, which also serves as a white paper.


[Top] [Prev] [Next] [Bottom] [Contents]

info@bluestone.com
Copyright © 1997, Bluestone. All rights reserved.