 |
» |
|
|
 |
In every ALLBASE/SQL C program, you embed SQL commands
in the declaration part and the procedure part of your program to carry
out specific tasks.
The program listing shown in Figure 1-8 “Program cex2: Using Simple SELECT”
illustrates where in a program
you can embed SQL commands to accomplish the tasks listed below.
Figure 1-7 “Runtime Dialog of Program cex2” shows the runtime dialog for the program. - 1
Declare the SQL Communications Area (sqlca). The sqlca is an ALLBASE/SQL data structure that contains current information
about a program's DBE session. Every ALLBASE/SQL C program must contain an
sqlca declaration in the global declaration section. Use the following
command:
- 2
Declare host variables. All host variables used in a program must be declared in a declaration
part. You can put more than one such declaration section in a program,
but all host variables must be declared between the BEGIN and END
DECLARE SECTION commands. - 3
Display error and warning messages
from the ALLBASE/SQL message catalog. You can display messages for any errors encountered
in execution as shown in the SQLStatusCheck function. Complete details
about error and message handling are presented in the chapter, "Runtime Status Checking and the sqlca." - 4
Start a DBE session. In most application programs, you embed the CONNECT command to start a
DBE session. This command must be executed before you can access the
DBEnvironment - 5
Check the status of SQL command execution. Your program should check for the success or failure of execution of
each SQL command, as shown in the example program. - 6
Terminate the DBE session. You use the RELEASE command or the RELEASE option of the COMMIT WORK
command to end a DBE session. - 7 and
Define transactions. - 8
You define transactions in a program to control concurrency and
consistency in your database access. The transaction is bounded by the
BEGIN WORK and COMMIT WORK or ROLLBACK WORK commands. When a COMMIT
WORK is successfully executed, all operations performed by the
transaction it ends are permanently committed to the DBEnvironment - 9
Define or manipulate data in the DBEnvironment. Nearly all programs access data in one or more databases.
The SELECT command shown in the example program retrieves the row from
PurchDB.Parts that contains a part number matching the value in the host
variable named in the WHERE clause. Note, indicator variables such
as SalesPriceInd are discussed in the chapter, "Host Variables," and data manipulation
is presented fully in Chapters 5 through 8.
|