The DB2 Call-Level Interface (DB2 CLI) is an IBM standard for the DB2 family of database servers. It is tuned up for C/C++ API programming, and it is used for establishing connections, passing dynamic SQL statements, or calling persistent modules (like stored procedures).
DB2 CLI is based on the ODBC specification and the international standard for SQL/CLI, discussed earlier in this chapter. The DB2 CLI driver acts like a comparable ODBC driver, and it conforms to level 2 of ODBC 2.0 and level 1 of the ODBC 3.0. Some features of ODBC 3.0 level-2 conformance are also supported.
Figure 16-6 illustrates the way an application accesses DB2 RDBMS server using the CLI driver, the main difference being that the ODBC driver scenario does not have the additional access layer of the ODBC Driver Manager.
Table 16-4 lists DB2 CLI driver features and ODBC driver for DB2 side by side with the ODBC Standard Specification.
ODBC Features |
DB2 CLI |
DB2 ODBC driver |
---|---|---|
Core level functions |
Implemented. |
Implemented. |
Level 1 functions |
Implemented. |
Implemented. |
Level 2 functions |
Implemented (except for SQLDrivers(), as nonapplicable). |
Implemented. |
Additional DB2 CLI functions |
SQLSetConnection(), |
Implemented all functions; can be accessed by dynamically loading DB2 CLI Library. |
SQL data types |
SQL_BIGINT,
SQL_BINARY,SQL_BLOB,
|
Supports all types listed for DB2 CLI, in addition to the ODBC standard. |
C data types |
SQL_C_BINARY,
SQL_C_BIT,
SQL_C_NUMERIC (supported for Win32 environment only). | |
Return codes |
SQL_SUCCESS,
SQL_SUCCESS_WITH_INFO,
|
Supports all types listed for DB2 CLI, in addition to the ODBC standard. |
SQLSTATES (SQL standard compliance) |
Some codes are not present (e.g., ODBC Type 08S01); otherwise the same as ODBC driver. |
Mapped to X/Open standard SQLSTATES(in addition to the IBM-specific SQLSTATES codes). |
Multiple connections for the client application |
Supported. |
Supported. |
Dynamic loading of driver |
N/A |
Supported. |
The main advantage of using DB2 CLI over embedded SQL is flexibility and convenience. Embedded SQL requires a precompiler to convert SQL Statements into executable code, which must be then bound to the DB2 database. DB2 CLI implementation is not tied to a particular product or environment, resulting in portable code; it is SQL standards (X/Open) compliant, can connect to a multiple databases (so much for the binding concept!), can use dynamic parameters, and, in general, is more suited for GUI (graphical user interface) applications. There is a performance penalty to pay for all this; embedded SQL is inherently faster because it does not go through all the layers of communication and translation.
Compared to DB2 ODBC driver, there's not much difference. True, elimination some of the middleware (ODBC Driver Manager) offers increased speed of execution and fewer environment setup problems (no ODBC Driver Manager). But it comes at the price of more limited set of features, and it relies squarely on IBM implementation (as opposed third-party ODBC drivers for DB2).