Pro*C/C++ Getting Started for Windows Platforms Go to Product Documentation Library
Library
Go to books for this product
Product
Go to Contents for this book
Contents
Go to Index
Index



Go to previous file in sequence Go to next file in sequence

Building Pro*C/C++ Applications



Building and Running Sample Programs

When you install Pro*C/C++, the installation procedure copies a set of sample programs and their corresponding files to the \PRO30\C\SAMPLES (WIN32) subdirectory or \PRO30\WIN16\C\SAMPLES (WIN16) subdirectory. Oracle recommends that you build and run these sample programs to verify that Pro*C/C++ is installed successfully and is operating correctly. You can delete the programs after you use them.

Note The following samples are available for 16- and 32-bit, unless otherwise stated. All sample program have resource files (.rc) for 16-bit.

Directory Sample
Program
Sample Pro*C/C++ Project Sample Files Description
WINSAM

WINSAM.PC
WINSAM.PRE

WINSAM.MAK
WINSAM.IDE
WINSAM.H
RESOURCE.H
WINSAM.RC
WINSAM.ICO

GUI Pro*C/C++ application

SAMPLE

SAMPLE.PC

SAMPLE.PRE

SAMPLE.MAK
SAMPLE.IDE

Application using EXEC SQL statements

SAMPLE1

SAMPLE1.PC

SAMPLE1.PRE

SAMPLE1.MAK
SAMPLE1.IDE

Application using EXEC SQL statements

SAMPLE2

SAMPLE2.PC

SAMPLE2.PRE

SAMPLE2.MAK
SAMPLE2.IDE

Application using EXEC SQL statements

SAMPLE3

SAMPLE3.PC

SAMPLE3.PRE

SAMPLE3.MAK
SAMPLE3.IDE

Application using EXEC SQL statements

SAMPLE4

SAMPLE4.PC

SAMPLE4.PRE

SAMPLE4.MAK
SAMPLE4.IDE

Application using EXEC SQL statements

SAMPLE5

SAMPLE5.PC
EXAMPBLD.SQL
EXAMPLOD.SQL

SAMPLE5.PRE

SAMPLE5.MAK
SAMPLE5.IDE

Pro*C/C++ with embedded PL/SQL blocks
NOTE: Run EXAMPBLD.SQL before running
EXAMPLOD.SQL, then build SAMPLE5.

SAMPLE6

SAMPLE6.PC

SAMPLE6.PRE

SAMPLE6.MAK
SAMPLE6.IDE

Application using EXEC SQL statements

SAMPLE7

SAMPLE7.PC

SAMPLE7.PRE

SAMPLE7.MAK
SAMPLE7.IDE

Application using EXEC SQL statements

SAMPLE8

SAMPLE8.PC

SAMPLE8.PRE

SAMPLE8.MAK
SAMPLE8.IDE

Application using EXEC SQL statements

SAMPLE9

SAMPLE9.PC
CALLDEMO.SQL

SAMPLE9.PRE

SAMPLE9.MAK
SAMPLE9.IDE

Pro*C/C++ application calling a PL/SQL stored
procedure
NOTE: Run CALLDEMO.SQL before building
SAMPLE9.

PLSSAM

PLSSAM.PC

PLSSAM.PRE

PLSSAM.MAK
PLSSAM.IDE

Pro*C/C++ with embedded PL/SQL blocks

CPPDEMO1

CPPDEMO1.PC

CPPDEMO1.PRE

C++ Pro*C application
(No 16-bit sample)

CPPDEMO2

CPPDEMO2.PC

CPPDEMO2.PRE

C++ Pro*C application

CPPDEMO3

CPPDEMO3.PC

CPPDEMO3.PRE

C++ Pro*C application
(No 16-bit sample)

CVDEMO

CV_DEMO.PC
CV_DEMO.SQL

CV_DEMO.PRE

CV_DEMO.MAK
CV_DEMO.IDE

Pro*C/C++ application using cursor variable with
PL/SQL stored procedure. (No 16-bit sample)
NOTE: Run CV_DEMO.SQL before building CV_DEMO.
ORACA

ORACA.PC

ORACA.PRE

ORACA.MAK
ORACA.IDE

Pro*C/C++ application using ORACA to determine various performance parameters at runtime.
Note: Run ORACATST.SQL before running ORACA.

SAMPLE10

SAMPLE10.PC

SAMPLE10.PRE

SAMPLE10.MAK
SAMPLE10.IDE

Pro*C/C++ application showing an implementation of Dynamic SQL Method 4. (No 16-bit sample)

SQLVCP

SQLVCP.PC

SQLVCP.PRE

SQLVCP.MAK
SQLVCP.IDE

Pro*C/C++ application demonstrating us of sqlvcp( ) and sqlgis( ) calls.

MU

MU.PC
TYPEIT.C

MU.PRE

MU.MAK
MU.IDE
TYPEIT.IDE
TYPEIT.MAK

