Pro*C/C++ Precompiler Getting Started
Release 8.1.5 for Windows NT and Windows 95/98
A68801-01

Library

Product

Contents

Index

PrevNext

3
Sample Programs

This chapter describes the sample programs that are provided with Pro*C/C++ release 8.1.5 for Windows NT and Windows 95/98.

Specific topics discussed are:

Sample Program Descriptions

The ORACLE_BASE\ORACLE_HOME\PRECOMP\DEMO\PROC directory contains the following sample programs:

Sample Program Source Files Pro*C/C++ GUI Project File MSVC Compiler
Project File
Notes

ANSIDYN1 

ANSIDYN1.PC 

ANSIDYN1.PRE 

ANSIDYN1.DSP 

 

ANSIDYN2 

ANSIDYN2.PC 

ANSIDYN2.PRE 

ANSIDYN2.DSP 

 

COLDEMO1 

COLDEMO1.H
COLDEMO1.PC
COLDEMO1.SQL
COLDEMO1.TYP 

COLDEMO1.PRE 

COLDEMO1.DSP 

Run COLDEMO1.SQL and the Object Type Translator before building COLDEMO1. 

CPPDEMO1 

CPPDEMO1.PC 

CPPDEMO1.PRE 

CPPDEMO1.DSP 

 

CPPDEMO2 

CPPDEMO2.PC

EMPCLASS.PC
CPPDEMO2.SQL
EMPCLASS.H

CPPDEMO2.PRE 

CPPDEMO2.DSP 

 Run CPPDEMO2.SQL before building CPPDEMO2.

CPPDEMO3 

CPPDEMO3.PC 

CPPDEMO3.PRE 

CPPDEMO3.DSP 

 

CVDEMO 

CV_DEMO.PC
CV_DEMO.SQL 

CV_DEMO.PRE 

CV_DEMO.DSP 

Run CV_DEMO.SQL before building CV_DEMO. 

LOBDEMO1

LOBDEMO1.H
LOBDEMO1.PC
LOBDEMO1.SQL 

LOBDEMO1.PRE 

LOBDEMO1.DSP 

Run LOBDEMO1.SQL before building LOBDEMO1. 

MLTTHRD1 

MLTTHRD1.PC
MLTTHRD1.SQL 

MLTTHRD1.PRE 

MLTTHRD1.DSP 

Run MLTTHRD1.SQL before building MLTTHRD1. 

NAVDEMO1 

NAVDEMO1.H
NAVDEMO1.PC
NAVDEMO1.SQL
NAVDEMO1.TYP 

NAVDEMO1.PRE 

NAVDEMO1.DSP 

Run NAVDEMO1.SQL and the Object Type Translator before building NAVDEMO1. 

OBJDEMO1 

OBJDEMO1.H
OBJDEMO1.PC
OBJDEMO1.SQL
OBJDEMO1.TYP 

OBJDEMO1.PRE 

OBJDEMO1.DSP 

Run OBJDEMO1.SQL and the Object Type Translator before building OBJDEMO1. 

ORACA 

ORACA.PC
ORACATST.SQL 

ORACA.PRE 

ORACA.DSP 

Run ORACATST.SQL before building ORACA. 

PLSSAM 

PLSSAM.PC 

PLSSAM.PRE 

PLSSAM.DSP 

 

SAMPLE 

SAMPLE.PC 

SAMPLE.PRE 

SAMPLE.DSP 

 

SAMPLE1 

SAMPLE1.PC 

SAMPLE1.PRE 

SAMPLE1.DSP 

 

SAMPLE2 

SAMPLE2.PC 

SAMPLE2.PRE 

SAMPLE2.DSP 

 

SAMPLE3 

SAMPLE3.PC 

SAMPLE3.PRE 

SAMPLE3.DSP 

 

SAMPLE4 

SAMPLE4.PC 

SAMPLE4.PRE 

SAMPLE4.DSP 

 

SAMPLE5 

SAMPLE5.PC
EXAMPBLD.SQL
EXAMPLOD.SQL 

SAMPLE5.PRE 

SAMPLE5.DSP 

Run EXAMPBLD.SQL, then run EXAMPLOD.SQL, before building SAMPLE5. 

SAMPLE6 

SAMPLE6.PC 

SAMPLE6.PRE 

SAMPLE6.DSP 

 

SAMPLE7 

