4.5 Pro*C/C++

The Oracle Pro*C/C++ precompiler allows programmers to use user-defined data types in C and C++ programs.

Topics:

4.5.1 About Pro*C/C++

Pro*C developers can use the Object Type Translator to map Oracle object types and collections into C data types to be used in the Pro*C application.

Pro*C provides compile time type checking of object types and collections and automatic type conversion from database types to C data types.

Pro*C includes an EXEC SQL syntax to create and destroy objects and offers two ways to access objects in the server:

  • SQL statements and PL/SQL functions or procedures embedded in Pro*C programs.

  • An interface to the object cache (described under "Oracle Call Interface (OCI)"), where objects can be accessed by traversing pointers, then modified and updated on the server.

    See Also:

    For a complete description of the Pro*C/C++ precompiler, see Pro*C/C++ Programmer's Guide

4.5.2 Associative Access in Pro*C/C++

Pro*C/C++ offers the following capabilities for associative access to objects:

  • Support for transient copies of objects allocated in the object cache

  • Support for transient copies of objects referenced as input host variables in embedded SQL INSERT, UPDATE, and DELETE statements, or in the WHERE clause of a SELECT statement

  • Support for transient copies of objects referenced as output host variables in embedded SQL SELECT and FETCH statements

  • Support for ANSI dynamic SQL statements that reference object types through the DESCRIBE statement, to get the object's type and schema information

See Also:

For background information on associative access, see "Associative Access in OCI Programs".

4.5.3 Navigational Access in Pro*C/C++

Pro*C/C++ offers the following capabilities to support a more object-oriented interface to objects:

  • Support for dereferencing, pinning, and optionally locking an object in the object cache using an embedded SQL OBJECT DEREF statement

  • Allowing a Pro*C/C++ user to inform the object cache when an object has been updated or deleted, or when it is no longer needed, using embedded SQL OBJECT UPDATE, OBJECT DELETE, and OBJECT RELEASE statements

  • Support for creating new referenceable objects in the object cache using an embedded SQL OBJECT CREATE statement

  • Support for flushing changes made in the object cache to the server with an embedded SQL OBJECT FLUSH statement

See Also:

For background information on navigational access, see "Navigational Access in OCI Programs".

4.5.4 Conversion Between Oracle Types and C Types

Pro*C/C++ provides ease-of-use enhancements to simplify use of OCI types in C and C++ applications.

The C representation for objects that is generated by the Oracle Type Translator (OTT) uses OCI types which are opaque and insulate you from changes to their internal formats, but are cumbersome to use in a C or C++ application. These representations include OCIString and OCINumber for scalar attributes and OCITable, OCIArray, and OCIRef types for collection types and object references.

With Pro*C/C++ enhancements:

  • Object attributes can be retrieved and implicitly converted to C types with the embedded SQL OBJECT GET statement.

  • Object attributes can be set and converted from C types with the embedded SQL OBJECT SET statement.

  • Collections can be mapped to a host array with the embedded SQL COLLECTION GET statement. Furthermore, if the collection is comprised of scalar types, then the OCI types can be implicitly converted to a compatible C type.

  • Host arrays can be used to update the elements of a collection with the embedded SQL COLLECTION SET statement. As with the COLLECTION GET statement, if the collection is comprised of scalar types, C types are implicitly converted to OCI types.

4.5.5 Oracle Type Translator (OTT)

The Oracle Type Translator (OTT) is a program that automatically generates C language structure declarations corresponding to object types.

OTT makes it easier to use the Pro*C precompiler and the OCI server access package.

See Also:

For complete information about OTT, see Oracle Call Interface Programmer's Guide and Pro*C/C++ Programmer's Guide.