Building C and C++ routine code using sample bldrtn scripts
Before you begin
bldrtnscript is located in the following database directories along with the sample programs:
- For C:sqllib/samples/c/
- For C++: sqllib/samples/cpp/
bldrtnscript can be used to build a source code file that contains both procedure and function implementations. The
bldrtnscript performs the following tasks:
- Establishes a connection with a user-specified database
- Precompiles the user-specified source code file
- Binds the package to the current database
- Compiles and links the source code to generate a shared library
- Copies the shared library to the database function directory on the database server
bldrtnscripts accept two arguments:
- The name of a source code file without any file extension
- The name of a database to which a connection is established
The database parameter is optional. If no database name is supplied, the program uses the default sample database. As routines must be built on the same instance where the database resides, no arguments are required for a user ID and password.
- Source code file that contains one or more routine implementations.
- The name of the database within the current database instance in which the routines are to be created.
To build a source code file that contains one or more routine code implementations:
- Open the Db2® command window.
- Copy your source code file into the same directory as the bldrtn script file.
- If the routines will be created in the sample database,
enter the build script name followed by the name of the source code
file without the .sqc or .sqC file
If the routines will be created in another database, enter the build script name, the source code file name without any file extension, and the database name:
bldrtn file-name database-name
bldrtnscript precompiles, compiles, and links the source code and produces a shared library. The script then copies the shared library to the function directory on the database server.
- If this is not the first time that the source code is built, stop and restart the database instance to ensure that the new version of the shared library is used by the database. You can restart the database instance by entering the db2stop command followed by the db2start command.