Transaction processing task in a DB2 UDB CLI application

This topic shows a typical order of function calls in a DB2® UDB CLI application.

The typical order of function calls in a DB2 UDB CLI application is shown in the following figure. The figure does not show all functions or possible paths.
Figure 1. Transaction processing
Transaction Processing
The figure shows the steps and the DB2 UDB CLI functions in the transaction processing task. This task contains these steps:
  1. Allocate statement handle(s) in a DB2 UDB CLI application
  2. Preparation and processing tasks in a DB2 UDB CLI application
  3. Processing results in a DB2 UDB CLI application
  4. Free statement handles in a DB2 UDB CLI application
  5. Commit or roll back in a DB2 UDB CLI application

The function SQLAllocStmt is needed to obtain a statement handle that is used to process the SQL statement. There are two methods of statement processing that can be used. By using SQLPrepare and SQLExecute, the program can break the process into two steps. The function SQLBindParameter is used to bind program addresses to host variables used in the prepared SQL statement. The second method is the direct processing method in which SQLPrepare and SQLExecute are replaced by a single call to SQLExecDirect.

As soon as the statement is processed, the remaining processing depends on the type of SQL statement. For SELECT statements, the program uses functions like SQLNumResultCols, SQLDescribeCol, SQLBindCol, SQLFetch, and SQLCloseCursor to process the result set. For statements that update data, SQLRowCount can be used to determine the number of affected rows. For other types of SQL statements, the processing is complete after the statement is processed. SQLFreeStmt is then used in all cases to indicate that the handle is no longer needed.