SAMPLE7.PC 

SAMPLE7.PRE 

SAMPLE7.DSP 

 

SAMPLE8 

SAMPLE8.PC 

SAMPLE8.PRE 

SAMPLE8.DSP 

 

SAMPLE9 

SAMPLE9.PC
CALLDEMO.SQL 

SAMPLE9.PRE 

SAMPLE9.DSP 

Run CALLDEMO.SQL before building SAMPLE9. 

SAMPLE10 

SAMPLE10.PC 

SAMPLE10.PRE 

SAMPLE10.DSP 

 

SAMPLE11 

SAMPLE11.PC
SAMPLE11.SQL 

SAMPLE11.PRE 

SAMPLE11.DSP 

Run SAMPLE11.SQL before building SAMPLE11. 

SAMPLE12 

SAMPLE12.PC 

SAMPLE12.PRE 

SAMPLE12.DSP 

 

SQLVCP 

SQLVCP.PC 

SQLVCP.PRE 

SQLVCP.DSP 

 

EMPCLASS 

CPPDEMO2.PC
EMPCLASS.PC
CPPDEMO2.SQL
EMPCLASS.H 

EMPCLASS.PRE 

EMPCLASS.DSP 

Run CPPDEMO2.SQL before building EMPCLASS. 

WINSAM 

RESOURCE.H
WINSAM.H
WINSAM.ICO
WINSAM.PC
WINSAM.RC 

WINSAM.PRE 

WINSAM.DSP 

 

The following subsections describe the functionality of the sample programs.

ANSIDYN1

Demonstrates using ANSI dynamic SQL to process SQL statements that are not known until runtime. This program is intended to demonstrate the simplest (though not the most efficient) approach to using ANSI dynamic SQL.

ANSIDYN2

Demonstrates using ANSI dynamic SQL to process SQL statements that are not known until runtime. This program uses the Oracle extensions for batch processing and reference semantics.

COLDEMO1

Fetches census information for California counties. This program demonstrates various ways to navigate through collection-typed database columns.

CPPDEMO1

Prompts the user for an employee number, then queries the EMP table for the employee's name, salary, and commission. This program uses indicator variables (in an indicator struct) to determine whether the commission is NULL.

CPPDEMO2

Retrieves the names of all employees in a given department from the EMP table (dynamic SQL Method 3).

CPPDEMO3

Finds all salespeople and prints their names and total earnings (including commissions). This program is an example of C++ inheritance.

CVDEMO

Declares and opens a ref cursor.

LOBDEMO1

Fetches and adds crime records to the database based on the person's Social Security number. This program demonstrates the mechanisms for accessing and storing large objects (LOBs) to tables and manipulating LOBs through the stored procedures available through the DBMS_LOB package.

MLTTHRD1

Shows how to use threading in conjunction with precompilers. The program creates as many sessions as there are threads.

NAVDEMO1

Demonstrates navigational access to objects in the object cache.

OBJDEMO1

Demonstrates the use of objects. This program manipulates the object types "person" and "address".

ORACA

Demonstrates how to use ORACA to determine various performance parameters at runtime.

PLSSAM

Demonstrates the use of embedded PL/SQL blocks. This program prompts you for an employee name that already resides in a database. It then executes a PL/SQL block, which returns the results of four SELECT statements.

SAMPLE

Adds new employee records to the personnel database and checks database integrity. The employee numbers in the database are automatically selected using the current maximum employee number +10.

SAMPLE1

Logs on to an Oracle database, prompts the user for an employee number, queries the database for the employee's name, salary, and commission, and displays the result. The program continues until the user enters 0 as the employee number.

SAMPLE2

Logs on to an Oracle database, declares and opens a cursor, fetches the names, salaries, and commissions of all salespeople, displays the results, and closes the cursor.

SAMPLE3

Logs on to an Oracle database, declares and opens a cursor, fetches in batches using arrays, and prints the results using the print_rows() function.

SAMPLE4

Demonstrates the use of type equivalencing using the LONG VARRAW external datatype.

SAMPLE5

Prompts the user for an account number and a debit amount. The program verifies that the account number is valid and that there are sufficient funds to cover the withdrawal before it debits the account. This program shows the use of embedded SQL.

SAMPLE6

Creates a table, inserts a row, commits the insert, and drops the table (dynamic SQL Method 1).

SAMPLE7

