-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] HUE-2334. Add cx_Oracle to external dependency
- Loading branch information
bc Wong
committed
Oct 28, 2014
1 parent
94d5bb1
commit c6f0ffa
Showing
102 changed files
with
26,906 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
Linux Build Hints | ||
----------------- | ||
(Tested on RedHat 4.x, Gentoo 2008.0, Ubuntu 8.x, and Debian 4.x) | ||
These hints are based on using Oracle's instantclient_11_1. It is necessary | ||
to download both 'instantclient-linux-basic' and 'instantclient-sdk-linux' from | ||
oracle.com in order to successfully compile. | ||
|
||
http://www.oracle.com/technology/software/tech/oci/instantclient/index.html | ||
|
||
Each compressed tarball needs to be extracted to the exact same location. | ||
Uncompress and untar each file from the same location in order to achieve this | ||
result. If placing into a system area such as /opt or /usr/local, make sure to | ||
have the correct permissions for writing to these filesystems and/or | ||
directories. It is advisable to use the same account from start to finish while | ||
installing cx_Oracle in order not to clobber the pre-set environment variables | ||
set below. | ||
|
||
It is necessary to set environment variables ORACLE_HOME and LD_LIBRARY_PATH | ||
inside $HOME/.profile in order for cx_Oracle to import properly after | ||
installation and in order to build correctly. Using a text editor add the | ||
settings below to $HOME/.profile making sure to change the location of your | ||
actual installation path. | ||
|
||
Example ($HOME/.profile): | ||
------------------------- | ||
export ORACLE_HOME=[your installation path]/instantclient_11_1 | ||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME | ||
|
||
To put these variables into the working shell env, either source .profile | ||
(. $HOME/.profile) or execute each export statement above from a shell | ||
individually to set these variables. If these are not added to $HOME/.profile | ||
they will need to be manually set each time cx_Oracle is loaded into Python. | ||
|
||
After both packages are untarred to there installation location a link needs | ||
to be made inside the instantclient_11_1 directory. If you are using a | ||
different version of the instant client simply adjust the link per the version | ||
of libclntsh.so. | ||
|
||
Steps: | ||
------ | ||
cd $ORACLE_HOME | ||
ln -s libclntsh.so.x.x libclntsh.so | ||
|
||
Continue to step: Building and Compilation. | ||
|
||
|
||
OS X Build Hints | ||
---------------- | ||
(Tested on Leopard 10.5.x) | ||
The procedures for OS X are almost idential to Linux except for the package | ||
names and a few environmental caveats. For OS X it is necessary to download | ||
both 'instantclient-basic-macosx' and 'instantclient-sdk-macosx'. Download and | ||
extract each file per the build hints for Linux. | ||
|
||
For OS X it is necessary to set environment variables ORACLE_HOME, | ||
LD_LIBRARY_PATH and DYLD_LIBRARY_PATH inside $HOME/.profile and start a new | ||
shell before testing cx_Oracle. If .profile does not exist, simply create one | ||
with a text editor and add the necessary path info to these variables. | ||
|
||
Example ($HOME/.profile): | ||
------------------------- | ||
export ORACLE_HOME=[your installation path]/instantclient_11_1 | ||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME | ||
export DYLD_LIBRARY_PATH=$ORACLE_HOME | ||
|
||
The variables placed inside $HOME/.profile need to be set prior to building. | ||
Therefore, source .profile (. $HOME/.profile) or execute each export statement | ||
above from a shell individually to set these variables. Not having | ||
DYLD_LIBRARY_PATH set inside $HOME/.profile prior to building will cause a | ||
compilation error regardless of being set in the current shell's env. | ||
|
||
After both packages are untarred a link needs to be made inside the | ||
instantclient_11_1 directory. If you are using a different version of the | ||
instant client simply adjust the link per the version of libclntsh.dylib. | ||
|
||
Steps: | ||
------ | ||
cd $ORACLE_HOME | ||
ln -s libclntsh.dylib.x.x libclntsh.dylib | ||
|
||
Continue to step: Building and Compilation. | ||
|
||
|
||
Building and Compilation | ||
------------------------ | ||
Use the provided setup.py to build and install the module which makes use of | ||
the distutils module. Note that on Windows, I have used mingw32 | ||
(http://www.mingw.org) and the module will not build with MSVC without | ||
modification. The commands required to build and install the module are as | ||
follows: | ||
|
||
python setup.py build | ||
python setup.py install | ||
|
||
|
||
Testing (Post Installation Quick Test) | ||
-------------------------------------- | ||
A very quick installation test can be performed from the command line using | ||
the Python interpreter. Below is an example of how this done. After importing | ||
cx_Oracle there should be a line containing only '>>>' which indicates the | ||
library successfully loaded. | ||
|
||
$ python | ||
Python 2.5.2 (r252:60911, Oct 25 2008, 19:37:28) | ||
[GCC 4.1.2 (Gentoo 4.1.2 p1.1)] on linux2 | ||
Type "help", "copyright", "credits" or "license" for more information. | ||
>>> import cx_Oracle | ||
>>> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
//----------------------------------------------------------------------------- | ||
// Buffer.c | ||
// Defines buffer structure and routines for populating it. These are used | ||
// to translate Python objects into the buffers needed for Oracle, including | ||
// Unicode or buffer objects. | ||
//----------------------------------------------------------------------------- | ||
|
||
// define structure for abstracting string buffers | ||
typedef struct { | ||
const void *ptr; | ||
Py_ssize_t numCharacters; | ||
Py_ssize_t size; | ||
PyObject *obj; | ||
} udt_Buffer; | ||
|
||
|
||
//----------------------------------------------------------------------------- | ||
// cxBuffer_Init() | ||
// Initialize the buffer with an empty string. Returns 0 as a convenience to | ||
// the caller. | ||
//----------------------------------------------------------------------------- | ||
static int cxBuffer_Init( | ||
udt_Buffer *buf) // buffer to initialize | ||
{ | ||
buf->ptr = NULL; | ||
buf->size = 0; | ||
buf->numCharacters = 0; | ||
buf->obj = NULL; | ||
return 0; | ||
} | ||
|
||
|
||
//----------------------------------------------------------------------------- | ||
// cxBuffer_Copy() | ||
// Copy the contents of the buffer. | ||
//----------------------------------------------------------------------------- | ||
static int cxBuffer_Copy( | ||
udt_Buffer *buf, // buffer to copy into | ||
udt_Buffer *copyFromBuf) // buffer to copy from | ||
{ | ||
buf->ptr = copyFromBuf->ptr; | ||
buf->size = copyFromBuf->size; | ||
buf->numCharacters = copyFromBuf->numCharacters; | ||
Py_XINCREF(copyFromBuf->obj); | ||
buf->obj = copyFromBuf->obj; | ||
return 0; | ||
} | ||
|
||
|
||
//----------------------------------------------------------------------------- | ||
// cxBuffer_FromObject() | ||
// Populate the string buffer from a unicode object. | ||
//----------------------------------------------------------------------------- | ||
static int cxBuffer_FromObject( | ||
udt_Buffer *buf, // buffer to fill | ||
PyObject *obj, // object (string or Unicode object) | ||
const char *encoding) // encoding to use, if applicable | ||
{ | ||
if (!obj) | ||
return cxBuffer_Init(buf); | ||
if (encoding && PyUnicode_Check(obj)) { | ||
buf->obj = PyUnicode_AsEncodedString(obj, encoding, NULL); | ||
if (!buf->obj) | ||
return -1; | ||
buf->ptr = PyBytes_AS_STRING(buf->obj); | ||
buf->size = PyBytes_GET_SIZE(buf->obj); | ||
buf->numCharacters = PyUnicode_GET_SIZE(obj); | ||
} else if (PyBytes_Check(obj)) { | ||
Py_INCREF(obj); | ||
buf->obj = obj; | ||
buf->ptr = PyBytes_AS_STRING(buf->obj); | ||
buf->size = buf->numCharacters = PyBytes_GET_SIZE(buf->obj); | ||
#if PY_MAJOR_VERSION < 3 | ||
} else if (PyBuffer_Check(obj)) { | ||
if (PyObject_AsReadBuffer(obj, &buf->ptr, &buf->size) < 0) | ||
return -1; | ||
Py_INCREF(obj); | ||
buf->obj = obj; | ||
buf->numCharacters = buf->size; | ||
#endif | ||
} else { | ||
PyErr_SetString(PyExc_TypeError, CXORA_TYPE_ERROR); | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
#define cxBuffer_Clear(buf) Py_XDECREF((buf)->obj) | ||
|
Oops, something went wrong.