the SOCI library

Simple Oracle Call Interface


Download SOCI
What is SOCI?
Documentation and tutorial
Why did I write it?
Other libraries

Download SOCI

save  soci-1.0.1.tar.gz (16 kB)
save  soci-1.0.1.zip (18 kB)

What is SOCI?

SOCI stands for Simple Oracle Call Interface and that's exactly what it is.

It is a very simple library for C++ programmers that makes the illusion of embedding SQL queries in regular C++ code, but staying entirely within the Standard C++ (no special preprocessor, etc.).

The motivating example is:

#include "soci.h"
#include <iostream>
#include <string>

using namespace SOCI;
using namespace std;

int main()
{
    Session sql("dbname", "username", "password");

    int count;
    sql << "select count(*) from person", into(count);

    cout << "There are " << count << " rows in table person.\n";

    int newId = 7;
    string newName = "John";
    sql << "insert into person(id, name)"
        " values(:newid, :newname)", use(newId), use(newName);

}

In other words, SOCI allows to use the SQL syntax with as little additions as possible - the accompanying C++ code is reduced to the minimum.
As a result, SOCI tries to be the easiest DB library for C++ programmers.

Please note that the SOCI library is not intended to completely cover the functionality of the underlying OCI library - only the most frequently used features are provided. If there is any need to use more advanced features of OCI, like call-back functions, distributed transactions, etc., it is possible to do so by accessing the low-level OCI handles which are available as public members of respective SOCI classes.

Why did I write it?

Short answer: I wrote the SOCI library because I do not like the other libraries.

Long answer:
Most of the libraries providing access to the Oracle databases (relying on OCI calls) seem to be quite low-level in the sense that even after wrapping some functionality into classes, the OCI concepts and way of thinking are still visible. Moreover, some of the libraries seem to concentrate only on the possibility to provide classes and methods, which is just a fraction of what C++ allows to do. It is just a shame that most library writers ignore other language features.
There is also a group of advanced and very interesting libraries that try to provide completely different interface, for example based on the STL or streams concepts. However, I tend to think that they introduce an extensive impedance-mismatch between the SQL level and the interface they implement. This mismatch is not necessarily good.
Since the SQL schema is usually known to the programmer and most of the programmers know the SQL syntax, there is a lot of sense in keeping both of them explicit in the program that accesses the database. This approach is taken by a lot of programming environments, and some of them even allow to embed SQL in 3GL code. For C++ programmers, embedding SQL is available with Pro*C++, but it is based on special preprocessing step that loses type information needed for further compilation phases (so that Pro*C++ and for example template code do not mix).
Apparently there is a niche for a library that would exploit templates and operator overloading to provide the most natural syntax and that will stay entirely within the Standard C++ to enable correct collaboration with any other language feature that the programmer may wish to use. The SOCI library fills this gap.

Other libraries

For the convenience of those who may want to try alternatives, here's the short (and not intended to be complete) list of available libraries for C++ programmers accessing Oracle databases:

http://orapp.sourceforge.net/
http://ocicpplib.sourceforge.net/
http://otl.sourceforge.net/home.htm
http://otn.oracle.com/tech/oci/occi/index.html


Go to top