Pro*C/C++ Getting Started for Windows Platforms | Library |
Product |
Contents |
Index |
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.
|
Note The .IDE files are for Borland C++. The .MAK files are for Microsoft Visual C++.
|
.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++.
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.
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.
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
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.
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.
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.
Logs on to ORACLE, declares and opens a cursor, fetches in batches using arrays, and prints the results using the function print_rows().
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.
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.
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 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.
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.
Retrieves the names of all employees in a given department from the EMP table (Dynamic SQL Method 3).
An example of C++ Inheritance, this program finds all salespeople and prints their names and their total earnings (including commissions).
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 use the ORACA to determine various performance parameters at runtime.
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).
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 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.
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:
Name
|
Null
|
Type
|
---------
|
--------
|
-------
|
ACCOUNT
|
NUMBER (10)
|
|
BALANCE
|
NUMBER (12,2)
|
For proper execution, the table should be filled with the accounts 10001 to 10008.
Follow these steps to precompile, compile, and link a sample program:
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.
|
The Pro*C/C++ application screen appears with the project file (for example, WINSAM.PRE) already loaded.
To run a sample program (in this case, WINSAM) after building it, follow these steps:
A dialog box appears notifying you whether the connection is successful.
An Employee Record dialog box appears. You can use SQL buttons such as SELECT, FETCH, or INSERT to manipulate the sample tables.
A dialog box notifies you whether the disconnect is successful.
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.
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.
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.
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.
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.
|
Prev Next |
Copyright © 1996 Oracle Corporation. All Rights Reserved. |
Library |
Product |
Contents |
Index |