DB2 Version 9.7 for Linux, UNIX, and Windows

Building CLI routines on Windows

DB2® provides batch files for compiling and linking CLI programs. These are located in the sqllib\samples\cli directory, along with sample programs that can be built with these files. The batch file bldrtn.bat contains the commands to build CLI routines (stored procedures and user-defined functions). bldrtn.bat creates a DLL on the server. It takes one parameter, represented inside the batch file by the variable %1, which specifies the name of your source file. The batch file uses the source file name for the DLL name.

About this task

To build the spserver DLL from the source file spserver.c:

Procedure

  1. Enter the batch file name and program name:
       bldrtn spserver

    The batch file uses the module definition file spserver.def, contained in the same directory as the CLI sample programs, to build the DLL. The batch file then copies the DLL, spserver.dll, to the server in the path sqllib\function.

  2. 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.

  3. 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 DLL spserver, you can build the CLI client application spclient that calls the routines within it.

You can build spclient by using the script file, bldapp.

To call the routines, 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 DLL, spserver, which executes the routines on the server database. The output is returned to the client application.