Transaction processing task in a DB2 UDB CLI application
The figure shows the typical order of function calls in a DB2® UDB call level interface (CLI) application. The figure does not show all functions or possible paths. Figure 1. Transaction processing
The figure shows the steps and the DB2 UDB CLI functions in the transaction processing task. This task contains these steps:
- Allocating statement handles in a DB2 UDB CLI application
- Preparing and processing tasks in a DB2 UDB CLI application
- Processing results in a DB2 UDB CLI application
- Freeing statement handles in a DB2 UDB CLI application
- Committing or rolling 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.
- Allocating statement handles in a DB2 UDB CLI application
SQLAllocStmt() allocates a statement handle. A statement handle refers to the data object that contains information about an SQL statement that is managed by DB2 UDB call level interface (CLI).
- Preparing and processing tasks in a DB2 UDB CLI application
After a statement handle has been allocated, there are two methods of specifying and running SQL statements.
- Processing results in a DB2 UDB CLI application
The next step after the statement has been processed depends on the type of SQL statement.
- Freeing statement handles in a DB2 UDB CLI application
SQLFreeStmt() ends processing for a particular statement handle.
- Committing or rolling back in a DB2 UDB CLI application
The last step for the transaction processing task is to either commit or roll back the transaction using SQLTransact().
Parent topic:
Writing a DB2 UDB CLI application