IBM Books

Building Applications for UNIX** Environments


Chapter 3. Introduction to Embedded SQL Applications

Each DB2 SDK includes sample programs that embed SQL statements. Chapters 4 through 6 explain how to build the sample programs for the supported compilers using script files supplied with the DB2 SDK for that platform. You can also use the makefiles that are supplied. Both the makefiles and the script files show you the compiler options you can use. These options are defined for each platform's supported compilers in the appropriate chapter. You might need to modify the options for your environment.

When you run a script file to build a sample program containing embedded SQL, the script file executes the following steps:

For User-Defined Functions (UDFs), you do not need to connect to a database or precompile and bind the program.
Note:The chapters on using embedded SQL show you just some of the script files. The directories that contain the sample programs contain all the script files, as well as a README file which may contain additional information about them.

Sections in these chapters also list the steps you can follow to build and run the sample programs shown in Table 7 using the supported programming languages. The steps you follow might vary, depending on your environment:

Table 7. Sample Programs Referred to in Script Files
Sample Program Name Program Description
updat Demonstrates the use of static SQL to update a database.
outsrv Demonstrates stored procedures using the SQLDA structure. This is the server program of a client/server example. (The client program is called outcli.) The program fills the SQLDA with the median SALARY of the employees in the STAFF table of the SAMPLE database. The server program does all the database processing (finding the median), and then returns the filled SQLDA and the SQLCA status to the client program. The outsrv program runs on the database server, and must be built there.
outcli Demonstrates stored procedures using the SQLDA structure. This is the client program of a client/server example. (The server program is called outsrv.) The program allocates and initializes a one-variable SQLDA, and passes it to the server program for further processing. The filled SQLDA is returned to the client program along with the SQLCA status. This program shows the invocation of stored procedures using an embedded SQL CALL statement.
udf Creates a library of User-Defined Functions (UDFs) made specifically for the SAMPLE database tables, but can be used with tables with compatible column types. (The sample program calludf uses the functions created by udf.) The udf program runs on the database server, and must be built there.
calludf Demonstrates the library of User-Defined Functions (UDFs) created by udf for the SAMPLE database tables. The calludf program uses the functions created by udf.

The source files for these sample programs are in the appropriate programming language subdirectory of sqllib/samples:

C
sqllib/samples/c

C++
sqllib/samples/cpp

IBM COBOL
sqllib/samples/cobol

Micro Focus COBOL
sqllib/samples/cobol_mf

FORTRAN
sqllib/samples/fortran
Note:Of the samples given in Table 7, the C++ directory, sqllib/samples/cpp, contains only a C++ version of the updat program. The stored procedure script files documented for the C++ compilers use the C versions of the outsrv and outcli programs found in sqllib/samples/c. In addition, sqllib/samples/cpp contains object-oriented sample programs specific to C++. These programs use several class source files and CLP script files to construct and manipulate a credit database system. See the README file in the sqllib/samples/cpp directory for more information.

After you build the sample programs they can be used as templates to create your own applications. This can be done by modifying the sample programs with your own SQL statements. You can build the modified programs using either the makefile or the script files to see if they work correctly. You can also build your own embedded SQL programs using these files.

"Sample Programs" lists all of the sample programs. The Embedded SQL Programming Guide explains how the samples containing embedded SQL work; the CLI Guide and Reference explains how the samples containing CLI work; and the API Reference explains how the samples containing DB2 APIs work.
Note:It is recommended that, before you alter or build the sample programs, you copy them from sqllib/samples to your own working directory.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]