(16-bit only) Pro*C/C++ application demonstrating Dynamic SQL Method 4 in a DLL.

MLTTHRD1

MLTTHRD1.PC
MLTTHRD1.SQL

MLTTHRD.PRE

MLTTHRD.MAK

(32-bit only) Multithread Pro*C/C++ application.

Note The .IDE files are for Borland C++. The .MAK files are for Microsoft Visual C++.

Attention For simplicity, each Pro*C/C++, 16-bit, Windows samples are divided in two parts. The Windows specific code such as message loop, creating windows, and the like, is separated from Pro*C/C++ code. All Windows specific code is in winmain.OBJ (which has winMain(), message loop and other utility functions to write text on a sample window). Pro*C/C++ sample program has the entry point as proCmain() which is called after the window is created in winMain(). The winmain.OBJ is provided to make sample program easier to understand. It is not supported for any other application.

.MAKE Files and IDE Files

.MAKE files help you build application programs. They guide and control the steps necessary to compile and link sample programs. Sample .MAKE files in this release, are created with Microsoft Visual C/C++ Version 4.2 and Microsoft Visual C/C++ 1.52c (for 16-bit), and .IDE files with Borland C++ Version 5.0, (both for 16- and 32-bit). Be sure to save the .Make files with different names since the provided .MAKE files are for Microsoft Visual C/C++.

Sample Pro*C/C++ Programs

When built, the sample programs that Oracle provides in Pro*C/C++ produce an .EXE executable. For some sample programs, you must run the SQL script(s) in the directory before you precompile and run the sample program. The SQL scripts set up the correct tables and data so that the sample programs run successfully. The sample programs are described below.

After the sample program (.pc) is successfully precompiled, use Microsoft Visual C/C++ Version 4.2, or Borland C++ Version 5.0 for 32-bit, to create the executable. Use Microsoft Visual C++ Version 1.52c or Borland C++ Version 5.0 for 16-bit, to create the executable.

SAMPLE.PC

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. The program asks you to enter the following data:

If the record has been inserted successfully, the following is printed:

ename added to department dname as employee # nnnnnn

where ename is the employee name you entered, dname is the department name, and nnnnn is the automatically generated employee number.

PLSSAM.PC

Demonstrates the use of embedded PL/SQL blocks in a Pro*C/C++ application. 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.

For example, if you enter the name SMITH, the following information is displayed:

SMITH's job is:  CLERK

Hired on:  17-DEC-80

0 people have served longer

Salary is: 800

15 people have a higher salary

Department number is: 20

6 people in the department

If you enter a name that does not reside in the database, the following message is displayed, where ename is the name you entered:

ename does not work for the company

WINSAM.PC

This GUI version of the SAMPLE.PC program 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 box.

SAMPLE1.PC

Logs on to ORACLE, prompts the user for an employee number, queries the database for the employee's name, salary, and commission, and displays the result. It continues until you enter a 0 (zero) as the employee number.

SAMPLE2.PC

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

SAMPLE3.PC

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

SAMPLE4.PC

Features an in-depth example of Datatype Equivalencing. After logging in, it creates a new table in the SCOTT account IMAGE, and simulates placement of bitmap images of employees. Later, when an employee number is entered, the associated bitmap is selected from the IMAGE table, and "pseudo-displayed" on the screen.

SAMPLE5.PC

Prompts the user for an account number and a debit amount. It verifies that the account number is valid and that there are sufficient funds to cover the withdrawal before it debits the account.

SAMPLE6.PC

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

SAMPLE7.PC

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

SAMPLE8.PC

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

SAMPLE9.PC

Connects to ORACLE using the SCOTT/TIGER account. The program declares several host arrays and calls a PL/SQL stored procedure (GET_EMPLOYEES in the CALLDEMO package) that fills the table OUT parameters. The PL/SQL procedure returns up to ASIZE values. SAMPLE9 keeps calling GET_EMPLOYEES, getting ASIZE arrays each time, and printing the values, until all rows have been retrieved. GET_EMPLOYEES sets the done_flag to indicate no more data.

CPPDEMO1.PC

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

CPPDEMO2.PC

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

CPPDEMO3.PC

An example of C++ Inheritance, this program finds all salespeople and prints their names and their total earnings (including commissions).

CV_DEMO.PC

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.

ORACA.PC

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

SAMPLE10.PC

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

SQLVCP.PC

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 sqlgls() function to get the text of the last SQL statement executed.

Additional Information Refer to "Error Handling" in the Programmer's Guide to the Oracle Pro*C/C++ Precompiler.

MU.PC

MU.PC is a reentrant sample Pro*C/C++ program. TYPEIT.C acts as a Windows front-end for MU.PC. TYPEIT.C prompts you to type in a SQL statement. It then loads MU.DLL to execute the SQL statement and prints out the results of the SQL statement. To build MU.DLL and TYPEIT.EXE, see instructions in the files MU.PC and TYPEIT.C, respectively.

