Building CLI stored procedures with configuration files
The configuration file, clis.icc
, in sqllib/samples/cli
,
allows you to build CLI stored
procedures.
Procedure
To use the configuration file to build the CLI stored
procedure spserver
from the source file spserver.c
:
- Set the CLIS environment variable to the program name by
entering:
export CLIS=spserver
- If you have a
clis.ics
file in your working directory, produced by building a different program with theclis.icc
file, delete theclis.ics
file with this command:
An existingrm clis.ics
clis.ics
file produced for the same program you are going to build again does not have to be deleted. - Compile the sample program by entering:
vacbld clis.icc
Note: Thevacbld
command is provided by VisualAge® C++. - The stored procedure is copied to the server in the path sqllib/function
Next, catalog the stored procedures by running the
spcreate.db2
script on the server. First, connect to the database with the user ID and password of the instance where the database is located:
If the stored procedures were previously cataloged, you can drop them with this command:db2 connect to sample userid password
Then catalog them with this command:db2 -td@ -vf spdrop.db2
Then, stop and restart the database to allow the new shared library to be recognized. If necessary, set the file mode for the shared library so the Db2® instance can access it.db2 -td@ -vf spcreate.db2
Once you build the stored procedure
spserver
, you can build the CLI client applicationspclient
that calls the stored procedure. You can buildspclient
by using the configuration file,cli.icc
.To call the stored procedure, run the sample client application by entering:
spclient
database userid passwordwhere- database
- Is the name of the database to which you want to connect. The
name could be
sample
, or its remote alias, or some other name. - userid
- Is a valid user ID.
- password
- Is a valid password.
The client application accesses the shared library,
spserver
, and executes a number of stored procedure functions on the server database. The output is returned to the client application.