Pro*C/C++ Precompiler Getting Started Release 8.1.6 for Windows Part Number A73023-01 |
|
This chapter describes how to build Oracle database applications with Pro*C/C++ using the sample programs that are included with this release. Specific topics discussed are:
When you install Pro*C/C++, Oracle Installer copies a set of Pro*C/C++ sample programs to the oracle_base
\
oracle_home
\precomp\demo\proc
directory. These sample programs are listed in Table 3-1, "Sample Programs". The SQL scripts are located in the oracle_base
\
oracle_home
\precomp\demo\sql
directory.
Oracle recommends that you build and run these sample programs to verify that Pro*C/C++ has been installed successfully and operates correctly. You can delete the programs after you use them.
When built, the sample programs that Oracle provides in Pro*C/C++ produce .exe
executables. For some sample programs, you must run the SQL scripts in the sample 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 correctly.
The following subsections describe the functionality of the sample programs.
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.
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.
Fetches census information for California counties. This program demonstrates various ways to navigate through collection-typed database columns.
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.
Retrieves the names of all employees in a given department from the EMP table (dynamic SQL Method 3).
Finds all salespeople and prints their names and total earnings (including commissions). This program is an example of C++ inheritance.
Declares and opens a ref cursor.
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.
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.
Shows how to use threading in conjunction with precompilers. The program creates as many sessions as there are threads. See"Building Multi-Threaded Applications" .
Demonstrates navigational access to objects in the object cache.
Demonstrates the use of objects. This program manipulates the object types person and address.
Demonstrates how to use ORACA to determine various performance parameters at runtime.
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.
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.
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.
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.
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.
Demonstrates the use of type equivalencing using the LONG VARRAW external datatype.
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.
Creates a table, inserts a row, commits the insert, and drops the table (dynamic SQL Method 1).
Inserts two rows into the EMP table and deletes them (dynamic SQL Method 2).
Retrieves the names of all employees in a given department from the EMP table (dynamic SQL Method 3).
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.
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).
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.
Demonstrates how to do array fetches using dynamic SQL Method 4.
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.
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.
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 Oracle8i server. If the account does not exist on your database, create the account before running the sample programs.
See Oracle8i Administrator's Guide for Windows NT for more information. If your database does not contain EMP and DEPT tables, you can use the demobld.sql
script to create them.
demobld.sql
script:
SQL> @ORACLE_BASE\ORACLE_HOME\SQLPLUS\DEMO\DEMOBLD.SQL;
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.
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. See Appendix A, "Integrating Pro*C/C++ into Microsoft Visual C++" for more information.
sample1.dsp
.
By default the sample .pre
files search for their corresponding .pc
files in the c:\oracle\ora81
directory where c:\
is the drive that you are using, and oracle\ora81
represents the location of the Oracle home. If the Oracle base and Oracle home directories are different on your computer, you must change the directory path to the correct path.
To change the directory path for a sample .pre
file:
.pre
file.
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|