TweetFollow Us on Twitter

June 91 - Data Access Language Unit for MacApp

Data Access Language Unit for MacApp

Mary Elaine Califf

A few months ago I began work on three Macintosh front-ends for administrative data. The data resides in Rdb databases on our VAXcluster and was to be accessed using Apple's Data Access Language (DAL).

Since all three projects were full-featured applications, I abandoned HyperCard-in which the previous incarnations of two of these front-ends were written-and started learning MacApp. When I couldn't find anyone else using DAL and MacApp together, UDAL was born.

This version of the UDAL unit uses the cl1_api interface provided with DAL instead of the Data Access Manager routines. Therefore, it works with both system 6.0.x and system 7.0. UDAL is currently written in MacApp 2.0, but conversion to MacApp 3.0 requires only minor changes. The UDAL unit may not handle everything you want to do with DAL, but should at least suggest a way to incorporate DAL into MacApp.

THE BASICS OF DATA ACCESS LANGUAGE

DAL is a client-server protocol for remote database access. The Macintosh client is a system extension-included with system 7.0, available separately for system 6.0.x. Servers are available with adapters for various databases on systems running VAX/VMS, MVS/TSO, and VM/CMS. Other servers are under development, including one for A/UX that has already been announced.

DAL uses an SQL-based language that includes some C-like programming constructs. DAL's greatest asset is in providing applications with a uniform access method across various systems, database management systems, and network connection types. Despite the network overhead and the translation of DAL into the databases' SQL dialects, DAL's performance is fairly good and is improving with newer versions of the servers.

OVERVIEW OF THE UDAL UNIT FOR MACAPP

UDAL defines two classes: TDALConnection and TDALRequest. TDALConnection maintains information about a DAL session and contains methods that call the DAL functions. TDALConnection also provides a Reconnect method that establishes a new session using a previous connection object whose session aborted. One TDALConnection object is needed for each concurrent DAL session.

TDALRequest manages DAL queries. This class is useful for long, complicated requests or for requests that need to be reissued. Besides the two object types, the UDAL unit provides an InitUDAL procedure, utility routines for converting between Pascal strings and the null-terminated strings used by DAL, and default error handling routines.

INSIDE TDALCONNECTION-INTERFACING TO THE DAL API

The TDALConnection class provides an object-oriented interface to the DAL API functions. Therefore, most of the object's methods are based on the API functions. Note: API functions all begin with the letters CL; DAL was originally called CL/1, and the original function names were retained for compatibility. Please refer to the TDALConnection interface listing for the complete source of the class interface.

I added functionality to TDALConnection by including an error handling procedure as one of the parameters to each of the methods based on an API function. This addition helps to hide the details of managing the DAL connections from applications interested only in the data retrieved. The procedure I usually pass to the functions, HandleDALError, is included in the UDAL unit. All functions except GetString return the result code from the API function called; this allows the calling method to handle error checking. GetString returns the result code in a var parameter instead of returning it as its function result.

IDALConnection

The IDALConnection method initializes the object and establishes a DAL session using the CLInit function. It takes the host name, user name, password, and connection options as parameters. The Reconnect method also establishes a DAL session using CLInit, but it uses the fields of the object to determine the parameters for CLInit since its purpose is to re-establish the user's connection with the host.

HandleDroppedConnection

HandleDroppedConnection calls CLEnd to ensure that the last session was properly closed and then displays an alert, enabling the user to reconnect immediately. My applications all provide menu choices allowing later reconnection. When the user discovers a dropped connection but wants to do something that doesn't require a current session (for example, printing an existing document), he shouldn't have to wait for the new session to be established. If the user does wish to reconnect immediately, HandleDroppedConnection calls Reconnect.

CloseConnection

CloseConnection calls CLEnd to close down a DAL session. It doesn't free the TDALConnection object, because the object could be used to handle another session after calling Reconnect.

SendSQL and ExecuteRequest

SendSQL and ExecuteRequest allow the application to talk to the host database. SendSQL sends a string to the host. The ExecuteRequest method tells the host to execute everything received since the last call to ExecuteRequest. Note: The host doesn't do anything with the commands received until the user tells it to execute them. Be careful to always complete a DAL programming construct between calls to ExecuteRequest-telling DAL to execute what it has when you're in the middle of a for loop always produces errors!

CheckState and GetString

