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:

  1. Set the CLIS environment variable to the program name by entering:
       export CLIS=spserver
  2. If you have a clis.ics file in your working directory, produced by building a different program with the clis.icc file, delete the clis.ics file with this command:
       rm clis.ics
    An existing clis.ics file produced for the same program you are going to build again does not have to be deleted.
  3. Compile the sample program by entering:
       vacbld clis.icc
    
    Note: The vacbld command is provided by VisualAge® C++.
  4. 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:
       db2 connect to sample userid password
    If the stored procedures were previously cataloged, you can drop them with this command:
       db2 -td@ -vf spdrop.db2
    Then catalog them with this command:
       db2 -td@ -vf spcreate.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.

    Once you build the stored procedure spserver, you can build the CLI client application spclient that calls the stored procedure. You can build spclient by using the configuration file, cli.icc.

    To call the stored procedure, 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 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.