Writing an ESQL Application
Once you determine your application objectives and design how it interacts with your SQL database(s), you are ready to begin coding your ESQL application. These are typical steps to implement an ESQL session using Progress/ESQL:
- Declare the C variables that you need for your application, including those needed to execute ESQL statements and return error conditions.
- Declare the actions that the program takes when ESQL statements execute with exceptional conditions.
- Log into the ESQL-LIB interface to begin your ESQL session using the
sqllogin()
function.- Execute additional ESQL-LIB functions and Progress/ESQL statements to connect databases, invoke SQL statements, and disconnect databases.
- Log out of the ESQL-LIB interface to end your ESQL session using the
sqllogout()
function.Figure 2–1 illustrates these steps with a sample ESQL application written to query the sports database using static ESQL.
NOTE: For simplicity, this example assumes that all database connection parameters are specified on the command line and acted on bysqllogin()
as part of Step 3. However, a more flexible approach is to control database access from within the application by selectively connecting and disconnecting databases using the ESQL-LIB functions,sqlconn()
andsqldiscon()
. For more information, see the section "Starting and Ending an ESQL Session."
Figure 2–1: Sample ESQL Application (Not Preprocessed)
- ESQL requires the SQLCODE or SQLSTATE variable declaration to return error codes to your application.
- The application specifies a branching label to handle error conditions. In general, you declare any label for error branching in each function that contains ESQL statements.
- As part of the login process, ESQL connects to the database using Progress startup parameters from the command line passed in
argv
.- The backslash (\) in cust\-num is required to specify hyphenated identifiers, because SQL does not permit the hyphenated identifiers that are allowed in Progress. However, you can preprocess and execute your application with the ESQL No Padding (-esqlnopad) startup parameter to avoid this restriction. The application also defines a standard exit point (done1) to terminate loops that operate on rows. The variable names, nam and custnum , are preceded by a colon (:).
- The application logs out of Progress for both error returns (at err) and normal returns (at done1).
Figure 2–2 shows the same application module after it is preprocessed.
Figure 2–2: Sample ESQL Application (Preprocessed)
A practical ESQL application typically includes much more SQL than this, but these fundamental steps form the backbone of any ESQL application. The remaining sections in this chapter explain the techniques available to expand and modify this basic approach.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |