vrogier / ocilib

OCILIB (C and C++ Drivers for Oracle) - Open source C and C++ library for accessing Oracle databases
http://www.ocilib.net
Apache License 2.0
326 stars 119 forks source link
api driver oci ocilib oracle oracle-database sql

# OCILIB - C and C++ Drivers for Oracle Build Status Code Analysis

1. About

OCILIB is an open source and cross platform Oracle Driver that delivers efficient access to Oracle databases.

The OCILIB library :

OCILIB is developed by Vincent Rogier. Get the latest package, install and enjoy it!

2. License

The source code is free source code licensed under Apache License, Version 2.0 - see LICENSE file

3. Features

5. Installation

Windows platforms

GNU (Unix / Linux) platforms

Make sure Oracle and OCILIB libraries paths are defined in your shared library environment variable You need to provide extra configure parameters when using Instant Clients – see Installation section)

6. Examples

Example of a minimal OCILIB C application

#include "ocilib.h"

int main(int argc, char *argv[])
{
    OCI_Connection* cn;
    OCI_Statement* st;
    OCI_Resultset* rs;

    OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT);

    cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
    st = OCI_StatementCreate(cn);

    OCI_ExecuteStmt(st, "select intcol, strcol from table");

    rs = OCI_GetResultset(st);

    while (OCI_FetchNext(rs))
    {
        printf("%i - %s\n", OCI_GetInt(rs, 1), OCI_GetString(rs,2));
    }

    OCI_Cleanup();

    return EXIT_SUCCESS;
}

Example of a minimal OCILIB C++ application

#include "ocilib.hpp"

using namespace ocilib;

int main(void)
{
    try
    {
        Environment::Initialize();

        Connection con("db", "usr", "pwd");

        Statement st(con);
        st.Execute("select intcol, strcol from table");

        Resultset rs = st.GetResultset();
        while (rs.Next())
        {
            std::cout << rs.Get<int>(1) << " - " <<  rs.Get<ostring>(2) << std::endl;
        }
    }
    catch(std::exception &ex)
    {
         std::cout << ex.what() << std::endl;
    }

    Environment::Cleanup();

    return EXIT_SUCCESS;
}