IBM DB2 overview - IBM DB2

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.

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.

Supported compilers
DB2 Express-C is currently supported on Linux and Windows platforms. At the time of writing, the following C/C++ compilers are supported.

Supported C/C++ Compiler versions

Supported C/C++ Compiler versions

Setting up the C/C++ environment
To set up the C/C++ environment, follow these steps:

  1. Check C/C++ compiler
    Ensure a supported C/C++ compiler is installed on a DB2 Express-C supported platform. Check Table for a list of supported compiler versions. Refer to the compiler documentation for installation and usage instructions.
  2. Check DB2 installation
    Ensure the development machine has either DB2 Express-C installed (if the database will be accessed locally) or at least the DB2 Application Development Client (if accessing the database remotely). This ensures you have the necessary precompilers and static libraries to develop C/C++ programs. If a DB2 client is installed, ensure that the client machine can connect successfully to the remote server.
  3. Check Windows environment (if applicable)
    On Windows development machines, ensure that the INCLUDE environment variable contains %DB2PATH%\INCLUDE as the first directory ahead of any Microsoft Platform SDK include directories. If this is not the case, you can do the following:
    a. Modify the INCLUDE variable at a command prompt by running the command: set INCLUDE=%DB2PATH%\include;%INCLUDE%
    b. For development using Visual C++, modify the INCLUDE environment variable in the vcvars32.bat file. Move the %INCLUDE% portion to the beginning of the list of Visual C++ directories.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

IBM DB2 Topics