home *** CD-ROM | disk | FTP | other *** search
- This directory contains the following DB-Library example files and scripts:
-
- example1.c: Submits 2 queries to the server on the table
- 'sysobjects', one to find all the system tables,
- the other to find the first 10 stored procedures.
- Binds program variables to the returned rows, then
- displays the rows.
-
- example2.c: Opens a data file, inserts data from the file into
- a database table, binds the data to program variables,
- and displays the results.
-
- example3.c: Illustrates binding aggregate and compute by results
- using the "pubs" database.
-
- example4.c: Submits a query to the server and saves up to 1,000
- rows of the results using row buffering rather
- than binding. Asks the user which row to display,
- then displays that row.
-
- example5.c: Illustrates data conversion with the dbconvert()
- routine.
-
- example6.c: Demonstrates the use of two DBPROCESSes to
- simultaneously query and update a table through
- browse mode. This example uses a hardcoded query.
-
- example7.c: Demonstrates most of the browse mode routines
- that deal with finding out about the results
- of an ad hoc query.
-
- example8.c: Illustrates how to use remote procedure calls
- and how to process return parameter values.
-
- example9.c: Illustrates a method for effectively managing
- multiple input and output data streams, via
- DBIORDESC(), DBIOWDESC(), DBRBUF(), dbsqlsend(),
- and dbsqlok().
-
- twophase.c: Illustrates the use of the two-phase commit
- service to perform a distributed transaction.
-
- datafile: The data file for examples 2 and 6.
-
- installsample: A script for building a sample dataserver and setting
- it up for running the sample DB-Lib programs.
-
- README: This file.
-
-
- Examples 1-9 setup:
-
- There are two parts to running the DB-Library sample programs, setting up a
- sample database, and compiling and running the samples:
-
- Setting up a sample database for examples 1-9:
-
- Because of the various permissions which the examples need
- set in the server, it is easiest to use new temporary master
- database devices. The script "installsample" will build
- a 16M sample database device, set it up, and start a server
- named PRACTICE for running DB-Lib examples 1-9. If you
- want to set up the sample database by hand, see the Notes
- section below for more details of the requirements for the
- sample programs. If you are planning on running the
- "twophase" example, see the Twophase Example Setup section
- below.
-
- Steps for setting up the sample database with a server
- named PRACTICE:
-
- 1. Set up the SYBASE environment variable using the following
- command:
-
- source /usr/sybase/scripts/SetVars
-
- 2. Create a new entry in the /usr/sybase/interfaces file
- for the server named PRACTICE. See the Install Guide
- for information on adding entries to the interfaces file.
-
- 3. Find enough space for a 16M database device on your disk.
-
- 4. Using "installsample", create a new database device and start
- a server named PRACTICE using the command:
-
- $SYBASE/sample/dblibrary/installsample <PRACTICE_device_name> PRACTICE
-
- where PRACTICE_device_name is the full pathname for the
- database device to be installed. We recommend that you
- always name database devices with a .sdb extension, e.g.,
-
- $SYBASE/sample/dblibrary/installsample\
- ~/your_dir/practice_db.sdb PRACTICE
-
- will install a 16M database device '~/your_dir/dbs/practice_db.sdb'
- and bring up a dataserver for it named PRACTICE.
-
- The script "installsample" uses "startserver" to
- build and/or start the specified device. This
- means that your server will be left running in a
- Terminal window after the database is installed.
-
- For more details on "installsample", see the script
- itself: /usr/sybase/sample/dblibrary/installsample
-
- 5. Set the DSQUERY environment variable to point to the PRACTICE
- server by typing:
-
- setenv DSQUERY PRACTICE
-
- 6. Now that the PRACTICE server is up and running, the
- database is set up to run examples 1-9.
-
- To compile and run examples 1-9:
-
- 1. You must login as 'sybase' in order to compile the samples.
-
- 2. Change to the /usr/sybase/sample/dblibrary directory using:
-
- cd /usr/sybase/sample/dblibrary
-
- 3. Set the SYBASE environment variable to the sybase root
- directory using the following command:
-
- setenv SYBASE /usr/sybase
-
- 4. Compile and link the source files:
-
- The makefile is set up to compile the samples and link them with
- shared libraries.
-
- To compile all the samples, use the command:
-
- make all
-
- To compile individual samples:
-
- make exam1
- make exam2
- etc.
-
- To use compile switches, use the CFLAGS switch:
-
- make CFLAGS=-g all
-
- 5. To run examples 1-9:
-
- exam1
- exam2
- etc.
-
- Twophase Example Setup:
-
- The two-phase commit C example requires two different master database
- devices and two servers to be running at the same time. Each server
- will have its own name in the interfaces file: one server will be
- named SERVICE and the other server will be named PRACTICE. You can
- use the database device you created for examples 1-9 as one of the
- database devices. If the server you you used for running examples
- 1-9 is still running, the PRACTICE server is ready to go, and you
- only need to install the SERVICE server.
-
- Here are the steps for setting up the databases and servers for
- the twophase sample. Note that the setup for the SERVICE server
- is completely analogous to the PRACTICE server. If you have not
- yet setup the PRACTICE server, follow the instructions in the
- section "Setting up a sample database for examples 1-9".
-
- Setting up the sample databases for the twophase example:
-
- 1. Set up the SYBASE environment variable using the
- following command:
-
- source /usr/sybase/scripts/SetVars
-
- 2. Create a new entry in /usr/sybase/interfaces file for the
- server named SERVICE. See the Install Guide for
- information on adding entries to the interfaces file.
-
- 3. Find enough space for a 16M database device on your
- disk.
-
- 4. Using "installsample", create a new database device and
- start a server named SERVICE using the command:
-
- $SYBASE/sample/dblibrary/installsample \
- <SERVICE_device_name> SERVICE
-
- where SERVICE_device_name is the full pathname for
- the database device to be installed. We recommend
- that you always name database devices with a
- .sdb extension. Note that this device must have
- a different name from the PRACTICE device.
-
- 5. Set the DSQUERY environment variable to point to
- the PRACTICE server. This is the necessary DSQUERY
- setting for running "twophase":
-
- setenv DSQUERY PRACTICE
-
- 6. With both the PRACTICE and SERVICE servers installed
- and running, you are now set up to run "twophase".
-
- To compile and run twophase:
-
- 1. You must login as 'sybase' in order to compile twophase.
-
- 2. Change to the /usr/sybase/sample/dblibrary directory using:
-
- cd /usr/sybase/sample/dblibrary
-
- 3. Set the SYBASE environment variable to the sybase root directory
- using the following command:
-
- setenv SYBASE /usr/sybase
-
- 4. Compile and link the source file using shared libraries:
-
- make twophase
-
- 5. To run twophase, type:
-
- twophase
-
- The correct, exciting output for twophase is:
-
- Demo of Two Phase Commit
- We made it!
-
- To stop the servers, use:
-
- $SYBASE/install/stopserver PRACTICE
- $SYBASE/install/stopserver SERVICE
-
-
- Notes:
-
- This section describes the requirements for the sample databases used
- by the DB-Lib examples. If you have followed the previous instructions for
- installing the sample databases using the "installsample" script, then
- you have performed all the required database initialization described here.
-
- These examples have "hard-coded" a server password
- "server_password" in the source. Make sure that the password
- for your server login on any server used when running the
- examples is "server_password". (The two-phase commit
- example requires two servers.) By default, the DB-Library
- routines use the UNIX login name to determine who you are
- and how to log you on.
-
- Each server used with the examples must contain the "pubs"
- database. This database is used by Example 3 and the
- two-phase commit example. The minimum size for the database
- device is 14M, which includes "model", "pubs", and enough
- space to create the "test" database.
-
- Example 2 requires that you have 'create database' permission.
- The example creates database "test".
-
- Example 6 requires that you have 'create table' permission.
- The example creates the table "alltypes" in your default
- database.
-
- Example 7 prompts the user for an ad hoc query. Notice
- how the results differ depending on whether the SELECT
- query includes the keywords FOR BROWSE and whether the
- table SELECTed is browsable.
-
- Example 8 assumes you have created the stored procedure
- "rpctest" in your default database. The comments at the
- top of the Example 8 source code specify the CREATE PROCEDURE
- statement necessary for creating "rpctest". This SQL
- statement is also specified in the "installsample" script.
-
- The two-phase commit example requires two servers. See
- the Twophase Example Setup for a complete description of
- the requirements for running this example. The example
- has "hard-coded" server names SERVICE and PRACTICE which
- must be in the interfaces file.
-
- The programs are well commented; take a look before you
- run them if you'd like more details.
-
-