CheckState and GetString retrieve information from the host. CheckState determines if a value is waiting for retrieval; GetString retrieves a value from the host (if it doesn't time out first) and returns it as a Pascal string. The timeout period is specified as a parameter to the method. The routine returns values as strings because I couldn't get DAL to give me anything else from my Rdb database, even when the value was clearly an integer. Therefore, it was more convenient for the routine to convert the C strings into Pascal strings.

StopRequest

The final method in TDALConnection (other than Fields) is StopRequest. This method should abort the current request if the abortSession parameter is false and abort the entire DAL session if abortSession is true. However, test the method thoroughly in your environment before making it available to users. The CLBreak function it is based on is not always reliable. In some environments, it occasionally hangs both the Macintosh and the process on the mainframe. Everyone I've spoken to who uses DAL with Rdb databases has experienced these crashes when using CLBreak. The function does, however, work with some DBMSs.

A "Nothing" example for TDALConnection

Drop the source listed in A simple example using TDALConnection into a view's draw method to provide a very simple example that shows how to use TDALConnection.

INSIDE TDALREQUEST-HANDLING COMPLEX REQUESTS

Many uses of DAL can be made using only the TDALConnection class-I handle a fair amount of database communication in my applications using SendSQL, ExecuteRequest, and GetString.

However, at least two situations require better request management and a subclass of TDALRequest: inserting a few user-provided values into a query template, and saving a query and repeating it with no modifications. (Please refer to the TDALRequest interface listing for the complete source of the class interface.)

I had these needs in my applications. The template for one of my queries is a STR# resource with 15 strings. Also, all my documents contain the results of a database query that the user should be able to update without having to remember the query.

TDALRequest saves the text of a DAL request in a linked list of strings. It also contains a reference to the DALConnection it is supposed to use. It provides three methods of interest: SendRequest, ShowRequest, and BuildRequest.

SendRequest and ShowRequest

SendRequest sends each string in the request list using SendSQL, and then calls ExecuteRequest.

ShowRequest provides for debugging by displaying a dialog box with a TTEView containing the text of the request. If you cancel the dialog, ShowRequest returns false. This helps you avoid sending a bad request to the host during debugging.

BuildRequest

Most programmers who use UDAL will want to override BuildRequest. UDAL provides a default version that takes the STR# resource with id 2000 and stuffs the strings into a TTEView in a dialog box. It then takes what is in the TTEView when the dialog box is dismissed (if the OK button is pressed) and breaks the text into the request list. I find this useful in early stages of my applications, but all requests in my finished applications are implemented by subclasses of TDALRequest.

Your version of BuildRequest should usually display a dialog box to get user information and then create the linked list of strings from a STR# resource, inserting the information in the appropriate places. Make sure that each place where you need to insert information falls between strings in your STR#. BuildRequest should return false if the user cancels the request or some other error occurs while building the request. Otherwise, BuildRequest should return true.

The following code example demonstrates the use of TDALRequest assuming that aDALConn exists and that TMyDocument.GetData retrieves the data from the request:

New(aDALRequest);
FailNIL(aDALRequest);
aDALRequest.IDALRequest(kDefaultRequestID,fConn);
if aDALRequest.BuildRequest then
if aDALRequest.ShowRequest then
    begin
        aDALRequest.SendRequest;
        aDocument.GetData;
    end;

INSIDE TRETRIEVER-HANDLING ASYNCHRONOUS REQUESTS

DAL performance is improving, but some requests can take a long time. My applications allow users to switch to another application while a request is pending, and they also allow users to perform any task inside my application that doesn't require a database lookup. If you handle more than one DAL session, you can even allow multiple lookups, but only one per session.

To handle the retrieval of the information in the background, I create a TRetriever class that overrides DoIdle. The instance of this class need only exist while a lookup is occurring.

TRetriever = OBJECT(TEvtHandler)
fConn       : TDALConnection;
fDocument   : TFSDirDocument;
PROCEDURE TRetrever.IRetriever(conn: TDALConnection;
                         doc: TStuDirDocument);
FUNCTION TRetriever.DoIdle(phase:IdlePhase):BOOLEAN;
                        OVERRIDE;
END;

TRetriever's DoIdle method is fairly simple. It need only check to see if there is data waiting and call an appropriate method of the document to retrieve the data-in this case, GetPersonRecord. My DoIdle method also does some error handling-see the TRetriever.DoIdle implementation listing for the complete source.

Installing an instance of TRetriever is quite simple. The following five lines of code create the retriever and install it in the cohandler chain. You would include this code right after a call to TDALRequest.SendRequest or after TDALConnection.ExecuteRequest.

New(aRetriever);
FailNIL(aRetriever);
aRetriever.IRetriever(fConn,SELF);
aRetriever.SetIdleFreq(1);
gApplication.InstallCoHandler(aRetriever,true);

LOOKING FOR OTHER DAL USERS

The UDAL unit may not do everything you'd like to do with DAL, but I hope it will prove useful and suggest other ways that DAL can be used with MacApp. One future direction for the unit is the creation of a system 7.0-only version that takes advantage of the asynchronous capabilities of the new Data Access Manager routines. I welcome comments and questions. I would appreciate hearing from anyone using DAL.
 
AAPL
$97.35
Apple Inc.
+0.32
MSFT
$44.49
Microsoft Corpora
+0.09
GOOG
$588.08
Google Inc.
-5.27

MacTech Search:
Community Search:

Software Updates via MacUpdate

TinkerTool 5.3 - Expanded preference set...
TinkerTool is an application that gives you access to additional preference settings Apple has built into Mac OS X. This allows to activate hidden features in the operating system and in some of the... Read more
Audio Hijack Pro 2.11.0 - Record and enh...
Audio Hijack Pro drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio with Audio Hijack... Read more
Intermission 1.1.1 - Pause and rewind li...
Intermission allows you to pause and rewind live audio from any application on your Mac. Intermission will buffer up to 3 hours of audio, allowing users to skip through any assortment of audio... Read more
Autopano Giga 3.6 - Stitch multiple imag...
Autopano Giga allows you to stitch 2, 20, or 2,000 images. Version 3.0 integrates impressive new features that will definitely make you adopt Autopano Pro or Autopano Giga: Choose between 9... Read more
Airfoil 4.8.7 - Send audio from any app...
Airfoil allows you to send any audio to AirPort Express units, Apple TVs, and even other Macs and PCs, all in sync! It's your audio - everywhere. With Airfoil you can take audio from any... Read more
Microsoft Remote Desktop 8.0.8 - Connect...
With Microsoft Remote Desktop, you can connect to a remote PC and your work resources from almost anywhere. Experience the power of Windows with RemoteFX in a Remote Desktop client designed to help... Read more
xACT 2.30 - Audio compression toolkit. (...
xACT stands for X Aaudio Compression Toolkit, an application that encodes and decodes FLAC, SHN, Monkey’s Audio, TTA, Wavpack, and Apple Lossless files. It also can encode these formats to MP3, AAC... Read more
Firefox 31.0 - Fast, safe Web browser. (...
Firefox for Mac offers a fast, safe Web browsing experience. Browse quickly, securely, and effortlessly. With its industry-leading features, Firefox is the choice of Web development professionals... Read more
Little Snitch 3.3.3 - Alerts you to outg...
Little Snitch gives you control over your private outgoing data. Track background activityAs soon as your computer connects to the Internet, applications often have permission to send any... Read more
Thunderbird 31.0 - Email client from Moz...
As of July 2012, Thunderbird has transitioned to a new governance model, with new features being developed by the broader free software and open source community, and security fixes and improvements... Read more

Latest Forum Discussions

See All

Garfield: Survival of the Fattest Coming...
Garfield: Survival of the Fattest Coming to iOS this Fall Posted by Jennifer Allen on July 25th, 2014 [ permalink ] Who loves lasagna? Me. Also everyone’s favorite grumpy fat cat, Garfield. | Read more »
Happy Flock Review
Happy Flock Review By Andrew Fisher on July 25th, 2014 Our Rating: :: HERD IT ALL BEFOREUniversal App - Designed for iPhone and iPad Underneath the gloss of Happy Flock’s visuals is a game of very little substance. It’s cute, but... | Read more »
Square Register Updates Adds Offline Pay...
Square Register Updates Adds Offline Payments Posted by Ellis Spice on July 25th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Looking For Group – Hearthstone’s Curse...
For the first time since its release (which has thankfully been a much shorter window for iPad players than their PC counterparts), Blizzard’s wildly successful Hearthstone: Heroes of Warcraft CCG is sporting some brand new content: the single... | Read more »
Poptile Review
Poptile Review By Jennifer Allen on July 25th, 2014 Our Rating: :: SIMPLY FUNUniversal App - Designed for iPhone and iPad Simple yet a little bit glorious, Poptile is a satisfying entertaining puzzle game with oodles of the ‘one... | Read more »
Modern Combat 5: Blackout Review
Modern Combat 5: Blackout Review By Brittany Vincent on July 25th, 2014 Our Rating: :: LESS QQ, MORE PEW PEWUniversal App - Designed for iPhone and iPad The fifth entry into the blockbuster Modern Combat series is what mobile... | Read more »
Watch and Share Mobile Gameplay Videos W...
Watch and Share Mobile Gameplay Videos With Kamcord Posted by Jennifer Allen on July 25th, 2014 [ permalink ] iPhone App - Designed for the iPhone, compatible with the iPad | Read more »
THE KING OF FIGHTERS '98 (Games)
THE KING OF FIGHTERS '98 1.0 Device: iOS Universal Category: Games Price: $3.99, Version: 1.0 (iTunes) Description: Series’ masterpiece “KOF ’98” finally joins the battle on iPhone! FEATURES:■ The best game balance in the “KOF”... | Read more »
LEX Goes Free For One Day In Honor of Ne...
LEX Goes Free For One Day In Honor of New Update Posted by Jennifer Allen on July 24th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Thomas Was Alone Goes Universal, Slashes...
Thomas Was Alone Goes Universal, Slashes Price to $3.99 Posted by Ellis Spice on July 24th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »

Price Scanner via MacPrices.net

Mac minis on sale for $100 off MSRP, starting...
Best Buy has Mac minis on sale for $100 off MSRP. Choose free shipping or free instant local store pickup. Prices are for online orders only, in-store prices may vary: 2.5GHz Mac mini: $499.99 2.3GHz... Read more
Global Tablet Market Grows 11% in Q2/14 Notwi...
Worldwide tablet sales grew 11.0 percent year over year in the second quarter of 2014, with shipments reaching 49.3 million units according to preliminary data from the International Data Corporation... Read more
New iPhone 6 Models to Have Staggered Release...
Digitimes’ Cage Chao and Steve Shen report that according to unnamed sources in Apple’s upstream iPhone supply chain, the new 5.5-inch iPhone will be released several months later than the new 4.7-... Read more
New iOS App Helps People Feel Good About thei...
Mobile shoppers looking for big savings at their favorite stores can turn to the Goodshop app, a new iOS app with the latest coupons and deals at more than 5,000 online stores. In addition to being a... Read more
Save on 5th generation refurbished iPod touch...
The Apple Store has Apple Certified Refurbished 5th generation iPod touches available starting at $149. Apple’s one-year warranty is included with each model, and shipping is free. Many, but not all... Read more
What Should Apple’s Next MacBook Priority Be;...
Stabley Times’ Phil Moore says that after expanding its iMac lineup with a new low end model, Apple’s next Mac hardware decision will be how it wants to approach expanding its MacBook lineup as well... Read more
ArtRage For iPhone Painting App Free During C...
ArtRage for iPhone is currently being offered for free (regularly $1.99) during Comic-Con San Diego #SDCC, July 24-27, in celebration of the upcoming ArtRage 4.5 and other 64-bit versions of the... Read more
With The Apple/IBM Alliance, Is The iPad Now...
Almost since the iPad was rolled out in 2010, and especially after Apple made a 128 GB storage configuration available in 2012, there’s been debate over whether the iPad is a serious tool for... Read more
MacBook Airs on sale starting at $799, free s...
B&H Photo has the new 2014 MacBook Airs on sale for up to $100 off MSRP for a limited time. Shipping is free, and B&H charges NY sales tax only. They also include free copies of Parallels... Read more
Apple 27″ Thunderbolt Display (refurbished) a...
The Apple Store has Apple Certified Refurbished 27″ Thunderbolt Displays available for $799 including free shipping. That’s $200 off the cost of new models. Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Sr. Project Manager for *Apple* Campus 2 -...
…the design and construction of one building or building components of the New Apple Campus located in Cupertino, CA. They will provide project management oversight for Read more
WW Sales Program Manager, *Apple* Online St...
**Job Summary** Imagine what you could do here. At Apple , great ideas have a way of becoming great products, services, and customer experiences very quickly. Bring Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.