Initialization and termination tasks in a DB2 UDB 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 UDB 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 DB2® UDB CLI. Using handles frees the application from having to allocate and manage global variables or data structures, such as the SQL descriptor area (SQLDA), or SQL communication area (SQLCA) used in embedded SQL interfaces for IBM® Database Management Systems (DBMSs). An application then passes the appropriate handle when it calls other DB2 UDB 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 UDB 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 UDB CLI application.