Compile and Run Pro*C Sample Programs


IMPORTANT PRE-REQUISITES

1. Set up sample database and user accounts

The following build_sampledb script should be run once to set up the sample database and user accounts

Windows:   > cd quickstart/sample_scripts/createdb
> build_sampledb.bat
Unix/Linux:   $ cd quickstart/sample_scripts/createdb
$ ./build_sampledb.sh

2. Set up environment to compile and run the sample programs

The following script must be run for each of the terminal session:

Windows:   > quickstart/ttquickstartenv.bat
Unix/Linux:   $ . quickstart/ttquickstartenv.sh OR
$ source quickstart/ttquickstartenv.csh

How to compile the sample Pro*C programs

To compile the sample programs in the sample_code/proc directory, you simply run the makefile supplied in the same directory. Note that the appropriate makefile is made available based on the platform of your TimesTen installation.

To build a sample program in the sample_code/proc directory, use the following command:

[Windows] > nmake <program-name>.exe**
[Linux/Unix] $ make <program-name>
where <program-name> is the program you want to compile.

For example, to compile the ansidyn1 program, you do:

[Windows] > nmake ansidyn1.exe**
[Linux/Unix] $ make ansidyn1

**To build the Pro*C sample programs on Windows:


How to run the sample Pro*C program

  addempPROC This Pro*C sample program prompts the user for information and inserts the corresponding data as a new employee into the EMP table.

This program is based on the Oracle Pro*C sample.pc program and minimal error checking is performed on the data to be inserted.

The EMP table needs to exist for this program to work.

  Example:

  (run the program using the default user appuser and the default TNS Service Name sampledb_1122, will prompt for the password)

   addempPROC

  (run the program specifying the username, password and service name)

   addempPROC -user myuser -password mypassword -service myservice

For full syntax of the program, try "addempPROC -help".

  ansidyn1 ansidyn1.pc is an Oracle Pro*C program that implements a dynamic SQL interpreter. Using the ANSI embedded SQL syntax, ansidyn1.pc accepts dynamic SQL at the input command prompt (SQL>)

You are prompted for the username and password at runtime. The ‘servicename’ can be either an entry in the TNSnames.ora file or an easy connect string.

No existing tables need to exist for this program to work.

  Example:

  (Run the program using either a TNS Service Name or Easy Connect String. For a TNS Service Name enter sampledb_1122. For an Easy Connect string, enter localhost/sampledb_1122:timesten_direct)

   ansidyn1

  batchfetchPROC This Pro*C sample program connects to the database and then declares and opens a cursor, fetches in batches using arrays, and prints the results using the function print_rows().

The EMP table needs to exist for this program to work.

  Example:

  (run the program using the default user appuser and the default TNS Service Name sampledb_1122, will prompt for the password)

   batchfetchPROC

  (run the program specifying the username, password and service name)

   batchfetchPROC -user myuser -password mypassword -service myservice


For full syntax of the program, try "batchfetchPROC -help".

 

  cursorPROC This Pro*C sample program connects to the database and then declares and opens a cursor. The cursor fetches the names, salaries, and commissions of all salespeople, displays the results, then closes the cursor.

The EMP table needs to exist for this program to work.

  Example:

  (run the program using the default user appuser and the default TNS Service Name sampledb_1122, will prompt for the password)

   cursorPROC

  (run the program specifying the username, password and service name)

   cursorPROC -user myuser -password mypassword -service myservice


For full syntax of the program, try "cursorPROC -help".

 

  getempPROC This Pro*C sample program prompts the user for an employee number and then:

- Queries the emp table for the employee's name, salary and commission.
- Uses indicator variables (in an indicator struct) to determine if the commission is NULL.

The employee numbers can be found by running the Pro*C batchfetchPROC sample program or via the EMP table.

The EMP table needs to exist for this program to work.

  Example:

  (run the program using the default user appuser and the default TNS Service Name sampledb_1122, will prompt for the password)

   getempPROC

  (run the program specifying the username, password and service name)

   getempPROC -user myuser -password mypassword -service myservice

For full syntax of the program, try "getempPROC -help".

 

  plsqlPROC This sample program uses Pro*C to access common PL/SQL packages (emp_pkg and sample_pkg) in four different ways:

- Calls a stored procedure with IN and OUT parameters
- Calls a stored function with IN and OUT parameters
- Calls an anonymous block and passes host variables into and out of the block
- Calls a store procedure to open a ref cursor and uses Pro*C to process the result-set of the ref cursor

The EMP table and the emp_pkg and sample_pkg PL/SQL packages need to exist for this program to work.

Build:

When plsqlPROC is being built via make [or nmake on Windows], the Oracle Pro*C pre-compiler will prompt for the password of the user 'appuser'.
To avoid being prompted for the password at build time, you can hard-code the password in the Makefile, but this is a security risk.

e.g. USERID=appuser/your_password_for_appuser

 
Example:

  (run the program using the default user appuser and the default TNS Service Name sampledb_1122, will prompt for the password)

   plsqlPROC

  (run the program specifying the username, password and service name)

   plsqlPROC -user myuser -password mypassword -service myservice


For full syntax of the program, try "plsqlPROC -help".


 

For more information on Pro*C/C++ support in TimesTen, refer to the Pro*C/C++ chapter in the Oracle TimesTen In-Memory Database C Developer's Guide.