Databases Reference
In-Depth Information
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.
4.2 Building a C/C++ application using embedded SQL
The steps involved in building a C/C++ application with embedded SQL are:
1. Create C/C++ source files containing programs with embedded SQL
statements. The extension of a source file is dependent on the platform and
host language (C or C++). The possible file extensions are discussed in 4.3.2,
“Precompiler source file extensions” on page 153.
2. Connect to the database, and precompile each source file using the DB2
PREP or PRECOMPILE command.
Depending on the file extension, either the C or C++ precompiler is invoked.
The precompiler generates modified source files containing C/C++ language
calls for the SQL statements. Depending on the options specified, packages
corresponding to the embedded SQL statements in the source files can be
created in the database, or bind files containing information about how to
create the packages can be produced.
3. Compile the modified source files (and other files without SQL statements)
using the C compiler.
4. Using the object files created from the compilation, link the files with DB2
UDB and C libraries to produce an executable program.
5. If packages were not created at precompile time (or if a different database is
to be accessed) and bind files were created, the bind files are bound against
the database.
6. Run the application.
For our example, assume we finished our C inventory program named
inventory.sqc on a Windows system using Visual C++. To precompile the
program, we can run the following statement shown in Example 4-1.
Example 4-1 Output from running the PREP command
db2 prep inventory.sqc
LINE MESSAGES FOR inventory.sqc
-------------------------------------------------------------------
SQL0060W The "C" precompiler is in progress.
SQL0091W Precompilation or binding was ended with "0"
errors and "0" warnings.
Search WWH ::




Custom Search