MLTTHRD1.PC

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

Each thread executes zero or more transactions, that are specified in a transient structure called, "records". The program requires a table,

"ACCOUNTS" to be in the schema scott/tiger. The description of ACCOUNTS is:

SQL> desc accounts

Name

Null

Type

---------

--------

-------

ACCOUNT

NUMBER (10)

BALANCE

NUMBER (12,2)

For proper execution, the table should be filled with the accounts 10001 to 10008.

Creating a Sample Program

Follow these steps to precompile, compile, and link a sample program:

  1. Integrate Pro*C/C++ into the development environment. (See Appendix A.)
  2. Open and check the sample project file.
  3. While you are in the development environment, open the sample project file (for example, useWINSAM.IDE for Borland C++ and use WINSAM.MAK for Microsoft Visual C/C++. Microsoft Visual C/C++ creates .mdp, .mcb, and the like, from .make file). Check the paths and filenames in the project file to make sure that they correspond to the configuration of your system. If they do not, change the paths and filenames accordingly. Your system may produce error messages if the paths to all components are not correct.

    Note All of the projects are created with C as the default drive.

    Additional Information When using Microsoft Visual C++ Version 4.2 (for 32-bit), note that the Pro*C/C++ samples are directly integrated into the Microsoft Visual C++ project file. There is no need to precompile files separately. Microsoft Visual C++ will run Oracle Pro*C/C++ precompiler when needed. Therefore, you can just run "build" to create the sample program using Microsoft Visual C++. You can then skip the rest of the remaining steps.

  4. Select Pro*C/C++ from the Tools menu.
  5. The Pro*C/C++ application screen appears with the project file (for example, WINSAM.PRE) already loaded.

  6. Select Run from the Tool bar to precompile the sample file.
  7. Once the precompile process is successfully completed, go back to your development environment, and create the sample application by running the build process.

Running a Sample Program

To run a sample program (in this case, WINSAM) after building it, follow these steps:

  1. From your development environment, run WINSAM.EXE.
  2. Select Connect from the Oracle menu.
  3. Enter SCOTT in the User ID box and TIGER in the Password box (or the connect string if connecting remotely). Choose OK.
  4. A dialog box appears notifying you whether the connection is successful.

  5. To enter employee data, select Employees from the Oracle menu.
  6. An Employee Record dialog box appears. You can use SQL buttons such as SELECT, FETCH, or INSERT to manipulate the sample tables.

  7. Choose Exit from the Employee Record dialog box. Then, choose Disconnect from the Oracle menu.
  8. A dialog box notifies you whether the disconnect is successful.

  9. Choose Exit to quit the program.
  10. Note:

All sample programs are written to be run on the local database. To connect to a remote database, use the LOCAL variable in the Windows 95 Registry. For 16-bit, LOCAL is in the oracle.ini file.

Building the Demonstration Tables

To run the Pro*C/C++ sample programs, you must have a database account with the username SCOTT and the password TIGER and a database with the demonstration tables EMP and DEPT. This account is included in the seed database (named ORACLE) that is shipped with your Oracle server. If no such account exists on your database, install one before running the sample program.

Additional Information See your Oracle database or server documentation.

If your database does not contain these tables, use the DEMOBLD.SQL script to create them. To run DEMOBLD, first use SQL*Plus or Server Manager to connect to the Oracle database.

Dynamic Link Libraries (DLLs)

The Pro*C/C++ API calls are implemented in DLL files provided with your Pro*C/C++ software. To use the DLLs, you must link your application with the import libraries (.LIB files) that correspond to the Pro*C/C++ DLLs. Also, you must make sure that the DLL files are installed on the workstation that is running your Pro*C/C++ application.

Applications linked with DLLs provide the following benefits over static libraries:

For Win32-specific applications, Microsoft provides you with three libraries: LIBC.LIB, LIBCMT.LIB, and MSVCRT.LIB. The Oracle DLLs for Win32 use the MSVCRT.LIB runtime library. You must link with MSVCRT.LIB rather than the other two Microsoft libraries.

Building Multi-Threaded Applications

When building a multi-threaded application, make sure that your C/C++ code is reentrant. This means that access to static or global data must be restricted to one thread at a time. If you mix multi-threaded and non-reentrant functions, one thread may potentially modify information that is required by another thread.

Attention For WIN16 operation, use the reentrant option to generate reentrant code for Windows 16-bit. This option is only available for Windows. Note, when using Pro*C/C++ (for WIN32) by default, it generates reentrant code.

Additional Information For more information on how to write multi-threaded applications with Pro*C/C++, see the Programmer's Guide to the Oracle Pro*C/C++ Precompiler.



Go to previous file in sequence Go to next file in sequence
Prev Next
Oracle
Copyright © 1996 Oracle Corporation.
All Rights Reserved.
Go to Product Documentation Library
Library
Go to books for this product
Product
Go to Contents for this book
Contents
Go to Index
Index