DB2® provides
build scripts for compiling and linking DB2 Call
Level Interface (CLI)
programs.
These are located in the sqllib/samples/cli directory,
along with sample programs that can be built with these files. The
script file bldrtn contains the commands to build CLI routines
(stored procedures and user-defined functions). bldrtn creates
a shared library on the server. It takes a parameter for the source
file name, represented inside the script file by the variable $1.
About this task
To build the sample program
spserver from
the source file
spserver.c:
Procedure
- Enter the build script name and program name:
bldrtn spserver
The
script file copies the shared library to the sqllib/function directory.
- Next, catalog the routines by running the spcat script
on the server:
spcat
This
script connects to the sample database, uncatalogs the routines if
they were previously cataloged by calling spdrop.db2,
then catalogs them by calling spcreate.db2, and finally
disconnects from the database. You can also call the spdrop.db2 and spcreate.db2 scripts
individually.
- Then, unless this is the first time the shared library
was built, stop and restart the database to allow the new version
of the shared library to be recognized. If necessary, set the
file mode for the shared library so the DB2 instance
can access it.
Results
Once you build the shared library,
spserver,
you can build the
CLI client
application,
spclient, that calls the routines within
the shared library.
The client application can be built
like any other CLI client
application by using the script file, bldapp.
To
access the shared library, run the sample client application by entering:
spclient database
userid password
where
- database
- Is the name of the database to which you want to connect.
The name could be sample, or its alias, or
another database name.
- userid
- Is a valid user ID.
- password
- Is a valid password.
The client application accesses the shared library, spserver,
and executes the routines on the server database. The output is returned
to the client application.