IBM Data Server Client Packages Version 10.1

Building embedded SQL applications written in C or C++ (Windows)

After you have written the source file, you have to build your embedded SQL application.

About this task

Some steps in the build process depend on the compiler that you use. The examples provided with each step of the procedure show how to build an application called myapp with a Microsoft Visual Studio 6.0 compiler, which is a C compiler. You can run each step in the procedure individually or run the steps together within a batch file from a DB2® Command Window prompt. For an example of a batch file that can be used to build the embedded SQL sample applications in the %DB2PATH%\SQLLIB\samples\c\ directory, refer to the %DB2PATH%\SQLLIB\samples\c\bldapp.bat file. This batch file calls another batch file, %DB2PATH%\SQLLIB\samples\c\embprep.bat, to precompile the application and bind the application to a database.

Procedure

  1. Precompile the application by issuing the PRECOMPILE command. For example:
            C application: db2 PRECOMPILE myapp.sqc BINDFILE
            C++ application: db2 PRECOMPILE myapp.sqx BINDFILE

    The PRECOMPILE command generates a .c or .C file, that contains a modified form of the source code in a .sqc or .sqC file, and an application package. If you use the BINDFILE option, the PRECOMPILE command generates a bind file. In the preceding example, the bind file would be called myapp.bnd.

  2. If you created a bind file, bind this file to a database to create an application package by issuing the BIND command. For example:
            db2 bind myapp.bnd

    The BIND command associates the application package with and stores the package within the database.

  3. Compile the modified application source and the source files that do not contain embedded SQL to create an application object file (a .obj file). For example:
           C application: cl -Zi -Od -c -W2 -DWIN32 myapp.c
           C++ application: cl -Zi -Od -c -W2 -DWIN32 myapp.cxx
  4. Link the application object files with the DB2 and host language libraries to create an executable program using the link command. For example:
            link -debug -out:myapp.exe myapp.obj