lameiro / cx_oracle_on_ctypes Goto Github PK
View Code? Open in Web Editor NEWcx_Oracle on ctypes
cx_Oracle on ctypes
There's a line that's currently commented out:
https://github.com/lameiro/cx_oracle_on_ctypes/blob/master/cx_Oracle/variable_factory.py#L109
When I execute SQL against one of my Oracle tables, one of the column types is OBJECTVAR
so I get an error: cx_Oracle.custom_exceptions.NotSupportedError: Type <cx_Oracle.variable_type.VariableType object at 0x108fcf128> (vt_Object) not found in mapping to python type
Thanks!
python version - 3.7.5rc1(64bit)
windows 10 64 bit
pip version - 19.3.1
pip install cx_Oracle
Requirement already satisfied: cx_Oracle in c:\python\lib\site-packages (7.2.3)
now in python terminal:
import cx_Oracle
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\rames\AppData\Roaming\Python\Python37\site-packages\cx_Oracle_init_.py", line 10, in
from custom_exceptions import Warning, Error, InterfaceError, DatabaseError, DataError, OperationalError, IntegrityError, InternalError, ProgrammingError, NotSupportedError
ModuleNotFoundError: No module named 'custom_exceptions'
I test this module on:
Debian 8
[PyPy 2.4.0 with GCC 4.9.2] on linux2
Oracle 12 as client.
But it seems only to be compatible only with oracle 11 -10 ..
Do you think you will support oracle 12 very soon.. or in any way can you point me out how to make it work on oracle 12 ?
In case i fix it I will pull the code in case I succed
regards,
Matteo
Hi,
There is difference between stock cx_Oracle and cx_oracle_on_ctypes for $subj.
cx_Oracle:
>>> cu.execute("""SELECT 'Test\0NameForDesc' from dual""").description
[("'TEST\x00NAMEFORDESC'", <type 'cx_Oracle.FIXED_CHAR'>, 16, 16, 0, 0, 1)]
cx_oracle_on_ctypes:
>>>> cu.execute("""SELECT 'Test\0NameForDesc' from dual""").description
[("'TEST", <class 'cx_Oracle.stringvar.FIXED_CHAR'>, 16, 16, 0, 0, 1)]
SqlAlchemy crash when searching with 'Binary'.
We fixed this by adding:
if python3_or_better():
Binary = bytes
else:
Binary = str
in the init.py file
Hi,
Context manager utils.ReplaceArgtypeByVoidPointerContextManager can fail to restore initial oci function arguments in multi-threaded application.
Issue can be reproduced with following script(once in ~5 runs on my machine):
import cx_Oracle
from threading import Thread
CNT = 40
class TSelector(Thread):
def run(self):
con = cx_Oracle.connect('test/test@TDB')
cur = cur_acc = con.cursor()
cur.execute('SELECT 1 FROM DUAL')
for row in cur:
print('Thread: %s Got row: %s' % (id(self), row,))
cur.close()
con.close()
threads = [TSelector() for _ in range(CNT)]
[t.start() for t in threads]
[t.join() for t in threads]
Here is example output:
Exception in thread Thread-7:
Traceback (most recent call last):
File "/usr/lib64/pypy-2.6.1/lib-python/2.7/threading.py", line 806, in __bootstrap_inner
self.run()
File "t.py", line 7, in run
con = cx_Oracle.connect('test/test@TDB')
File "/home/porta-one/cx_Oracle/connection.py", line 42, in __init__
self.environment = Environment.new_from_scratch(threaded, events, encoding, nencoding)
File "/home/porta-one/cx_Oracle/environment.py", line 46, in new_from_scratch
env = Environment(handle)
File "/home/porta-one/cx_Oracle/environment.py", line 25, in __init__
status = oci.OCIHandleAlloc(handle, byref(error_handle_as_void_p), oci.OCI_HTYPE_ERROR, 0, argtypes[4]())
File "/usr/lib64/pypy-2.6.1/lib_pypy/_ctypes/function.py", line 714, in __call__
funcptr = self._getfuncptr(argtypes, restype, thisarg)
File "/usr/lib64/pypy-2.6.1/lib_pypy/_ctypes/function.py", line 421, in _getfuncptr
ptr = self._getfuncptr_fromaddress(argtypes, restype)
File "/usr/lib64/pypy-2.6.1/lib_pypy/_ctypes/function.py", line 410, in _getfuncptr_fromaddress
ffiargs = [argtype.get_ffi_argtype() for argtype in argtypes]
AttributeError: 'AnythingGoes' object has no attribute 'get_ffi_argtype'
One more:
File "/usr/lib64/pypy-2.6.1/lib-python/2.7/threading.py", line 806, in __bootstrap_inner
self.run()
File "t.py", line 7, in run
con = cx_Oracle.connect('test/test@TDB')
File "/usr/lib64/pypy-2.6.1/site-packages/cx_Oracle/connection.py", line 61, in __init__
self.connect(mode, twophase, newpassword)
File "/usr/lib64/pypy-2.6.1/site-packages/cx_Oracle/connection.py", line 69, in connect
OCIHandleAlloc(self.environment, self.server_handle, oci.OCI_HTYPE_SERVER, "Connection_Connect(): allocate server handle")
File "/usr/lib64/pypy-2.6.1/site-packages/cx_Oracle/pythonic_oci.py", line 31, in OCIHandleAlloc
status = oci.OCIHandleAlloc(environment.handle, byref(handle), handle_type, 0, argtypes[4]())
File "/usr/lib64/pypy-2.6.1/lib_pypy/_ctypes/function.py", line 720, in __call__
return CFuncPtr.__call__(self, *args)
File "/usr/lib64/pypy-2.6.1/lib_pypy/_ctypes/function.py", line 350, in __call__
self._convert_args(argtypes, args, kwargs))
File "/usr/lib64/pypy-2.6.1/lib_pypy/_ctypes/function.py", line 579, in _convert_args
raise ArgumentError(str(e))
ArgumentError: expected LP_c_void_p instance instead of LP_LP_struct_OCIServer
Let's make a release and upload the package to Pypi.
I can help with that.
Do you know why cx_oracle_on_ctypes can't find libclntsh.so library? Standard cx_Oracle can find it without me manually exporting LD_LIBRARY_PATH (because i have proper path set in /etc/ld.so.conf.d/oracle.conf), but somehow cx_oracle_on_ctypes ignores this path.
$ python -c 'import cx_Oracle'
$ export PYTHONPATH=/home/kossak/apps/cx_oracle_on_ctypes
$ python -c 'import cx_Oracle'
Traceback (most recent call last):
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/oci.py", line 2, in
from cx_Oracle.oci_generated_12 import *
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/oci_generated_12.py", line 613, in
_libs["libclntsh.so.12.1"] = load_library("libclntsh.so.12.1")
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/oci_generated_12.py", line 367, in load_library
raise ImportError("%s not found." % libname)
ImportError: libclntsh.so.12.1 not found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/oci.py", line 5, in
from cx_Oracle.oci_generated_11 import *
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/oci_generated_11.py", line 596, in
_libs["libclntsh.so.11.1"] = load_library("libclntsh.so.11.1")
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/oci_generated_11.py", line 366, in load_library
raise ImportError("%s not found." % libname)
ImportError: libclntsh.so.11.1 not found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/oci.py", line 8, in
from cx_Oracle.oci_generated_10 import *
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/oci_generated_10.py", line 596, in
_libs["libclntsh.so.10.1"] = load_library("libclntsh.so.10.1")
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/oci_generated_10.py", line 366, in load_library
raise ImportError("%s not found." % libname)
ImportError: libclntsh.so.10.1 not found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/init.py", line 13, in
from cx_Oracle.connection import Connection
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/connection.py", line 4, in
from cx_Oracle import oci
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/oci.py", line 10, in
raise Exception("Could not import oracle libraries version 12, 11 or 10. Giving up. Don't forget to set your ORACLE_HOME and LD_LIBRARY_PATH.")
Exception: Could not import oracle libraries version 12, 11 or 10. Giving up. Don't forget to set your ORACLE_HOME and LD_LIBRARY_PATH.
$ export LD_LIBRARY_PATH=/opt/oracle/oracle/product/12.1.0/client_1/lib
$ python -c 'import cx_Oracle'
$ echo $?
0
oci_generated_10.py
_libs["libclntsh.so.10.1"]
oci_generated_11.py
_libs["libclntsh.so.11.1"]
on windows it's "oci.dll" not "libclntsh*".
also see:http://docs.oracle.com/cd/B28359_01/appdev.111/b28390/install.htm
Since this is a pure python-package, there seems no reason
not to have a setup.py.
I can't get it to run on pypy. I can import original cx_Oracle (using standard python), so i guess all env vars are correctly specified.
$ python -c 'import cx_Oracle'
$ export PYTHONPATH=/home/kossak/apps/cx_oracle_on_ctypes
$ pypy -c 'import cx_Oracle'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/__init__.py", line 10, in <module>
from custom_exceptions import Warning, Error, InterfaceError, DatabaseError, DataError, OperationalError, IntegrityError, InternalError, ProgrammingError, NotSupportedError
ImportError: No module named 'custom_exceptions'
$ python -c 'import cx_Oracle'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/__init__.py", line 10, in <module>
from custom_exceptions import Warning, Error, InterfaceError, DatabaseError, DataError, OperationalError, IntegrityError, InternalError, ProgrammingError, NotSupportedError
ImportError: No module named 'custom_exceptions'
$ python -V
Python 3.5.2 :: Anaconda 4.2.0 (64-bit)
$ pypy -V
Python 3.3.5 (619c0d5af0e5, Oct 08 2016, 21:08:33)
[PyPy 5.5.0-alpha0 with GCC 4.8.2]
$ ls -l /home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/custom_exceptions.py
-rwxr-xr-x 1 kossak kossak 723 Oct 20 16:13 /home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/custom_exceptions.py*
$ cd /home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle
$ pypy __init__.py
Traceback (most recent call last):
File "__init__.py", line 10, in <module>
from custom_exceptions import Warning, Error, InterfaceError, DatabaseError, DataError, OperationalError, IntegrityError, InternalError, ProgrammingError, NotSupportedError
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/custom_exceptions.py", line 1, in <module>
from utils import python3_or_better
File "/home/kossak/apps/cx_oracle_on_ctypes/cx_Oracle/utils.py", line 31, in <module>
cxString = unicode
NameError: name 'unicode' is not defined
I'm on Linux Mint 18 x64 but get the same error on Oracle Linux Server 6.5 x64
I attempted to create an Oracle connection that would return numbers as Decimal instances, instead of float. Code was copied from https://github.com/oracle/python-cx_Oracle/blob/master/samples/ReturnNumbersAsDecimals.py
from decimal import Decimal
import cx_Oracle
def NumbersAsDecimal(cursor, name, defaultType, size, precision, scale):
"""Helper class so we can get Decimals out of the database."""
if defaultType == cx_Oracle.NUMBER:
return cursor.var(str, 100, cursor.arraysize, outconverter=Decimal)
dbcon = cx_Oracle.connect(dsn='DSN STRING', user='username', password='pass')
dbcon.outputtypehandler = NumbersAsDecimal
dbcur = dbcon.cursor()
dbcur.execute("select * from dual")
This works on regular cx_Oracle, however cx_oracle_on_ctypes crashes:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/user/dsp/envpypy/site-packages/cx_Oracle/cursor.py", line 305, in execute
self.perform_define()
File "/home/user/dsp/envpypy/site-packages/cx_Oracle/cursor.py", line 132, in perform_define
var = variable_factory.define(self, self.fetch_array_size, pos)
File "/home/user/dsp/envpypy/site-packages/cx_Oracle/variable_factory.py", line 137, in define
var = self.define_helper(cursor, param, position, num_elements)
File "/home/user/dsp/envpypy/site-packages/cx_Oracle/variable_factory.py", line 171, in define_helper
var = self.new_by_output_type_handler(cursor, param, cursor.connection.outputtypehandler, var_type, size, num_elements)
AttributeError: 'VariableFactory' object has no attribute 'new_by_output_type_handler
Python version is:
Python 2.7.10 (5.1.2+dfsg-1~16.04, Jun 16 2016, 17:37:42)
[PyPy 5.1.2 with GCC 5.3.1 20160413]
Connection.begin method is missing in cx_oracle_on_ctypes, present in C cx_Oracle.
Hi,
I've profiled cx_oracle_on_ctypes on PyPy-2.6.1 with vprof profiler. vprof is a statistical profiler, so it shouldn't affect relative time, spent in different code parts.
Results show that for simple INSERT with 2 variables:
import cx_Oracle
conn = cx_Oracle.connect('user/pass@DB')
cr = conn.cursor()
sql = 'INSERT INTO TEST(num, chr) values(:num, :chr)'
for i in range(10**3):
cr.execute(sql, {'num': i, 'chr': 'test_string'})
conn.commit()
cr.close()
conn.close()
68% of CPU time is spent on variable binding, and 27% is spent on execute().
Here are profiling results:
100.0% <module> t.py:1
69.3% execute cx_Oracle/cursor.py:265
46.0% set_bind_variables cx_Oracle/cursor.py:160
45.3% set_bind_variable_helper cx_Oracle/cursor.py:209
43.9% set_value cx_Oracle/variable.py:225
43.5% set_single_value cx_Oracle/variable.py:237
32.4% __call__ /usr/lib64/pypy-2.6.1/lib_pypy/_ctypes/function.py:710
29.9% <module> cx_Oracle/__init__.py:1
26.5% _call_funcptr /usr/lib64/pypy-2.6.1/lib_pypy/_ctypes/function.py:368
20.7% internal_execute cx_Oracle/cursor.py:135
20.1% set_value cx_Oracle/numbervar.py:136
19.8% <module> cx_Oracle/custom_exceptions.py:1
19.8% <module> cx_Oracle/utils.py:1
19.8% <module> cx_Oracle/oci.py:1
17.7% set_value cx_Oracle/stringvar.py:98
15.8% set_value_from_integer cx_Oracle/numbervar.py:232
11.6% <module> cx_Oracle/oci_generated_11.py:1
8.9% _as_ffi_pointer_ /usr/lib64/pypy-2.6.1/lib_pypy/_ctypes/pointer.py:125
7.7% <module> cx_Oracle/oci_generated_12.py:1
7.2% new_from_object cx_Oracle/buffer.py:36
7.0% set_row_count cx_Oracle/cursor.py:354
6.7% OCIAttrGet cx_Oracle/pythonic_oci.py:7
6.3% load_library cx_Oracle/oci_generated_12.py:359
6.3% getpaths cx_Oracle/oci_generated_12.py:383
6.3% __setitem__ /usr/lib64/pypy-2.6.1/lib_pypy/_ctypes/array.py:185
6.2% _compile /usr/lib64/pypy-2.6.1/lib-python/2.7/re.py:230
6.2% getplatformpaths cx_Oracle/oci_generated_12.py:519
6.2% compile /usr/lib64/pypy-2.6.1/lib-python/2.7/re.py:192
6.2% compile /usr/lib64/pypy-2.6.1/lib-python/2.7/sre_compile.py:567
5.4% _create_ld_so_cache cx_Oracle/oci_generated_12.py:457
4.7% glob /usr/lib64/pypy-2.6.1/lib-python/2.7/glob.py:18
I've checked code, however it is not clear if it is possible to improve variable binding performance.
Please advise.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.