Databases Reference
In-Depth Information
This will produce a modified source file named inventory.c and a package in the
database.
Alternatively, we can create a bind file and later bind the file to manually create a
package. This is known as deferred binding . We can accomplish this by using
the BINDFILE option in the PRECOMPILE command.
Example 4-2 Basic statements to create a bind file and package
db2 prep inventory.sqc BINDFILE
db2 bind inventory.bnd
After precompiling, we need to compile the modified source file. We can do this
on the Windows system by running the command:
cl -Zi -Od -c -W2 inventory.c
This produces an object file named inventory.obj . We can then create an
executable file named inventory.exe by running the command:
link -debug -out:inventory.exe inventory.obj db2api.lib
Depending on your compiler and the options you set, the commands for
compiling and linking will be different.
4.2.1 Host variables and parameter markers
In a static SQL statement, the complete SQL statement along with the type and
length of the data requested is known at precompile time. The only missing
information is the actual data values for the SQL statement. Acting as
placeholders for the missing data, host variables need to be defined by the
application to represent the remaining information in the SQL statement. Host
variables are represented by prefixing a colon (:) in front of the variable name.
For a dynamic SQL statement, parameter markers are represented as a question
mark (?) for any variable information in an SQL statement.
4.3 A simple C inventory program using embedded SQL
To illustrate the basic fundamentals of building a C/C++ application, let us
develop a simple C inventory program for a company to store inventory
information about its products, and the associated quantity and location of each
product.
Search WWH ::




Custom Search