Code Monkey home page Code Monkey logo

erloci's Introduction

erloci - An Erlang wrapper for the Oracle Call Interface

Compiling

We assume you have rebar somewhere on your path. Rebar will take care of the Erlang and C++ sources. rebar compile Please check the rebar manual for how to add erloci as a dependency to your project.

3d party dependencies

Threadpool

The threadpool code (threadpool.cpp/h) is developed by Mathias Brossard [email protected]. His threadpool library is hosted at https://github.com/mbrossard/threadpool. This library is unused (not linked) in a Windows environment. For an easier installation process we include the required threadpool files in the erloci repo. So this is NOT a dependency you have to resolve by yourself.

Oracle Call Interface (OCI)

OCI provides a high performance, native 'C' language based interface to the Oracle Database. There is no ODBC layer between your application and the database. Since we don't want to distribute the Oracle Code you MUST download the OCI Packages (basic and devel) from the Oracle Website: http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html.

In order to successfully compile and link 'erloci' you must set the variables "CXXFLAGS" and "DRV_LDFLAGS" in rebar.config.

In our case we just created a folder 'lib' containing symlinks pointing to the downloaded libraries and header files.

manually installing the OCI libraries system wide (Linux)

Since the OCI libraries do not come as RPMs or DEBs that you can install with your package manager of choice, as well as the downloaded library doesn't provide a script (e.g. Makefile) to install it system wide you have to install it by yourself. However this is not required, you can always put the extracted library files into LD_LIBRARY_PATH. So if you really need this, here is the way to go:

  1. Create the file 'oci.pc' in /usr/lib/pkgconfig (if not present)
  2. Copy the library to an appropriate place (e.g. /usr/lib/oracle/)
  3. Put the following lines in oci.pci. You may need to modify the path and other info as seem fit for your system
prefix=/usr/lib/oracle/11.2/client
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${exec_prefix}/include
 
Name: oci
Description: Oracle OCI client libraries
Version: 11.2
Libs: -L${libdir} -lclntsh -lnnz11 -locci
Cflags: -I${includedir}

Compile ERLOCI in Windows

Navigate to the Git repo path of ERLOCI from a Visual Studio Command Prompt and run the following: rebar.bat compile -C rebar.config.win

Please refer to rebar for further details on how to build rebar or rebar.bat in Windows.

Usage

{ok, Pool} = oci_session_pool:start_link("127.0.0.1", 1521, {service, "db.local"}, "dbauser", "supersecret",[]).
%% getting a new session from the pool. (parameterized module) 
Session = oci_session_pool:get_session(Pool).

%% execute_sql can execute INSERT, UPDATE, DELETE, and SELECT statements
MaxRowsToReturn = 10.
ok = Session:execute_sql("select * from test_erloci", [], MaxRowsToReturn).

%% in the case of the select, we can fetch MaxRowsToReturn rows at a time.
FirstTenRows = Session:get_rows().

%% as long as we have an 'open' select statement we can get the column information
Columns = Session:get_columns().

%% we can fetch the rows until we get an empty list
%% Session stays open and we can resuse it for further queries otherwise we close the session
Session:close().

%% if we are really done we shutdown the session pool
oci_session_pool:stop(Pool).

TODOs

  1. Better session and pool monitoring
  2. Log handling
  3. Improve testing

erloci's People

Contributors

dergraf avatar c-bik avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.