Databases Reference
In-Depth Information
4.1 Overview
Applications written in the C/C++ programming language can access and
manipulate data in a DB2 database using embedded SQL or through the DB2
Call Level Interface (CLI).
Embedded SQL statements in an application can either be of static or dynamic
type. If the complete SQL statement and all database objects accessed within
the statement are known prior to compile time, then it can be written as a static
SQL statement. Otherwise, if the complete SQL statement or any database
objects accessed within the statement are not known until runtime, then it must
be written as a dynamic SQL statement. Using embedded SQL in an application
requires a precompiler to create its associated package in the database. A
package is a database object and is needed for processing because it holds the
optimized form of an SQL statement.
The DB2 Call Level Interface is an SQL interface that C/C++ applications can
use to interact with DB2. The interface follows the ISO CLI and Microsoft's Open
Database Connectivity (ODBC) standard. In addition, it provides some useful
DB2 Application Programming Interfaces (APIs). Writing C/C++ code to make
use of the CLI interface is an alternative to using embedded dynamic SQL.
Whether a C/C++ application uses embedded static SQL, embedded dynamic
SQL, or the CLI interface is dependent on several factors. If database statistics
do not change much, programs can run faster using embedded static SQL
because source files are precompiled and SQL statements do not need to be
prepared at runtime. However, if database statistics change often, programs can
run faster using embedded dynamic SQL because it uses current database
statistics during runtime. If the application wants to make use of dynamic SQL
processing, or the application will run against different database products, then
using the CLI interface to access DB2 can be the best approach. This is because
you do not need to precompile CLI applications, and, hence, there are no
application bind files that need to be bound to the database. Note that it is
possible for an application to use both embedded static SQL and the CLI
interface (which runs dynamic SQL) by writing a CLI application with static SQL
modules. You need to take all these factors into consideration when coding a
C/C++ application to interact with DB2.
4.1.1 C/C++ development environment setup
Developing C/C++ applications with the DB2 product family requires the DB2
Application Development Client (which is part of the DB2 Client in V9) and a
supported C/C++ compiler.
Search WWH ::




Custom Search