Databases Reference
In-Depth Information
4.5.1 CLI header files
To begin a CLI program, we need to ensure one of the following header files is
included:
sqlcli.h - Contains CLI constants, function prototypes and data structures
sqlcli1.h - Contains everything in sqlcli.h as well as SQL extensions in sqlext.h
4.5.2 Allocating handles
There are various CLI APIs we can use to allocate different types of handles.
Refer to DB2 documentation for the syntax of each API. In Table 4-6, we list the
APIs.
Table 4-6 APIs to allocate handles
CLI API
Purpose
SQLAllocEnv
Get an environment handle.
SQLAllocConnect
Get a connection handle.
SQLAllocHandle
Get a handle.
SQLAllocStmt
Get a statement handle.
Note: SQLAllocEnv(), SQLAllocConnect(), and SQLAllocStmt() are all ODBC
2.0 APIs and are deprecated. These APIs should be replaced by
SQLAllocHandle.
We use SQLAllocHandle in our sample CLI application.
This is the syntax of the function, as outlined in the DB2 documentation:
SQLRETURN SQLAllocHandle (
SQLSMALLINT HandleType, /* fHandleType */
SQLHANDLE InputHandle, /* hInput */
SQLHANDLE *OutputHandlePtr); /* *phOutput */
In the above syntax, HandleType is the type of handle, InputHandle is the
context for the new handle, and OutputHandlePtr is a buffer storing the newly
allocated handle data structure.
To begin the application, we need to define and allocate an environment and
connection handle. Example 4-31 on page 184 illustrates how to do this. We
declare two variables to store the data structure of the handles and then call the
SQLAllocHandle() API. When environment handles are allocated, there is no
 
Search WWH ::




Custom Search