简体   繁体   中英

Get OCCI Connection from Pro*C connection?

We maintain an extensive collection of components written in C++ that run under Linux, Solaris, AIX and HP/UX that connect to an Oracle database using Pro*C. I am about to write a component that performs a lot of dynamic SQL and would like to implement that functionality using OCCI . The base class to all our components creates a connection to the database using the fairly normal Pro*C:

EXEC SQL CONNECT :user IDENTIFIED BY :password AT :alias USING :name;

And alias is used in all future Pro*C code to interact with the database.

Is it possible to get an OCCI connection from this so that I can leave our base class implementation intact but use OCCI in my component?

tl;dr: you can't reuse a Pro*C connection with OCCI, but connection reuse is supported by OTL , though.

The Pro*C runtime library internally uses the OCI API. Oracle documents how to get the currently used OCI handle:

Precompiler applications can extract OCI handles and call OCI functions directly. However, non-blocking mode is not supported because the precompilers are unable to handle the "still executing" error that might be returned. (Oracle's Pro*C Programmer's Guide , 11.2g)

You can obtain the OCI handle after the embedded CONNECT statement.

See the SQLEnvGet() / SQLSvcCtxGet() functions for details.

Although OCCI also internally uses OCI it doesn't provide any way to 'start from' an existing OCI handle. It only provides methods for getting its OCI handle, once you have connected with OCCI.

In contrast to OCCI, the OTL allows you to start from an existing OCI handle . Similar to OCCI, it provides a convenient API for dynamic SQL in C++. In addition and unlike OCCI, it is header-only (no more C++ compiler/STL issues), open-source, portable and its API is better engineered than OCCI's. Thus, it is arguably the better alternative than OCCI if you want to interface with Oracle on a higher level than OCI/Pro*C.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM