ALLBASE/SQL Pascal Application Programming Guide: HP 3000 MPE/iX Computer Systems > Chapter 1 Getting Started with ALLBASE/SQL Pascal ProgrammingThe ALLBASE/SQL Pascal Preprocessor |
|
The preprocessor ignores Pascal constructs in your source code, but generates Pascal constructs, based on the embedded SQL commands in your code. Figure 1-2 “Preprocess-Time Events” summarizes the four main preprocess-time events:
The Pascal preprocessor scans the source code for SQL commands. If the syntax of an SQL command is valid, the preprocessor converts the command into compilable Pascal constructs that call ALLBASE/SQL external procedures at run time. During preprocessing, for example, ALLBASE/SQL converts the following SQL command:
The preprocessor produces the following converted modified source code constructs:
The embedded SELECT command has been converted into a Pascal comment, and Pascal constructs that enable ALLBASE/SQL to execute the SELECT command at run time have been inserted. The names that appear in the inserted Pascal code identify variables used by the ALLBASE/SQL external procedures; in this example, the names identify variables used by the SQLXFET external procedure. Some of these variables are derived from host variables. As shown in the embedded SELECT command above, you precede a host variable with a colon when you use it in SQL commands:
Type declarations used by preprocessor generated code are defined and initialized in the include files the preprocessor creates:
The preprocessor inserts $INCLUDE directives that reference these files in the Declaration part of the modified source code:
The chapter, "Using the ALLBASE/SQL Pascal Preprocessor," explains how the SQLEXTN file is derived.
When you invoke the preprocessor, you name an ALLBASE/SQL DBEnvironment. The preprocessor starts a DBE session for that DBEnvironment when preprocessing begins and terminates that session when preprocessing is completed. When the preprocessor encounters a syntactically correct SQL command, it usually creates a section and stores it in the system catalog of the DBEnvironment being accessed. An ALLBASE/SQL section is a group of stored ALLBASE/SQL instructions for executing one SQL command. All sections created during a preprocessing session constitute a module. The preprocessor derives the name of the module from the program heading unless you supply a different name when you invoke the preprocessor:
The main program and the subprograms that comprise an application must each have a unique name. And no two modules should have the same name. When the preprocessor terminates its DBEnvironment session, it issues a COMMIT WORK command if it encountered no errors. Created sections are stored in the system catalog and associated with the module name. A section consists of ALLBASE/SQL instructions for executing an SQL command. Not every SQL command requires a section. For each SQL command that does require a section, the preprocessor creates the section and assigns to it a unique reference number. In the following generated code, SQLSECNUM contains the number of the stored section.
A section serves the following two purposes:
By creating and storing sections at preprocessing time rather than at run time, runtime performance is improved. A section is assigned one of two states at preprocessing time: valid or invalid. A section is valid when access validation criteria are satisfied. If the SQL command references objects that exist at preprocessing time and the individual doing the preprocessing is authorized to issue the command, the stored section is marked as valid. A section is invalid when access validation criteria are not satisfied. If the SQL command references an object that does not exist at preprocessing time or if the individual doing the preprocessing is not authorized to issue the command, the stored section is marked as invalid. After being stored by the preprocessor, a valid section is marked as invalid when such activities as the following occur:
At run time, ALLBASE/SQL executes valid sections and attempts to validate any section marked as invalid. If an invalid section can be validated, as when an altered table does not affect the results of a query, ALLBASE/SQL marks the section as valid and executes it. If an invalid section cannot be validated, as when a table reference is invalid because the table owner name has changed, ALLBASE/SQL returns an error indication to the application program. When a section is validated at run time, it remains in the valid state until an event that invalidates it occurs. The program execution during which validation occurs is slightly slower than program executions following validation. |