1077-1080

Previous Table of Contents Next

Page 1077

CHAPTER 47

Using SQLWindows

IN THIS CHAPTER

  • Connecting to the Database 1078
  • Communicating with the Database 1079

Page 1078

SQLWindows is an object-oriented development tool for Microsoft Windows that is most easily distinguished from its competition by its unique programming interface. SQLWindows Application Language, or SAL, uses an outline structure that is unlike any tool of its kind. The application outline represents the hierarchy of constants, variables , and objects within the application by placing them at different levels of indentation within the outline structure. At each level, the outline can be expanded or collapsed , in order to view details or hide levels of detail when navigating to a particular section.

In addition to a unique language and programming structure, SQLWindows provides several means of communicating with an ODBC data source, both programmatically and through bound controls. This chapter focuses on these aspects of the product, including QuickObjects and the SAL programming interface to ODBC. In addition, a brief overview of the object-oriented features of SQLWindows is provided.

Connecting to the Database

SQLWindows can only connect using the Q+E drivers supplied with the product. These drivers should be installed with SQLWindows and the SQLBase desktop database engine. You can use Quest, the interactive querying, reporting, and data source configuration tool included with SQLWindows, to configure a new ODBC data source and ensure that it is accessible by SQLWindows.

After launching Quest, select ODBC from the Utilities menu. The dialog box displayed is the Data Sources dialog box of the ODBC administration program. You can use this dialog box to define a new data source in ODBC.INI, and data sources defined here will be available to all applications.

Next, add the data source to the Quest desktop by selecting Add from the Database option of the Utilities menu. The Add Database dialog box will present a list of defined ODBC data sources. Click on the name of the data source to be added, and enter a user ID and password in the appropriate fields. When adding an Oracle data source to the list of Quest databases, the dialog box might appear as in Figure 47.1.

Figure 47.1.
The Quest Add
Database dialog box.

Page 1079

Click on OK to add the selected data source to Quest's list. You can use Quest to create and save queries and reports and to view catalog information, such as table definitions. Try viewing a small table to test the connection. If data can be accessed through Quest, it can be accessed through SQLWindows QuickObjects and SAL SQL functions as well.

Communicating with the Database

The easiest way to communicate with a database through SQLWindows is to use QuickObjects. There are three main categories of QuickObjects: visualizers, commanders, and the data source. Visualizers and commanders are data-aware controls that tie a window control to values stored in the database. A data source is used to connect to the database and provide data to bound controls. To place a data source on the form, click on the Quest icon on the tool palette, and select cQuickDatabase as the class. The object should appear on the form as in Figure 47.2.

Figure 47.2.
A cQuickDatabase
object that will be used
as a data source.

After placing the new data source on the form, click on table or query to choose the means by which it will be populated . If a query is selected, a new query can be defined, or a file containing the prewritten SQL can be identified. Alternatively, a cQuickTable object can be used as the data source. The primary difference between a cQuickTable and a cQuickDatabase object that is using a table as its data source is the default display format. A cQuickTable defaults to table display type, while a cQuickDatabase object defaults to the VCR button format, which displays a single record at a time.

SQLWindows refers to bound controls that display data as Visualizers. After defining the result set for the data source, Visualizers can be placed on the form and bound to columns in the data source. The simplest of the Visualizers is the data field. To create a bound data field, select the data field icon on the tool palette and select cQuickField as the class. When cQuickField is

Page 1080

clicked in the class window of the tool palette, a drop-down list box appears in the lower portion of the tool palette. Select the name of the data source from the drop-down list, and in the list of columns below, select the name of the column to which the data field will be bound. Other controls can be used as Visualizers. Radio buttons or drop-down list boxes can be bound to description columns of lookup tables, check boxes can be bound to columns containing Boolean values, and list boxes and multiline edits can be bound to columns to display data.

Commanders, in SQLWindows terminology, refer to pushbutton classes of QuickObjects that perform operations on a data source. To create a new Commander, click on the pushbutton icon on the tool palette, select the data source name from the drop-down list, and select from the list of Commander types. This creates an object of type cQuickCommander. These include First, Last, Next, Prev, and Retrieve. The first four are used to position the record pointer, and the last is used to fetch the row at the current record position.

The additional methods New, Apply, Delete, and Discard can be used to edit the record set. As is typically the case with bound controls, it is probably not advisable to use these methods when accessing a remote database through ODBC. The lack of control over the transaction and SQL that is prepared adds a considerable amount of risk to this method of applying transactions.

The SAL programming language provides functions for communicating with the database that are very similar to the underlying ODBC API. In addition, it provides numerous system variables and abstract datatypes to make the API easier to use. Connecting to the database, for example, requires that three system variables be set, followed by a single function call (SqlConnect). The system variables SqlDatabase, SqlUser, and SqlPassword must be set to the name of the ODBC data source, the user ID, and the password, respectively. SqlConnect takes a single argument, the buffer that will receive the new connection handle if the function succeeds. SqlConnect returns TRUE if it succeeds, FALSE if it fails. The example in Listing 47.1 uses SAL to establish a database connection by taking values from a login form and an initialization file to connect to the data source.

Listing 47.1. This code fragment uses SAL to connect to an ODBC data source.

 Contents     Pushbutton:pbOK         Message Actions             On SAM_Click                iLen = SalGetProfileString("ORACLE TEST", "DSN",                       "ORACLE", szTmpBuf, "TEST.INI")                Set SqlDatabase = SalStrLeft(szTmpBuf, iLen)                Set SqlUser = dfUser                Set SqlPassword = dfPassword                bSuccess = SqlConnect(hSQLMain)                If (bSuccess = FALSE)                    Call SalMessageBox("Unable To Connect.",                         "Oracle Test", 0) Window Variables     Sql Handle: hSQLMain    Boolean: bSuccess 
Previous Table of Contents Next


Oracle Unleashed
Oracle Development Unleashed (3rd Edition)
ISBN: 0672315750
EAN: 2147483647
Year: 1997
Pages: 391

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net