X

The leading edge of scripting languages and Oracle Database brought to you by the Data Access Development team

Open Source Library Drives Powerful Oracle Database Applications

Christopher Jones
Senior Principal Product Manager

ODPI-C logo

ODPI-C

The production release of Oracle Database Programming Interface for C (ODPI-C) is now available on GitHub

ODPI-C is an open source library of C code that simplifies access to Oracle Database for applications written in C or C++.

 

ODPI-C:

  • exposes a C API in a readily consumable way to C and C++ developers writing applications for Oracle Database.
  • is aimed at language interfaces and applications where speed of development is important, and where special-case Oracle features are not needed.
  • is already being used for Python, Node.js, Go and Rust interfaces, as well as for custom applications.
  • allows faster application implementation with less code.
  • makes memory and resource management simpler, particularly for 'binding' and 'defining' data. A reference counting mechanism adds resiliency by stopping applications destroying in-use resources.
  • is available as source code on GitHub under the Apache 2.0 and/or the Oracle UPL licenses, for direct inclusion into your own code bases.

ODPI-C is a wrapper over Oracle Call Interface. OCI is Oracle Database's main C API and is widely used by our products and user applications so it is stable, fast, scalable and supported. OCI's API is extremely flexible and gives fine-grained control to the developer for a very wide range of use cases.

ODPI-C is also flexible but is aimed primarily at language interface creators. These creators are programming within the confines of a scripting language's type system and semantics. The languages often expose simplified data access to users through cross-platform, common-denominator APIs. Therefore it makes sense for ODPI-C to provide easy to use functionality for common data access, while still allowing the power of Oracle Database to be used.

Of course ODPI-C isn't just restricted to language interface usage. Since it provides a simple programming experience, if ODPI-C has the functionality you need for accessing Oracle Database, then you can add it to your own projects.

ODPI-C is developed by the Oracle Database Data Access team, who also look after OCI and other language APIs for Oracle Database. Anthony Tuininga has been leading the ODPI-C effort. He has made full use of his extensive knowledge as creator and maintainer of the extremely popular, and full featured, Python cx_Oracle interface.

A big thank you to all the users who have given feedback on ODPI-C pre-releases.

ODPI-C Features

The ODPI-C feature list currently includes all the normal calls you'd expect to manage connections and to execute SQL and PL/SQL efficiently. It also has such gems as SQL and PL/SQL object support, scrollable cursors, Advanced Queuing, and Continuous Query Notification. ODPI-C does extra validation and has a reference counting mechanism for resiliency to help stop applications destroying in-use OCI resources. Writing threaded mode applications is easier.

The Oracle feature list in this initial release, in no particular order, is:

  • 11.2, 12.1 and 12.2 Oracle Client support
  • 9.2 and higher Oracle Database support (depending on Oracle Client version)
  • SQL and PL/SQL execution
  • Character data types (CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, NCLOB, LONG)
  • Numeric data types (NUMBER, BINARY_FLOAT, BINARY_DOUBLE)
  • Dates, Timestamps, Intervals
  • Binary types (BLOB, BFILE, RAW, LONG RAW)
  • PL/SQL data types (PLS_INTEGER, BOOLEAN, Collections, Records)
  • JSON
  • User Defined Types
  • REF CURSOR, Nested cursors, Implicit Result Sets
  • Array fetch
  • Array bind/execute
  • Session pools, with connection validation
  • Standalone connections
  • Database Resident Connection Pooling (DRCP)
  • External authentication
  • Statement caching
  • End-to-end tracing, mid-tier authentication and auditing
  • Edition Based Redefinition
  • Scrollable cursors
  • DML RETURNING
  • Privileged connection support (SYSDBA, SYSOPER, SYSASM, PRELIM_AUTH)
  • Database Startup/Shutdown
  • Session Tagging
  • Proxy authentication
  • Batch Errors
  • Array DML Row Counts
  • Query Result Caching
  • Application Continuity
  • Query Metadata
  • Password Change
  • Two Phase Commit
  • Continuous Query Notification
  • Advanced Queuing

In case you want to access other OCI functionality without having to modify ODPI-C code, there is a call to get the underlying OCI Service Context handle.

ODPI-C applications can take advantage of OCI features which don't require API access, such as the oraaccess.xml configuration for enabling statement cache auto-tuning. Similarly, Oracle Database features controlled by SQL and PL/SQL, such as partitioning, can be used in applications, as you would expect.

Since communication to the database is handled by Oracle's Network Services, features such as encrypted communication and LDAP can easily be configured.

Using ODPI-C

See ODPI-C Installation for detailed instructions.

ODPI-C code can be included in your C or C++ applications and compiled like any OCI application. Or, if you want to use ODPI-C as a shared library, use the provided example Makefile. 

To try out ODPI-C, build it as a shared library and then compile the sample programs. These show a number of ODPI-C features. You can also view the test suite.

ODPI-C makes it easy to build and distribute application code or binaries because it is open source, and OCI headers and libraries are not needed at compilation. Applications need standard Oracle client libraries only at run time.

Oracle client libraries must be installed separately. Version 11.2, 12.1 or 12.2 are required. These allow applications to connect to Oracle Database 9.2 or later (depending on the client version).

ODPI-C uses the shared library loading mechanism available on each supported platform to load the Oracle Client library at run time. This allows code using ODPI-C to be built only once, and then run using available Oracle Client libraries.

Oracle client libraries are available in the free, easily installed Oracle Instant Client "Basic" and "Basic Light" packages. Client libraries are also available in any Oracle Database installation, or in the full Oracle Client installation.

ODPI-C has been tested on Windows, macOS and Linux. Compilation on other platforms such as AIX and Solaris x64 is possible, but these have not been fully tested.

Wrap Up

ODPI-C provides an API to Oracle Database that enables functional, flexible application and scripting language API development.

ODPI-C is being used by us for the Python cx_Oracle 6 interface, and in node-oracledb 2 for Node.js. Third party developers have also started Go and Rust interfaces too. These code bases are handy, bigger examples of how to use ODPI-C.

It's also pleasing to have gotten positive feedback from internal Oracle projects that have adopted ODPI-C for a variety of other application development purposes.

ODPI-C will continue to be enhanced, bringing great Oracle Database technologies to developers. Scripting language drivers will similarly see enhancements and get benefits of the common ODPI-C code base.

I think you'll be pleased with our direction and plans for developers and scripting languages in 2017.

ODPI-C References

Home page: https://oracle.github.io/odpi/

Code: https://github.com/oracle/odpi

Documentation: https://oracle.github.io/odpi/doc/index.html

Report issues and discuss: https://github.com/oracle/odpi/issues

Footnote Trivia

Why is this first production release called version 2?  Because ODPI-C is a significantly updated, refactored, and standalone release of code which had origins in a node-oracledb 1.x. abstraction layer.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services