Initialization and termination tasks in a Db2 for i CLI application

The initialization task allocates and initializes environment handles and connection handles.

The following figure shows the function call sequences for both the initialization and termination tasks. The transaction processing task in the middle of the diagram is shown in Transaction processing task in a Db2 for i CLI application.

Figure 1. Conceptual view of initialization and termination tasks
Conceptual view of initialization and termination task
The termination task frees handles. A handle is a variable that refers to a data object that is controlled by CLI. . Using handles frees the application from having to allocate and manage global variables or data structures, such as descriptor areas, or the SQL Diagnostic Area used in embedded SQL interfaces for IBM® Database Management Systems (DBMSs). An application then passes the appropriate handle when it calls other Db2 for i CLI functions. Here are the types of handles:
Environment handle
The environment handle refers to the data object that contains global information regarding the state of the application. This handle is allocated by calling SQLAllocEnv(), and freed by calling SQLFreeEnv(). An environment handle must be allocated before a connection handle can be allocated. Only one environment handle can be allocated per application.
Connection handle
A connection handle refers to a data object that contains information that is associated with a connection that is managed by Db2 for i CLI. This includes general status information, transaction status, and diagnostic information. Each connection handle is allocated by calling SQLAllocConnect() and freed by calling SQLFreeConnect(). An application must allocate a connection handle for each connection to a database server.
Statement handle
Statement handles are discussed in Transaction processing task in a Db2 for i CLI application.
Descriptor handle
A descriptor handle is available for applications that want to use certain CLI functions for reading and modifying individual bound parameter attributes on a API call basis for statements that have parameters or result sets associated with them. These functions can be used as alternatives to SQLBindCol() and SQLBindParameter() functions. See SQLGetDescField(), SQLGetDescRec(), SQLSetDescField(), and SQLSetDescRec() functions for more information.