April 16, 2002 Douglas Clark is a program management consultant who first started using OS/2 version 1.3. He's married, with 2 girls, and is old enough to remember when 4 color mainframe terminals were a big thing. If you have a comment about the content of this article, please feel free to vent in the OS/2 eZine discussion forums. There is also a Printer Friendly version of this page. |
|
ODBC on OS/2 Part 12
| |||
RexxThere are two products for Rexx that provide access to ODBC databases, neither of which is sold anymore: VX-Rexx and VisPro-Rexx. There is currently no method for getting at ODBC data apart from those two products. However the is a library of data access routines called RexxSQL put out by Mark Hessling that provide a common (though not ODBC) interface to DB2, Oracle, mSQL, mySQL, and SQL Anywhere. SibylSibyl is a Delphi clone that works on OS/2. It builds Borland-like Turbo Pascal applications using the same interface and parts as Borland's Delphi 2. It is very compatible with Delphi and supposedly you can take Delphi source (Pascal language, forms, etc.) and recompile with Sibyl on OS/2. When you are finished building your application you end up with a stand-alone executable that can be moved to any Warp machine. Sibyl is very complete. It has interfaces to TCP/IP, the OS/2 Control Program API, Rexx, multimedia and more. You can build very nice applications with Sibyl, as NewView by Aaron Lawrence shows. Sibyl is not perfect - the component classes that come with Sibyl can be buggy, especially the ones that work with databases. However Sibyl supplies the source code for its classes in fix pack 4 so you are not completely stuck with a bug you can't get around. Sibyl has been reviewed before in OS/2 eZine and we are not going to repeat that review. Instead we will concentrate on a very quick overview of the database capabilities in Sibyl. The folder for Sibyl looks like this. The DBExplorer icon is not installed in the folder; you must add it yourself.
Sibyl can work with any ODBC enabled database. It also comes with a number of drivers for different databases that bypass ODBC and allow Sibyl to work directly with that database: DB2/2, dBase, mySQL, Oracle 7, SQL Anywhere, and Paradox. I have not tested any of these. But in theory, for instance, you could use Sibyl to write applications for mySQL which does not have an ODBC driver (that works) in OS/2. Sibyl addresses databases through a concept it calls a database alias. This database alias is very similar to a data source in ODBC, meaning that an alias is the association of an arbitrary name with a database driver. The driver can be either one of Sibyl's built in drivers or it can be an ODBC data source - if the alias is an ODBC datasource the alias must have the same name as the ODBC data source name. The easiest way to create database aliases is with the DBExplorer tool. This little jack-of-all-trades tool allows you to create a database alias, browse the attributes of a database, and to submit SQL statements to a database. The first tab lists all the built in database drivers supplied with Sibyl.
The second tab lists the database aliases. It is here that you also create a new database alias with the Database Command on the menu bar.
The Database Command brings up the following dialog where you specify the type of driver and the name you want to use for the alias. Once again, if you are using an ODBC driver the name of the alias must match that of the ODBC DSN (data source name).
If you want to browse a database you can expand the list on the left side until you get to an attribute you want to examine. The figure below shows a PostgreSQL database access through ODBC.
The IDE for Sibyl should look very familiar to Delphi users. If consists of a number of separate windows all connected through a menu bar/tool bar window that appears at the top of the screen. Controls and components appear in tabbed areas in the top window. Notice the Database tab; this is where the components are located for database access. The form window is where the visual and non-visual components are placed. The Object Inspector window on the right is where the properties and events are listed for "current" or selected component on the form window. The window behind the form window is the editor and debugger. As components are placed on the form window Pascal code is added to the editor to handle those components. Visual components are controls that are visible to the user. Non-visual components are components that are needed to perform some service but are invisible to the user. Most of the Database components duplicate other components in Sibyl, the difference being that the database components have additional logic necessary to handle data. For instance there is a regular list box and a database component listbox, the database listbox gets its values from a database instead of being supplied programmatically. ExampleWe are going to make a very simple application that lists the data in a table from a database. This will require us to place three components on the form and set the properties of those components. We will also add two lines of Pascal code to cause the visual database component to resize when the window is resized. The three components we will use are:
The figure below shows all three components placed on the form, along with the Object Inspector for the TQuery component where we are creating the SQL statement to retrieve the rows from the customer table - we double-clicked on the SQL property to get the dialog box you see below where we enter the SQL statement. The DBGrid appears on the form in the figure below as just a square area with a raised part.
The TDataSource and TQuery are connected together through the DataSet property in the TDataSource component, shown below. The name of the TQuery component is entered in the DataSet property.
The Object Inspector is shown below for the DBGrid component. The DBGrid component is tied to the TDataSource component by entering the name of the TDataSource object in the DataSource property.
The final action we will do is to write code to resize the DBGrid when the form window is resized. To do this we need to click on the Events tab in the Object Inspector for the form object. Then we need to find the Resize event. Finally we double-click on the Resize event entry box and we are taken to the editor where that procedure exists. We can then type in anything we want. We will set the DBGrid height and width to the ClientHeight and ClientWidth of the form object, as shown below.
The editor has a neat feature where it will pop-up a list of all the properties and events that pertain to an object/component as you are typing the object name, as shown below. You can then just pick the item you need from the list.
We then click the Run button - which automatically compiles the application, and this is the final result. Not bad for just three components and two lines of code.
The Bad NewsEverything is not peaches and cream though.
Sibyl ConclusionSibyl is an exceptional, albeit buggy, product for application development. It is one of the few OS/2 application development environments that provides easy access to ODBC data. ODBC ConclusionODBC is alive and well on OS/2. You can get to most of the major databases on the market today with ODBC drivers in OS/2.
|
|||||
|