Skip to content

c-bik/erloci

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 mathias@brossard.org. 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

About

Erlang Wrapper for the Oracle Call Interface (OCI)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published