IBM Books

Call Level Interface Guide and Reference


Appendix J. CLI Sample Code

This appendix lists all the sample DB2 CLI programs, including those demonstrated in this book. The samples can be found on OS/2 and Windows 32-bit operating systems in sqllib\samples\cli, and on UNIX platforms in sqllib/samples/cli. The README file contains a complete description of each file, and describes how to use the makefile and build scripts to build all the samples.

The following table lists all the DB2 CLI sample programs.

Table 216. Sample CLI Programs in DB2 Universal Database
Sample Program Name Program Description
Utility files used by most CLI samples
samputil.c
Utility functions used by most samples
samputil.h
Header file for samputil.c, included by most samples
General CLI Samples
adhoc.c
Interactive SQL with formatted output (was typical.c)
async.c
Run a function asynchronously (based on fetch.c)
basiccon.c
Basic connection
browser.c
List columns, foreign keys, index columns or stats for a table
calludf.c
Register and call a UDF
colpriv.c
List column Privileges
columns.c
List all columns for table search string
compnd.c
Compound SQL example
datasour.c
List all available data sources
descrptr.c
Example of descriptor usage
drivrcon.c
Rewrite of basiccon.c using SQLDriverConnect
duowcon.c
Multiple DUOW Connect type 2, syncpoint 1 (one phase commit)
embedded.c
Show equivalent DB2 CLI calls, for embedded SQL (in comments)
fetch.c
Simple example of a fetch sequence
getattrs.c
List some common environment, connection and statement options/attributes
getcurs.c
Show use of SQLGetCursor, and positioned update
getdata.c
Rewrite of fetch.c using SQLGetData instead of SQLBindCol
getfuncs.c
List all supported functions
getfuncs.h
Header file for getfuncs.c
getinfo.c
Use SQLGetInfo to get driver version and other information
getsqlca.c
Rewrite of adhoc.c to use prepare/execute and show cost estimate
lookres.c
Extract string from the resume clob field using locators
mixed.sqc
CLI sample with functions written using embedded SQL (Note: This file must be precompiled )
multicon.c
Multiple connections
native.c
Simple example of calling SQLNativeSql, and SQLNumParams
prepare.c
Rewrite of fetch.c, using prepare/execute instead of execdirect
proccols.c
List procedure parameters using SQLProcedureColumns
procs.c
List procedures using SQLProcedures
sfetch.c
Scrollable cursor example (based on xfetch.c)
setcolat.c
Set column attributes (using SQLSetColAttributes)
setcurs.c
Rewrite of getcurs.c using SQLSetCurs for positioned update
seteattr.c
Set environment attribute (SQL_ATTR_OUTPUT_NTS)
tables.c
List all tables
typeinfo.c
Display type information for all types for current data source
xfetch.c Extended Fetch, multiple rows per fetch
BLOB Samples
picin.c
Loads graphic BLOBS into the emp_photo table directly from a file using SQLBindParamToFile
picin2.c
Loads graphic BLOBS into the emp_photo table using SQLPutData
showpic.c
Extracts BLOB picture to file (using SQLBindColToFile), then displays the graphic.
showpic2.c
Extracts BLOB picture to file using piecewise output, then displays the graphic.
Stored Procedure Samples
clicall.c
Defines a CLI function which is used in the embedded SQL sample mrspcli3.sqc
inpcli.c
Call embedded input stored procedure samples/c/inpsrv
inpcli2.c
Call CLI input stored procedure inpsrv2
inpsrv2.c
CLI input stored procedure (rewrite of embedded sample inpsrv.sqc)
mrspcli.c
CLI program that calls mrspsrv.c
mrspcli2.c
CLI program that calls mrspsrv2.sqc
mrspcli3.sqc
An embedded SQL program that calls mrspsrv2.sqc using clicall.c
mrspsrv.c
Stored procedure that returns a multi-row result set
mrspsrv2.sqc
An embedded SQL stored procedure that returns a multi-row result set
outcli.c
Call embedded output stored procedure samples/c/inpsrv
outcli2.c
Call CLI output stored procedure inpsrv2
outsrv2.c
CLI output stored procedure (rewrite of embedded sample inpsrv.sqc)
Samples using ORDER tables created by create.c (Run in the following order)
create.c
Creates all tables for the order scenario
custin.c
Inserts customers into the customer table (array insert)
prodin.c
Inserts products into the products table (array insert)
prodpart.c
Inserts parts into the prod_parts table (array insert)
ordin.c
Inserts orders into the ord_line, ord_cust tables (array insert)
ordrep.c
Generates order report using multiple result sets
partrep.c
Generates exploding parts report (recursive SQL Query)
order.c
UDF library code (declares a 'price' UDF)
order.exp Used to build order libary
Samples unchanged from DB2 Version 2
v2sutil.c
samputil.c using old v2 functions
v2sutil.h
samputil.h using old v2 functions
v2fetch.c
fetch.c using old v2 functions
v2xfetch.c
xfetch.c using old v2 functions
Note:Other files in the samples/cli directory include:
  • README - Lists all example files.
  • makefile - Makefile for all files
  • build files for applications and stored procedures

The following two example files are listed in this section.:


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

[ DB2 List of Books | Search the DB2 Books ]