This section explains how to use MIPSpro C with the following kinds of DB2 interfaces:
The script file bldccapi, in sqllib/samples/c, contains the commands to build a DB2 API program. The parameter, $1, specifies the name of your source file.
#! /bin/ksh # bldccapi script file # Builds a DB2 API program # Usage: bldccapi <prog_name> # Set DB2PATH to where DB2 will be accessed. # The default is the standard instance path. DB2PATH=$HOME/sqllib # Compile the util.c error-checking utility. cc -I$DB2PATH/include -c util.c # Compile util.c for n32 object type support. # cc -n32 -I$DB2PATH/include -c util.c # Compile the program. cc -I$DB2PATH/include -c $1.c # Compile the program for n32 object type support. # cc -n32 -I$DB2PATH/include -c $1.c # Link the program. cc -o $1 $1.o util.o -L$DB2PATH/lib -rpath $DB2PATH/lib -lm -ldb2 # Link the program for n32 object type support # cc -n32 -o $1 $1.o util.o -L$DB2PATH/lib32 -rpath $DB2PATH/lib32 -lm -ldb2 |
Compile and Link Options for bldccapi |
---|
The script file contains the following compile options:
|
The script file contains the following link options:
Refer to your compiler documentation for additional compiler
options.
|
To build the sample program client from the source file client.c , enter:
bldccapi client
The result is an executable file, client. To run the executable file against the sample database, enter:
client userid password
where
The script file bldcli in sqllib/samples/cli contains the commands to build a DB2 CLI program. The parameter, $1, specifies the name of your source file.
#! /bin/ksh # bldcli script file -- Silicon Graphics IRIX # Builds a CLI program with MIPSpro C. # Usage: bldcli <prog_name> # Set DB2PATH to where DB2 will be accessed. # The default is the instance path. DB2PATH=$HOME/sqllib # Compile the error-checking utility. cc -I$DB2PATH/include -c samputil.c # Compile the utility for n32 object type support. # cc -n32 -I$DB2PATH/include -c samputil.c # Compile the program. cc -I$DB2PATH/include -c $1.c # Compile the program for n32 object type support. # cc -n32 -I$DB2PATH/include -c $1.c # Link the program. cc -o $1 $1.o samputil.o -L$DB2PATH/lib -rpath $DB2PATH/lib -lm -ldb2 # Link the program for n32 object type support. # cc -n32 -o $1 $1.o samputil.o -L$DB2PATH/lib32 -rpath $DB2PATH/lib32 -lm -ldb2 |
Compile and Link Options for bldcli |
---|
The script file contains the following compile options:
|
The script file contains the following link options:
Refer to your compiler documentation for additional compiler
options.
|
To build the sample program basiccon from the source file basiccon.c , enter:
bldcli basiccon
The result is an executable file basiccon. You can run the executable file by entering:
basiccon userid password
where
Stored procedures are programs that access the database and return information to the client application. You compile and store stored procedures on the server. The server runs on another platform.
To build the DB2 CLI stored procedure outsrv2 on a DB2-supported platform server, refer to the "Building Applications" chapter for that platform in this book. For other servers accessible by DB2 clients, see "Supported Servers".
Once you build the stored procedure outsrv2, you can build the client application that calls the stored procedure, outcli2, from the source file outcli2.c , by using the script file bldcli. Refer to "DB2 CLI Applications" for details.
To call the stored procedure, run the client application by entering:
outcli2 remote_database userid password
where
The client application passes a variable to the server program outsrv2, which gives it a value, and then returns the variable to the client application.
User-defined functions (UDFs) are your own scalar and table functions that you compile and store on the server. The server runs on another platform. To build the user-defined function program, udf , on a DB2-supported platform server, refer to the "Building Applications" chapter for that platform in this book. For other servers accessible by DB2 clients, see "Supported Servers".
Once you build udf, you can build the DB2 CLI client application, calludf, that calls it, from the calludf.c source file in sqllib/samples/cli, using the DB2 CLI script file bldcli. Refer to "DB2 CLI Applications" for details.
To call the UDF program, run the calling application by entering:
calludf userid password
where
The calling application calls functions from the udf library.
The script file bldcc, in sqllib/samples/c, contains the commands to build an embedded SQL program.
The first parameter, $1, specifies the name of your source file. The second parameter, $2, specifies the name of the database to which you want to connect. The third parameter, $3, specifies the user ID for the database, and $4, specifies the password. Only the first parameter, the source file name, is required. Database name, user ID, and password are optional. If no database name is supplied, the program uses the default sample database.
#! /bin/ksh # bldcc script file # Builds a sample C program containing embedded SQL # Usage: bldcc <prog_name> [ <db_name> [ < userid> <password> ]] # Set DB2PATH to where DB2 will be accessed. # The default is the instance path. DB2PATH=$HOME/sqllib # Connect to a database. if (($# < 2)) then db2 connect to sample elif (($# < 3)) then db2 connect to $2 else db2 connect to $2 user $3 using $4 fi # Precompile the program. db2 prep $1.sqc bindfile # Bind the program to the database. db2 bind $1.bnd # Disconnect from the database. db2 connect reset # Compile the util.c error-checking utility. cc -I$DB2PATH/include -c util.c # Compile util.c for n32 object type support. # cc -n32 -I$DB2PATH/include -c util.c # Compile the program. cc -I$DB2PATH/include -c $1.c # Compile the program for n32 object type support. # cc -n32 -I$DB2PATH/include -c $1.c # Link the program. cc -o $1 $1.o util.o -L$DB2PATH/lib -rpath $DB2PATH/lib -lm -ldb2 # Link the program for n32 object type support. # cc -n32 -o $1 $1.o util.o -L$DB2PATH/lib32 -rpath $DB2PATH/lib32 -lm -ldb2 |
Compile and Link Options for bldcc |
---|
The script file contains the following compile options:
|
The script file contains the following link options:
Refer to your compiler documentation for additional compiler
options.
|
To build the sample program updat from the source file updat.sqc , enter:
bldcc updat remote_database userid password
where
The result is an executable file, updat. To run the executable file against the sample database, enter:
updat userid password
where
Stored procedures are programs that access the database and return information to the client application. You compile and store stored procedures on the server. The server runs on another platform.
To build the embedded SQL stored procedure outsrv on a DB2-supported platform server, refer to the "Building Applications" chapter for that platform in this book. For other servers accessible by DB2 clients, see "Supported Servers".
Once you build the stored procedure outsrv, you can build the client application that calls the stored procedure. You can build outcli from the source file outcli.sqc , by using the script file bldcc. Refer to "Embedded SQL Applications" for details.
To call the stored procedure, run the client application by entering:
outcli remote_database userid password
where
The client application passes a variable to the server program, outsrv, which gives it a value, and then returns the variable to the client application.
User-defined functions (UDFs) are your own scalar and table functions that you compile and store on the server. The server runs on another platform. To build the user-defined function program, udf , on a DB2-supported platform server, refer to the "Building Applications" chapter for that platform in this book. For other servers accessible by DB2 clients, see "Supported Servers".
Once you build udf, you can build the embedded SQL client application, calludf, that calls it, from the calludf.sqc source file in sqllib/samples/c using the script file bldcc. Refer to "Embedded SQL Applications" for details.
To call the UDF program, run the calling application by entering:
calludf userid password
where
The calling application calls functions from the udf library.
Multi-threaded applications on Silicon Graphics IRIX need to be linked with the POSIX threads version of the DB2 library for either the o32 or n32 object types, using the -ldb2_th link option.
The script file bldccmt, in sqllib/samples/c, contains the commands to build an embedded SQL multi-threaded program. If you want to build a DB2 API or DB2 CLI multi-threaded program, comment out the connect, precompile, bind, and disconnect commands. For DB2 CLI, also substitute the samputil.c and samputil.o files for util.c and util.o.
The first parameter, $1, specifies the name of your source file. The second parameter, $2, specifies the name of the database to which you want to connect. The third parameter, $3, specifies the user ID for the database, and $4, specifies the password. Only the first parameter, the source file name, is required. Database name, user ID, and password are optional. If no database name is supplied, the program uses the default sample database.
#! /bin/ksh # bldccmt script file -- Silicon Graphics IRIX # Builds a multi-threaded C program containing embedded SQL # Usage: bldccmt <prog_name> [ <db_name> [ <userid> <password> ]] # Set DB2PATH to where DB2 will be accessed. # The default is the instance path. DB2PATH=$HOME/sqllib # Connect to a database. if (($# < 2)) then db2 connect to sample elif (($# < 3)) then db2 connect to $2 else db2 connect to $2 user $3 using $4 fi # Precompile the program. db2 prep $1.sqc bindfile # Bind the program to the database. db2 bind $1.bnd # Disconnect from the database. db2 connect reset # Compile the util.c error-checking utility. cc -I$DB2PATH/include -c util.c # Compile util.c for n32 object type support. # cc -n32 -I$DB2PATH/include -c util.c # Compile the program. cc -I$DB2PATH/include -c $1.c # Compile the program for n32 object type support. # cc -n32 -I$DB2PATH/include -c $1.c # Link the program. cc -o $1 $1.o util.o -L$DB2PATH/lib -rpath $DB2PATH/lib -lm -ldb2_th # Link the program for n32 object type support. # cc -n32 -o $1 $1.o util.o -L$DB2PATH/lib32 -rpath $DB2PATH/lib32 -lm -ldb2_th |
Besides the -ldb2_th link option, discussed above, the other compile and link options are the same as those used for the embedded SQL script file, bldcc. For information on these options, see "Embedded SQL Applications".
To build the sample program, thdsrver, from the source file thdsrver.sqc , enter:
bldccmt thdsrver
The result is an executable file, thdsrver.
To run the executable file against the sample database, enter the executable name:
thdsrver