Inserts two rows into the EMP table and deletes them (dynamic SQL Method 2).

SAMPLE8

Retrieves the names of all employees in a given department from the EMP table (dynamic SQL Method 3).

SAMPLE9

Connects to an Oracle database using the SCOTT/TIGER account. The program declares several host arrays and calls a PL/SQL stored procedure (GET_EMPLOYEES in the CALLDEMO package). The PL/SQL procedure returns up to ASIZE values. The program keeps calling GET_EMPLOYEES, getting ASIZE arrays each time, and printing the values, until all rows have been retrieved.

SAMPLE10

Connects to an Oracle database using your user name and password and prompts for a SQL statement. You can enter any legal SQL statement, but you must use regular SQL syntax, not embedded SQL. Your statement is processed. If the statement is a query, the rows fetched are displayed (dynamic SQL Method 4).

SAMPLE11

Fetches from the EMP table, using a cursor variable. The cursor is opened in the stored PL/SQL procedure open_cur, in the EMP_DEMO_PKG package.

SAMPLE12

Demonstrates how to do array fetches using dynamic SQL Method 4.

SQLVCP

Demonstrates how you can use the sqlvcp() function to determine the actual size of a VARCHAR struct. The size is then used as an offset to increment a pointer that steps through an array of VARCHARs.

This program also demonstrates how to use the SQLStmtGetText() function to retrieve the text of the last SQL statement that was executed.

WINSAM

Adds new employee records to the personnel database and checks database integrity. You can enter as many employee names as you want and perform the SQL commands by selecting the appropriate buttons in the Employee Record dialog box. This is a GUI version of the SAMPLE program.

EMPCLASS

The EMPCLASS and CPPDEMO2 files were written to provide an example of how to write Pro*C/C++ programs within a C++ framework. EMPCLASS encapsulates a specific query on the emp table and is implemented using a cursor variable. EMPCLASS instantiates an instance of that query and provides cursor variable functionality (that is: open, fetch, close) through C++ member functions that belong to the emp class. The empclass.pc file is NOT a standalone demo program..  It was written to be used by the cppdemo2 demo program. To use the emp class, you have to write a driver (CPPDEMO2.PC) which declares an instance of the emp class and issues calls to the member functions of that class.



Building the Sample Tables

To run the sample programs, you must have a database account with the user name SCOTT and the password TIGER. Also, you must have a database with the sample tables EMP and DEPT. This account is included in the starter database for your Oracle8 server. If the account does not exist on your database, create the account before running the sample programs.
See your Oracle8 server documentation for more information. If your database does not contain EMP and DEPT tables, you can use the DEMOBLD.SQL script to create them.


To build the sample tables:

  1. Start SQL*Plus:
  2. C:\> SQLPLUS
  3. Connect as user name SCOTT with the password TIGER:
  4. Enter user-name: SCOTT/TIGER
  5. Run the DEMOBLD.SQL script:
  6. SQL> @ORACLE_BASE\ORACLE_HOME\DBS\DEMOBLD.SQL;

Compiler Project Files

Microsoft Visual C++ 6.0 project files have an extension of .DSP.

The .DSP files in the ORACLE_BASE\ORACLE_HOME\PRECOMP\DEMO\PROC directory guide and control the steps necessary to precompile, compile, and link the sample programs.


Building the Sample Programs

Pro*C/C++, SQL*Plus, and the Object Type Translator have been integrated into the Microsoft Visual C++ sample project files. You do not have to run Pro*C/C++, SQL*Plus, and the Object Type Translator separately before compilation.
Additional Information:

See Appendix A for more information about integrating Pro*C/C++ into Microsoft Visual C++.

See Chapter 20 of the Pro*C/C++ Precompiler Programmer's Guide for more information about the Object Type Translator. 

To build a sample program:

  1. Open a Visual C++ project file (for example, SAMPLE1.DSP).
  2. Check the paths in the project file to ensure that they correspond to the configuration of your system. If they do not, change the paths accordingly. Your system may produce error messages if the paths to all components are not correct.


  3. Note:

    All of the sample programs were created with C:\ORACLE\ORA81 as the default drive. 


  4. Choose Rebuild All from the Build menu.

  5. Visual C++ creates the executable.

Prev Next
Oracle
Copyright © 1999 Oracle Corporation.
All Rights Reserved.
Library Product Contents Index