Transaction processing task in a Db2 for i CLI application
The figure shows the typical order of function calls in a Db2® for i CLI application. The figure does not show all functions or possible paths.
The figure shows the steps and the Db2 for i CLI functions in the transaction processing task. This task contains these steps:
- Allocating statement handles in a Db2 for i CLI application
- Preparing and processing tasks in a Db2 for i CLI application
- Processing results in a Db2 for i CLI application
- Freeing statement handles in a Db2 for i CLI application
- Committing or rolling back in a Db2 for i CLI application
The SQLAllocStmt()
or SQLAllocHandle()
function
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 SQLBindParameter()
function
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 toSQLExecDirect()
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.