Giter Site home page Giter Site logo

oracle / python-cx_oracle Goto Github PK

View Code? Open in Web Editor NEW
880.0 75.0 359.0 7.49 MB

Python interface to Oracle Database now superseded by python-oracledb

Home Page: https://oracle.github.io/python-cx_Oracle

License: Other

Python 39.88% C 56.38% PLSQL 3.73%
python database-connector oracle-db oracle-database db-connection python-library python-module odpi

python-cx_oracle's People

Contributors

alexhenrie avatar andribas404 avatar anthony-tuininga avatar cjbj avatar ddriddle avatar draco94 avatar glenwalker avatar hoops avatar jakobgurn avatar osblaineora avatar rickeylev avatar shaib avatar vnaydionov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-cx_oracle's Issues

6.0rc1: linux rpm

For installation issues:

Answer the following questions:

  1. What is your version of Python? Is it 32-bit or 64-bit?
    Python 3.5.3

  2. What is your version of cx_Oracle?
    rpm -qa | grep cx_
    cx_Oracle-6.0rc1-1.x86_64

  3. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?
    rpm -qa | grep oracle
    oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64
    rpm -ql oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64
    /usr/lib/oracle/12.2/client64/bin/

  4. What is your version of the Oracle Database?
    TimesTen 11g Release 2 (11.2.2.8.0)

  5. What is your OS and version?
    Linux 4.10.14-200.fc25.x86_64 ( Fedora 25 )

  6. What compiler version did you use? For example, with GCC, run
    gcc --version.
    gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1)

  7. What environment variables did you set? How exactly did you set them?
    export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH

  8. What exact command caused the problem (e.g. what command did you try to
    install with)? Who were you logged in as?
    as root:
    dnf install /home/az/Downloads/cx_Oracle-6.0rc1-py35-1.x86_64.rpm

  9. What error(s) you are seeing?
    in python3.5
    import cx_Oracle
    fails with wit "unable to import module"
    upon digging it appears that the rpm installs the cx module in the non standard location -
    rpm -ql cx_Oracle-6.0rc1-1
    /opt/rh/rh-python35/root/usr/lib64/python3.5/site-packages/

vs:
/usr/lib[64]/python3.5/site-packages/

the manual install of the wheel:
python3 install /home/az/Downloads/cx_Oracle-6.0rc1-cp35-cp35m-manylinux1_x86_64.whl
places the cx_ package into the standard - usr/lib64/python3.5/site-packages/

Also,
i'm not sure of the wheel installs the samples and tests files provided by rpm ( /usr/share/doc/cx_Oracle-6.0rc1). If it doesn't, it would be great to add to the wheel, please.

ORA-04043: object SDO_ELEM_INFO_ARRAY does not exist on Oracle 11.2.0.4

Describe exactly what you did and what you want to happen:

First of all, thanks a lot for your hard work and for bringing the feature to build & write SDO_GEOMETRY objects!

I've upgrade my cx_Oracle version to 5.3 in order to be able to build / write SDO_GEOMETRY data (without SQL or PL/SQL) and I am currently testing my code with the following matching Oracle versions (in order not to run into an OCI-22351):

  • Oracle Instant Client 11.2.0.4 => Oracle Database 11.2.0.4
  • Oracle Instant Client 12.1.0.2 => Oracle Database 12.1.0.2

I used the sample code from InsertGeometry.py for writing some sample data:

...
typeObj = connection.gettype("SDO_GEOMETRY")
elementInfoTypeObj = connection.gettype("SDO_ELEM_INFO_ARRAY")
ordinateTypeObj = connection.gettype("SDO_ORDINATE_ARRAY")
...

This works fine for 12.1.0.2, but on 11.2.0.4, I'm receiving the following error:

elementInfoTypeObj = connection.gettype("SDO_ELEM_INFO_ARRAY")
cx_Oracle.DatabaseError: ORA-04043: object SDO_ELEM_INFO_ARRAY does not exist

In order to fix it, I had to add the MDSYS schemata:

typeObj = connection.gettype("MDSYS.SDO_GEOMETRY")
elementInfoTypeObj = connection.gettype("MDSYS.SDO_ELEM_INFO_ARRAY")
ordinateTypeObj = connection.gettype("MDSYS.SDO_ORDINATE_ARRAY")

Not sure if this is actually an issue by cx_Oracle or just related to my 11.2.0.4 database, but I wanted to report the behavior. If this issue also encountered during your tests, the example maybe could be extended to use the fully qualified type to be compatible with all Oracle Database versions.

Thanks in advance!

Answer the following questions:

  1. What is your version of Python? Is it 32-bit or 64-bit?

Python 3.5.1 / 64-Bit

  1. What is your version of cx_Oracle?

5.3

  1. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?
Oracle Instant Client 11.2.0.4 / Linux 64-Bit
/opt/oracle-ic_11.2.0.4

&

Oracle Instant Client 12.1.0.2 / Linux 64-Bit
/opt/oracle-ic_12.1.0.2

cx_Oracle has been installed in two different environments to be linked against the according version.

  1. What is your OS and version?

Oracle Linux Server release 7.1 / 64-Bit

  1. What compiler version did you use? For example, with GCC, run
    gcc --version.

gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)

  1. What environment variables did you set? How exactly did you set them?
export ORACLE_HOME=/opt/oracle-ic_11.2.0.4
export LD_LIBRARY_PATH=$ORACLE_HOME

cx_Oracle Package Not working inside Crontab

I am using cx_Oracle library in my python script. My code works fine if I directly execute by python script from Linux terminal but when I put it in crontab I am getting following error.

!!DatabaseError: DPI-1047: Oracle Client library cannot be loaded: libclntsh.so: cannot open shared object file: No such file or directory. See https://oracle.github.io/odpi/doc/installation.html for help

DPI-1005: unable to acquire Oracle environment handle
!!Traceback (most recent call last):
import cx_Oracle
!!DatabaseError: DPI-1005: unable to acquire Oracle environment handle

I googled this issue and It seems some environment variable missing when it ran using crontab.
I try to export following in crontab but it does not work.

export LD_LIBRARY_PATH='/usr/lib/oracle/11.2/client64/lib'

If I remove cx_Oracle package other code runs fine. I have only one version of python installed on my machine.

  1. What is your version of Python? Is it 32-bit or 64-bit?
    Python 2.6 . 64 bit

  2. What is your version of cx_Oracle?
    Version 6.0b1

  3. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?
    oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

  4. What is your OS and version?
    CentOS 6.7

  5. What environment variables did you set? How exactly did you set them?
    export LD_LIBRARY_PATH='/usr/lib/oracle/11.2/client64/lib'

Encoding issues

I have the following simple code for python (version 3.6.1 x64 Windows):

# -*- coding: utf-8 -*-
import cx_Oracle
import os

os.environ["NLS_LANG"] = "RUSSIAN_RUSSIA.AL32UTF8"

conn = cx_Oracle.connect("user/pass@//host:1521/dbname")
cur = conn.cursor()

print(cx_Oracle.__version__)

print(conn.encoding)
print(conn.nencoding)

cur.execute("select 'Значение' from dual")
res = cur.fetchone()

cur.close()
conn.close()

print(res)

With cx_Oracle version 5.3 it works as expected and gives the following output:

5.3
UTF-8
UTF-8
('Значение',)

But with the 6.02b version it becomes broken.

  1. It throws exception about unicode character in query:
6.0b2
ASCII
ASCII
Traceback (most recent call last):
  File "C:/Users/SBT-Chernopyatov-AS/PycharmProjects/CUP_Fetcher/ptest_602.py", line 15, in <module>
    cur.execute("select 'Значение' from dual")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 8-15: ordinal not in range(128)
  1. If we fix it by using ".encode('utf8')" or by changing query to "select * from table_with_unicode_data", it gives '????????' for output.
  2. If we try to get back 'UTF-8' in connection.encoding by adding "encoding='UTF-8'" we get:
Traceback (most recent call last):
  File "C:/Users/SBT-Chernopyatov-AS/PycharmProjects/CUP_Fetcher/ptest_602.py", line 7, in <module>
    conn = cx_Oracle.connect("user/pass@//host:1521/dbname", encoding='UTF-8')
cx_Oracle.DatabaseError: DPI-1005: unable to acquire Oracle environment handle

So, seems there is no way to work with the unicode strings right now.

Consider providing standard python wheels instead of wininst executables

For windows installations there are now only .exe packages available in PyPi. Please consider providing standard .whl packages instead.

This allows to install cx_Oracle with standard pip install commands on windows, without the need to download them manually, convert them with wheel convert path_to_package.exe and then install it with pip install.

[6.0b1] OverflowError: Python int too large to convert to C long

I think that there is regression in cx_Oracle==6.0b1. Passing number with 19 9's i.e. 9999999999999999999 to the cursor fails with OverflowError: Python int too large to convert to C long (18 9's works). Please find below regression test that fails in cx_Oracle==6.0b1 and works in cx_Oracle==5.3:

import cx_Oracle
connection = cx_Oracle.connect("user", "password", "TNS")
cursor = connection.cursor()
cursor.execute("select :arg0 from dual", {':arg0': -9999999999999999999})
  • Python 3.4.3 (64-bit)

NotSupportedError contains a str, not a cx_Oracle._Error object

When I follow the docs' guidance on exception handling, a NotSupportedError contains a string, not the expected cx_Oracle._Error object. Below is a short script that reproduces the issue. I'm using a dict as an example variable, but any unsupported variable type will throw this error.

from __future__ import print_function
import cx_Oracle

connection = cx_Oracle.Connection("cx_Oracle/dev@localhost/orcl")
cursor = connection.cursor()

my_dict = {"foo": 1, "bar": 2}

try:
    stmt = cursor.prepare("SELECT dummy FROM dual WHERE dummy = :myvar")
    cursor.execute(stmt, {"myvar": my_dict})

except cx_Oracle.DatabaseError as exc:
    print(str(type(exc)))                      # <class 'cx_Oracle.NotSupportedError'>
    print(repr(exc))                           # NotSupportedError('Variable_TypeByValue(): unhandled data type dict',)
    error, = exc.args                          # "error" is a str, NOT a cx_Oracle._Error object
    print("Oracle-Error-Code:", error.code)    # AttributeError: 'str' object has no attribute 'code'
    print("Oracle-Error-Message:", error.message)

The documentation states:

With cx_Oracle every exception object has exactly one argument in the args tuple. This argument is a cx_Oracle._Error object...

Environment

  • Python: 2.7.13 |Anaconda 4.3.1 (64-bit)
  • cx_Oracle: 5.2.1
  • Oracle client version: InstantClient 12.2 via rpm
  • Oracle database version: 12.2
  • OS: CentOS release 6.9 (Final)

5.3 regression w/Django - introspecting a database causes TypeError because of precision=None on int fields

A regression was introduced in this commit that causes a TypeError inside Django by returning precision = None instead of precision = 0 previously.

Django Version: 1.10.6
Python Version: 3.5.2

Traceback:

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
  42.             response = get_response(request)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/contrib/admin/options.py" in wrapper
  544.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/contrib/admin/sites.py" in inner
  211.             return view(request, *args, **kwargs)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapper
  67.             return bound_func(*args, **kwargs)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/utils/decorators.py" in bound_func
  63.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/contrib/admin/options.py" in changelist_view
  1543.                 self.list_max_show_all, self.list_editable, self,

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/contrib/admin/views/main.py" in __init__
  79.         self.get_results(request)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/contrib/admin/views/main.py" in get_results
  176.             full_result_count = self.root_queryset.count()

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/db/models/query.py" in count
  369.         return self.query.get_count(using=self.db)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/db/models/sql/query.py" in get_count
  476.         number = obj.get_aggregation(using, ['__count'])['__count']

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/db/models/sql/query.py" in get_aggregation
  457.         result = compiler.execute_sql(SINGLE)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/db/models/sql/compiler.py" in execute_sql
  846.                 val = cursor.fetchone()

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/db/utils.py" in inner
  101.                 return func(*args, **kwargs)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/db/backends/oracle/base.py" in fetchone
  511.         return _rowfactory(row, self.cursor)

File "[REDACTED]/.venv/lib/python3.5/site-packages/django/db/backends/oracle/base.py" in _rowfactory
  580.             elif precision > 0:

Exception Type: TypeError at [REDACTED]
Exception Value: unorderable types: NoneType() > int()

This can be considered a Django bug, but this is also a breaking change on the cx_Oracle side that was not announced as one.

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 53: invalid configuration byte

Delete irrelevant parts of this template.

For general questions:

Describe exactly what you did and what you want to happen.
Use the questions at the bottom of this template as a guide.

Use Markdown syntax, particularly for code blocks: see https://help.github.com/articles/basic-writing-and-formatting-syntax/#quoting-code

For security issues:

See https://www.oracle.com/support/assurance/vulnerability-remediation/reporting-security-vulnerabilities.html for how to report security issues.

For installation issues:

Use a gist for screen output and logs: see https://gist.github.com/
Do not paste long output into this issue

Review the install instructions at
https://github.com/oracle/python-cx_Oracle#installation

Review your output and logs. Google any errors

Answer the following questions:

  1. What is your version of Python? Is it 32-bit or 64-bit?
    64

  2. What is your version of cx_Oracle?
    cx_Oracle-6.0b2-cp36-cp36m-win_amd64.whl

  3. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?

  4. What is your version of the Oracle Database?
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Producti

  5. What is your OS and version?
    windows 7

  6. What error(s) you are seeing?
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 53: invalid configuration byte

  7. Using Anaconda 4.3.0 (64bit), python 3.6.0, 64

cx_Oracle unaware DB server gone away

For general questions:

Connected to Primary Oracle RAC with Active DataGuard (secondary is Read-Only)

If Primary listener goes away cx_Oracle will attempt a query, but time out after 180 seconds. Can we reduce that?

In this case, a backhoe cut some fiber, but easily reproduced with: iptables -A OUTPUT -d xxx.xxx.xxx.xxx -j DROP

Ultimately we'd like to react more quickly if a server is dead. When we do detect a reconnect scenario, SQLAlchemy's timeout does not appear to affect cx_Oracle connections so we perform a simple TCP connect first. This is fine, but the larger issue is when a connection is established, but the DB server is gone.

Answer the following questions:

  1. What is your version of Python? Is it 32-bit or 64-bit?

64-bit 3.5.3 and 3.6.1

  1. What is your version of cx_Oracle?

cx-Oracle==5.2.1

  1. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?
> rpm -qa|grep instantclient12
oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64
oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64

RPM defaults: /usr/lib/oracle/12.1/client64/

  1. What is your OS and version?

cat /etc/system-release
Oracle Linux Server release 6.5

  1. What compiler version did you use? For example, with GCC, run
    gcc --version.
gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  1. What environment variables did you set? How exactly did you set them?
> cat .bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

if [ -d ~/.bashrc.d ]; then
    for i in ~/.bashrc.d/*.sh ; do
        if [ -r "$i" ]; then
            if [ "${-#*i}" != "$-" ]; then
                . "$i"
            else
                . "$i" >/dev/null 2>&1
            fi
        fi
    done
fi

> cat .bashrc.d/oracle-instantclient.sh 
#!/bin/bash

export ORACLE_HOME=/usr/lib/oracle/12.1/client64/
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib:$LD_LIBRARY_PATH
  1. What error(s) you are seeing?
  • Connection sits and waits.
  • After 180 seconds, we get the error we expect. Can we get it sooner?
2017-04-26 21:36:23,111 ERROR: (cx_Oracle.OperationalError) ORA-03135: connection lost contact\nProcess ID: 26655\nSession ID: 20 Serial number: 48108

This is actually wrapped in sqlalchemy.exc.OperationalError, caught similar to this (simplified):

        try:
                result = self.Session.read_session.query(self.model).filter(*_f).all()

        except (sqlalchemy.exc.OperationalError, sqlalchemy.exc.UnboundExecutionError, sqlalchemy.exc.InterfaceError, sqlalchemy.exc.DatabaseError, cx_Oracle.InterfaceError) as e:

                emit(e, code=500, source='%s modelsearch.ModelSearch.run()' % (sid), extra="DB Query Failure.  Reconnecting.")

                ... etc.

TimesTen: suggestion

Not an issue, since CX_ doesn't officially support TimesTen, but i figured it would be nice:
a. either include the support into the roadmap
b. note that TT can be used with the cx_.

cannot find dpi.h

Delete irrelevant parts of this template.

For general questions:

Trying to build and install cx_Oracle in mac OS X 10.11.6 El Capiton 64 bit version according to the instructions http://www.cs.utexas.edu/~mitra/csSpring2012/cs327/cx_mac.html

Getting "src/cx_Oracle.c:21:10: fatal error: 'dpi.h' file not found"

when executing "$python setup.py build".

This is the last include statement in the file "cx_Oracle.c" in the "src" directory.

  1. Have tried with Anaconda python 3
  2. Then thought that it might be issue with python3 and tried with Anaconda python 2.
  3. Still did not work. So tried with the version python 2.7.10 available through OS X

Unable to acquire Oracle environment handle

I followed the instructions here.

I downloaded the instantclient and unzipped in $HOME/Resources/oracle/

After the installation I ran sqlplus hr/welcome@localhost/orcl and was able to connect using credentials for my database.

I then installed cx_Oracle with pip. However, when I try to connect:

import cx_Oracle
conn = cx_Oracle.connect('hr/welcome@localhost/orcl')

I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

I have looked online for a solution and have tried this:
setting os env.

import os
import cx_Oracle

os.environ['DYLD_LIBRARY_PATH'] = '/Users/gonzalezma/Resources/oracle/instantclient_11_2'

conn = cx_Oracle.connect('hr/welcome@localhost/orcl')

Still does not work. I have looked online, but have yet to find a solution.

Answer the following questions:

  1. What is your version of Python? Is it 32-bit or 64-bit?
  • Python 3.5.2 64-bit
  1. What is your version of cx_Oracle?
  • cx-Oracle==5.3
  1. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?
  1. What is your OS and version?
  • MacOSX 10.11.6
  1. What compiler version did you use? For example, with GCC, run
    gcc --version.
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  1. What environment variables did you set? How exactly did you set them?
export ORACLE_HOME="$HOME/Resources/oracle/instantclient_11_2"
export DYLD_LIBRARY_PATH="$ORACLE_HOME:$DYLD_LIBRARY_PATH"
export PATH=$PATH:/Users/gonzalezma/Resources/oracle/instantclient_11_2
  1. What exact command caused the problem (e.g. what command did you try to
    install with)? Who were you logged in as?
  • I was able to successfully install with pip. This is the command that gave me the error.
import cx_Oracle

conn_str = user + '/' + pw + '@' + host + ':' + port + '/' + service
conn = cx_Oracle.connect(conn_str)
  1. What error(s) you are seeing?
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

max open cursors for Stored Procedure that returns nested SYS-REFCURSORs

I am calling a stored procedure via cursor.callproc in an Oracle 12.1.0.2 database that returns a sys_refcursor. There are 16 scalar data elements and two child sys_refcursors within the parent cursor.

My Python program simply attempts to iterate the cursors. For each parent cursor row/iteration, I explicitly create the child cursors, iterate them and close them. I am running into "ORA-01000: maximum open cursors exceeded" when the program attempts to iterate the 101st parent row.

open_cursors is set to 300 in my database. When I monitor v$session, v$open_cursor, etc., I can see that for each parent row/iteration, there is 1 open cursor for the parent and 100 cursors open for each child cursor.

It would seem that cursor.close() is not actually closing the child cursor. I can call the same stored procedure with PL/SQL and iterate the result set without issue. I would prefer to keep the nested cursors. Is there a method to close them as I iterate that actually closes them on the server side?

Environment:
Oracle 12.1.0.2 on RHEL 7
Python 3.5.2 64-bit
cx_Oracle 5.3-12c 64-bit
Windows 7 Enterprise SP1 64-bit client
Oracle 12.1.0.2 Instant Client 64-bit

Example code:

import cx_Oracle

conn = cx_Oracle.connect('user/password@host:port/service')

curs_main = conn.cursor()

p1 = 2016

l_cur_main = curs_main.var(cx_Oracle.CURSOR)

try:
    curs_main.callproc('My_Package_Pub.get_my_data', [p1, l_cur_main])
except cx_Oracle.DatabaseError as exc:
    error, = exc.args
    print("Oracle Error Code:", error.code)
    print("Oracle Error Message:", error.message)
    exit (1)

for mc in l_cur_main.getvalue():
    print(mc[0],mc[1],mc[2],mc[3],mc[4],mc[5],mc[6],mc[7],mc[8],mc[9],mc[10],mc[11],mc[12],mc[13],mc[14],mc[15])
    
    curs_ro = conn.cursor()
    l_cur_ro = curs_ro.var(cx_Oracle.CURSOR)
    l_cur_ro = mc[16]
    for ro in l_cur_ro:
        print('\t',ro[0])
    curs_ro.close()

    curs_rq = conn.cursor()
    l_cur_rq = curs_rq.var(cx_Oracle.CURSOR)
    l_cur_rq = mc[17]
    for rq in l_cur_rq:
        print('\t\t',rq[0])
    curs_rq.close()

curs_main.close()
conn.close()

Error Installing cx_Oracle

OS: Windows 7 64-bit
cx_Oracle Version: 5.3
Oracle Database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
Oracle Instant Client: 12.2.0.1.0

Processing h:\work\code\serapis\dist\serapis-0.0.1.dev1-py2.py3-none-any.whl
Requirement already satisfied: pandas in c:\programdata\anaconda3\lib\site-packages (from serapis==0.0.1.dev1)
Collecting cx-Oracle (from serapis==0.0.1.dev1)
Using cached cx_Oracle-5.3.tar.gz
Requirement already satisfied: numpy in c:\programdata\anaconda3\lib\site-packages (from serapis==0.0.1.dev1)
Requirement already satisfied: python-dateutil>=2 in c:\programdata\anaconda3\lib\site-packages (from pandas->serapis==0.0.1.dev1)
Requirement already satisfied: pytz>=2011k in c:\programdata\anaconda3\lib\site-packages (from pandas->serapis==0.0.1.dev1)
Requirement already satisfied: six>=1.5 in c:\programdata\anaconda3\lib\site-packages (from python-dateutil>=2->pandas->serapis==0.0.1.dev1)
Building wheels for collected packages: cx-Oracle
Running setup.py bdist_wheel for cx-Oracle: started
Running setup.py bdist_wheel for cx-Oracle: finished with status 'error'
Complete output from command C:\ProgramData\Anaconda3\python.exe -u -c "import setuptools, tokenize;file='C:\Users\elmasm\AppData\Local\Temp\pip-build-xsy0ez73\cx-Oracle\setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d C:\Users\elmasm\AppData\Local\Temp\tmppmpw2e99pip-wheel- --python-tag cp36:
running bdist_wheel
running build
running build_ext
building 'cx_Oracle' extension
creating build
creating build\temp.win-amd64-3.6-11g
creating build\temp.win-amd64-3.6-11g\Release
creating build\temp.win-amd64-3.6-11g\Release\src
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\oracle\ora11g_r2\oci\include -IC:\oracle\ora11g_r2\rdbms\demo -IC:\ProgramData\Anaconda3\include -IC:\ProgramData\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\winrt" -IC:\Sybase\OCS-15_0\include /Tcsrc/cx_Oracle.c /Fobuild\temp.win-amd64-3.6-11g\Release\src/cx_Oracle.obj -DBUILD_VERSION=5.3
cx_Oracle.c
c:\users\elmasm\appdata\local\temp\pip-build-xsy0ez73\cx-oracle\src\Connection.c(685): warning C4244: 'function': conversion from 'Py_ssize_t' to 'ub4', possible loss of data
c:\users\elmasm\appdata\local\temp\pip-build-xsy0ez73\cx-oracle\src\Connection.c(697): warning C4244: 'function': conversion from 'Py_ssize_t' to 'ub4', possible loss of data
c:\users\elmasm\appdata\local\temp\pip-build-xsy0ez73\cx-oracle\src\Connection.c(709): warning C4244: 'function': conversion from 'Py_ssize_t' to 'ub4', possible loss of data
creating C:\Users\elmasm\AppData\Local\Temp\pip-build-xsy0ez73\cx-Oracle\build\lib.win-amd64-3.6-11g
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\oracle\ora11g_r2\bin /LIBPATH:C:\oracle\ora11g_r2 /LIBPATH:C:\oracle\ora11g_r2\oci\lib\msvc /LIBPATH:C:\oracle\ora11g_r2\sdk\lib\msvc /LIBPATH:C:\ProgramData\Anaconda3\libs /LIBPATH:C:\ProgramData\Anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.15063.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.15063.0\um\x64" /LIBPATH:C:\Sybase\DataAccess64\ADONET\dll /LIBPATH:C:\Sybase\DataAccess\ADONET\dll /LIBPATH:C:\Sybase\OCS-15_0\lib oci.lib /EXPORT:PyInit_cx_Oracle build\temp.win-amd64-3.6-11g\Release\src/cx_Oracle.obj /OUT:build\lib.win-amd64-3.6-11g\cx_Oracle.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6-11g\Release\src\cx_Oracle.cp36-win_amd64.lib
cx_Oracle.obj : warning LNK4197: export 'PyInit_cx_Oracle' specified multiple times; using first specification
Creating library build\temp.win-amd64-3.6-11g\Release\src\cx_Oracle.cp36-win_amd64.lib and object build\temp.win-amd64-3.6-11g\Release\src\cx_Oracle.cp36-win_amd64.exp
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobGetChunkSize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtExecute
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFileClose
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectPin
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIEnvNlsCreate
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIRawSize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITransCommit
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITableNext
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIErrorGet
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDescribeAny
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobTrim
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIPing
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDescriptorFree
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFreeTemporary
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISubscriptionRegister
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectNew
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINumberToText
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINlsCharSetNameToId
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISessionPoolCreate
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIRawAssignBytes
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISessionEnd
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITransRollback
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobGetLength2
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIIterNext
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIHandleFree
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectGetAttr
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDateTimeConstruct
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFileGetName
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectSetAttr
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISessionRelease
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITransStart
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITableLast
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIBindByPos
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIServerAttach
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectFree
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFileSetName
cx_Oracle.obj : error LNK2001: unresolved external symbol OCICollAssignElem
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDBShutdown
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectCopy
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIAQDeq
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIBindByName
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISessionGet
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIAttrGet
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIRawResize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDescriptorAlloc
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITablePrev
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobIsOpen
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobRead2
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobWrite2
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINumberToInt
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDateTimeGetDate
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINumberFromText
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIEnvCreate
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtGetBindInfo
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtPrepare
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISubscriptionUnRegister
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtPrepare2
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFileOpen
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIBindObject
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISessionBegin
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITableExists
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobClose
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIHandleAlloc
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDefineByPos
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINlsNameMap
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobOpen
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIServerDetach
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDBStartup
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINumberFromInt
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStringPtr
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIParamGet
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDefineObject
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectUnpin
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobIsTemporary
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIIntervalGetDaySecond
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIClientVersion
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINumberFromReal
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINlsNumericInfoGet
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIAQEnq
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINlsCharSetIdToName
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIPasswordChange
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIIterCreate
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtFetch2
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITransPrepare
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIIntervalSetDaySecond
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIAttrSet
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITableDelete
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISessionPoolDestroy
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStringResize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINumberToReal
cx_Oracle.obj : error LNK2001: unresolved external symbol OCICollGetElem
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtRelease
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobCreateTemporary
cx_Oracle.obj : error LNK2001: unresolved external symbol OCICollSize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDateTimeGetTime
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITableFirst
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFileExists
cx_Oracle.obj : error LNK2001: unresolved external symbol OCICollTrim
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDateTimeCheck
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStringAssignText
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIBreak
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStringSize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectGetInd
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIRawPtr
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobTrim2
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIIterDelete
cx_Oracle.obj : error LNK2001: unresolved external symbol OCICollAppend
build\lib.win-amd64-3.6-11g\cx_Oracle.cp36-win_amd64.pyd : fatal error LNK1120: 107 unresolved externals
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe' failed with exit status 1120


Running setup.py clean for cx-Oracle
Failed to build cx-Oracle
Installing collected packages: cx-Oracle, serapis
Running setup.py install for cx-Oracle: started
Running setup.py install for cx-Oracle: finished with status 'error'
Complete output from command C:\ProgramData\Anaconda3\python.exe -u -c "import setuptools, tokenize;file='C:\Users\elmasm\AppData\Local\Temp\pip-build-xsy0ez73\cx-Oracle\setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record C:\Users\elmasm\AppData\Local\Temp\pip-x3sctwha-record\install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_ext
building 'cx_Oracle' extension
creating build
creating build\temp.win-amd64-3.6-11g
creating build\temp.win-amd64-3.6-11g\Release
creating build\temp.win-amd64-3.6-11g\Release\src
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\oracle\ora11g_r2\oci\include -IC:\oracle\ora11g_r2\rdbms\demo -IC:\ProgramData\Anaconda3\include -IC:\ProgramData\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.15063.0\winrt" -IC:\Sybase\OCS-15_0\include /Tcsrc/cx_Oracle.c /Fobuild\temp.win-amd64-3.6-11g\Release\src/cx_Oracle.obj -DBUILD_VERSION=5.3
cx_Oracle.c
c:\users\elmasm\appdata\local\temp\pip-build-xsy0ez73\cx-oracle\src\Connection.c(685): warning C4244: 'function': conversion from 'Py_ssize_t' to 'ub4', possible loss of data
c:\users\elmasm\appdata\local\temp\pip-build-xsy0ez73\cx-oracle\src\Connection.c(697): warning C4244: 'function': conversion from 'Py_ssize_t' to 'ub4', possible loss of data
c:\users\elmasm\appdata\local\temp\pip-build-xsy0ez73\cx-oracle\src\Connection.c(709): warning C4244: 'function': conversion from 'Py_ssize_t' to 'ub4', possible loss of data
creating C:\Users\elmasm\AppData\Local\Temp\pip-build-xsy0ez73\cx-Oracle\build\lib.win-amd64-3.6-11g
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\oracle\ora11g_r2\bin /LIBPATH:C:\oracle\ora11g_r2 /LIBPATH:C:\oracle\ora11g_r2\oci\lib\msvc /LIBPATH:C:\oracle\ora11g_r2\sdk\lib\msvc /LIBPATH:C:\ProgramData\Anaconda3\libs /LIBPATH:C:\ProgramData\Anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.15063.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.15063.0\um\x64" /LIBPATH:C:\Sybase\DataAccess64\ADONET\dll /LIBPATH:C:\Sybase\DataAccess\ADONET\dll /LIBPATH:C:\Sybase\OCS-15_0\lib oci.lib /EXPORT:PyInit_cx_Oracle build\temp.win-amd64-3.6-11g\Release\src/cx_Oracle.obj /OUT:build\lib.win-amd64-3.6-11g\cx_Oracle.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6-11g\Release\src\cx_Oracle.cp36-win_amd64.lib
cx_Oracle.obj : warning LNK4197: export 'PyInit_cx_Oracle' specified multiple times; using first specification
Creating library build\temp.win-amd64-3.6-11g\Release\src\cx_Oracle.cp36-win_amd64.lib and object build\temp.win-amd64-3.6-11g\Release\src\cx_Oracle.cp36-win_amd64.exp
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobGetChunkSize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtExecute
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFileClose
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectPin
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIEnvNlsCreate
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIRawSize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITransCommit
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITableNext
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIErrorGet
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDescribeAny
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobTrim
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIPing
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDescriptorFree
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFreeTemporary
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISubscriptionRegister
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectNew
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINumberToText
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINlsCharSetNameToId
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISessionPoolCreate
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIRawAssignBytes
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISessionEnd
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITransRollback
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobGetLength2
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIIterNext
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIHandleFree
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectGetAttr
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDateTimeConstruct
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFileGetName
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectSetAttr
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISessionRelease
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITransStart
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITableLast
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIBindByPos
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIServerAttach
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectFree
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFileSetName
cx_Oracle.obj : error LNK2001: unresolved external symbol OCICollAssignElem
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDBShutdown
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectCopy
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIAQDeq
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIBindByName
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISessionGet
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIAttrGet
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIRawResize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDescriptorAlloc
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITablePrev
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobIsOpen
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobRead2
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobWrite2
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINumberToInt
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDateTimeGetDate
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINumberFromText
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIEnvCreate
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtGetBindInfo
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtPrepare
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISubscriptionUnRegister
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtPrepare2
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFileOpen
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIBindObject
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISessionBegin
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITableExists
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobClose
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIHandleAlloc
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDefineByPos
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINlsNameMap
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobOpen
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIServerDetach
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDBStartup
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINumberFromInt
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStringPtr
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIParamGet
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDefineObject
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectUnpin
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobIsTemporary
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIIntervalGetDaySecond
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIClientVersion
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINumberFromReal
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINlsNumericInfoGet
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIAQEnq
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINlsCharSetIdToName
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIPasswordChange
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIIterCreate
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtFetch2
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITransPrepare
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIIntervalSetDaySecond
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIAttrSet
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITableDelete
cx_Oracle.obj : error LNK2001: unresolved external symbol OCISessionPoolDestroy
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStringResize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCINumberToReal
cx_Oracle.obj : error LNK2001: unresolved external symbol OCICollGetElem
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStmtRelease
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobCreateTemporary
cx_Oracle.obj : error LNK2001: unresolved external symbol OCICollSize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDateTimeGetTime
cx_Oracle.obj : error LNK2001: unresolved external symbol OCITableFirst
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobFileExists
cx_Oracle.obj : error LNK2001: unresolved external symbol OCICollTrim
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIDateTimeCheck
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStringAssignText
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIBreak
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIStringSize
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIObjectGetInd
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIRawPtr
cx_Oracle.obj : error LNK2001: unresolved external symbol OCILobTrim2
cx_Oracle.obj : error LNK2001: unresolved external symbol OCIIterDelete
cx_Oracle.obj : error LNK2001: unresolved external symbol OCICollAppend
build\lib.win-amd64-3.6-11g\cx_Oracle.cp36-win_amd64.pyd : fatal error LNK1120: 107 unresolved externals
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe' failed with exit status 1120

----------------------------------------

ImportError: DLL load failed: %1 is not a valid Win32 application

Hello,

I have

  • Python 3.6.1 64 bit,
  • Oracle client 12.2 x64 (instantclient-sdk-windows.x64-12.2.0.1.0.zip (1,801,992 bytes) (cksum - 3191784704) and instantclient-basic-windows.x64-12.2.0.1.0.zip (75,062,441 bytes) (cksum - 1462971172) wrote path in Windows OS Environment ORACLE_HOME = C:\DataBases\Oracle\instantclient),
  • OS windows 2012 x64,
  • compiler MS C/C++ 19.10.25017 x64
    MS Visual C++ 2015

Tried to execute this code

#!/usr/bin/python
import cx_Oracle
ip='192.168.0.2'
port = 1521
SID = 'dboracle'
USERNAME='dboracle'
PASSWORD='pwd'
sql_script="""
SELECT sysdate from dual
"""
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
print (dsn_tns)
conn = cx_Oracle.connect(USERNAME, PASSWORD, dsn_tns)
c = conn.cursor()
c.execute(sql_script)
for row in c:
    print (row[0], row[1])
conn.close()

end got error

C:\Python36\python.exe C:/templates/DB/Oracle/Jobs.py
Traceback (most recent call last):
  File "C:/templates/DB/Oracle/Jobs.py", line 2, in <module>
    import cx_Oracle
ImportError: DLL load failed: %1 is not a valid Win32 application.

How to solve this problem?

question about cx_Oracle 6.0b1

I found that cx_Oracle version 6.0b1 solves a problem I have with versions 5.2.1. and 5.3 (i.e. getting ORA 01461 when inserting String or Unicode longer than 4000 Byte into a CLOB-field). My Question is, if I could use Version 6.0 Beta for production use or better wait for a later version? Can you please give a advice?

Python 3 compatibility of tests

Currently the tests are not Python 3 compatible. This following patch should fix those:

diff --git a/test/test_dbapi20.py b/test/test_dbapi20.py
index e37e595..e6b4edf 100644
--- a/test/test_dbapi20.py
+++ b/test/test_dbapi20.py
@@ -10,6 +10,8 @@
 """Driver specific portion of the DB API test suite provided by Stuart Bishop
    available at http://stuartbishop.net/Software/DBAPI20TestSuite/"""
 
+from __future__ import print_function
+
 import cx_Oracle
 import dbapi20
 import unittest
@@ -43,6 +45,6 @@ class TestSuite(dbapi20.DatabaseAPI20Test):
 
 
 if __name__ == "__main__":
-    print "Testing cx_Oracle version", cx_Oracle.version
+    print("Testing cx_Oracle version", cx_Oracle.version)
     unittest.main()
 
diff --git a/test/uFeatures12_1.py b/test/uFeatures12_1.py
index ae45a1e..3d92e04 100644
--- a/test/uFeatures12_1.py
+++ b/test/uFeatures12_1.py
@@ -39,7 +39,7 @@ class TestArrayDMLBatchError(BaseTestCase):
         self.cursor.executemany(sql, rows, arraydmlrowcounts = True)
         self.connection.commit()
         self.assertEqual(self.cursor.getarraydmlrowcounts(),
-                [1L, 1L, 1L, 1L, 1L])
+                [1, 1, 1, 1, 1])
         self.cursor.execute(u"select count(*) from TestArrayDML")
         count, = self.cursor.fetchone()
         self.assertEqual(count, len(rows))
@@ -54,7 +54,7 @@ class TestArrayDMLBatchError(BaseTestCase):
         sql = u"insert into TestArrayDML (IntCol,StringCol) values (:1,:2)"
         self.assertRaises(cx_Oracle.DatabaseError, self.cursor.executemany,
                 sql, rows, arraydmlrowcounts = True)
-        self.assertEqual(self.cursor.getarraydmlrowcounts(), [1L, 1L])
+        self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1])
 
     def testExecutingDelete(self):
         "test executing delete statement with arraydmlrowcount mode"
@@ -73,7 +73,7 @@ class TestArrayDMLBatchError(BaseTestCase):
         rows = [ (200,), (300,), (400,) ]
         statement = u"delete from TestArrayDML where IntCol2 = :1"
         self.cursor.executemany(statement, rows, arraydmlrowcounts = True)
-        self.assertEqual(self.cursor.getarraydmlrowcounts(), [1L, 3L, 2L])
+        self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 3, 2])
 
     def testExecutingUpdate(self):
         "test executing update statement with arraydmlrowcount mode"
@@ -96,7 +96,7 @@ class TestArrayDMLBatchError(BaseTestCase):
         sql = u"update TestArrayDML set StringCol = :1 where IntCol2 = :2"
         self.cursor.executemany(sql, rows, arraydmlrowcounts = True)
         self.assertEqual(self.cursor.getarraydmlrowcounts(),
-                [1L, 1L, 3L, 2L])
+                [1, 1, 3, 2])
 
     def testInsertWithBatchError(self):
         "test executing insert with multiple distinct batch errors"
@@ -120,7 +120,7 @@ class TestArrayDMLBatchError(BaseTestCase):
                 for e in self.cursor.getbatcherrors()]
         self.assertEqual(actualErrors, expectedErrors)
         self.assertEqual(self.cursor.getarraydmlrowcounts(),
-                [1L, 1L, 0L, 1L, 0L])
+                [1, 1, 0, 1, 0])
 
     def testBatchErrorFalse(self):
         "test batcherrors mode set to False"
@@ -170,6 +170,6 @@ class TestArrayDMLBatchError(BaseTestCase):
                 for e in self.cursor.getbatcherrors()]
         self.assertEqual(actualErrors, expectedErrors)
         self.assertEqual(self.cursor.getarraydmlrowcounts(),
-                [1L, 2L, 0L, 0L, 1L])
+                [1, 2, 0, 0, 1])
         self.assertEqual(self.cursor.rowcount, 4)
 
diff --git a/test/uNumberVar.py b/test/uNumberVar.py
index 1487758..f13ea9b 100644
--- a/test/uNumberVar.py
+++ b/test/uNumberVar.py
@@ -23,7 +23,7 @@ class TestNumberVar(BaseTestCase):
           floatCol = i + i * 0.75
           unconstrainedCol = i ** 3 + i * 0.5
           if i % 2:
-              nullableCol = 143L ** i
+              nullableCol = 143 ** i
           else:
               nullableCol = None
           dataTuple = (i, numberCol, floatCol, unconstrainedCol, nullableCol)
@@ -62,7 +62,7 @@ class TestNumberVar(BaseTestCase):
         self.cursor.execute(u"""
                 select * from TestNumbers
                 where IntCol = :value""",
-                value = 3L)
+                value = 3)
         self.assertEqual(self.cursor.fetchall(), [self.dataByKey[3]])
 
     def testBindLargeLong(self):

Document testing requirements

Running the test suite via python setup.py test appears to require a pre-existing database to work with.
Is there a subset of the tests that don't have that requirement, i.e. that either create and use a temporary database, or that perform some other simple checks just to verify that the build succeeded ?

I couldn't find any test instruction in https://github.com/oracle/python-cx_Oracle/blob/master/README.md or elsewhere.

Thanks,
Stefan

Add support to XML type

Hi,

The XML type is not supported on cx_Oracle. When I run a code like below, I get the error: AttributeError: 'cx_Oracle.OBJECT' object has no attribute 'read'

result = cursor.execute(
  """SELECT XMLElement("Date", hire_date)
  FROM hr.employees
  WHERE employee_id = 203"""
 )

for res in result:
	# The exception occours right here
	raw_xml = res[0].read()

But there are simple workaround. Just use the function GETCLOBVAL:

result = cursor.execute(
  """SELECT XMLElement("Date", hire_date).GETCLOBVAL()
  FROM hr.employees
  WHERE employee_id = 203"""
 )

for res in result:
	import xml.etree.ElementTree as ET
	xml_string = res[0].read()
	tree = ET.fromstring(xml_string)

The workaround works. But I think that would more pythonic if the cx_Oracle do this automatically:

result = cursor.execute(
  """SELECT XMLElement("Date", hire_date)
  FROM hr.employees
  WHERE employee_id = 203"""
 )

for res in result:
	xml = res[0].read()
	type(xml) # <class 'xml.etree.ElementTree.Element'>

cx_Oracle.DatabaseError: ORA-12560: TNS:protocol adapter error in Python

Recently there was change in the Database connection as they changed the connection type over SSL.

The connection protocol has been changed from TCP to TCPS and the port no has been updated as well.

have made the required changes in TNSNAMES.ora file my local machine.

TNS_LSNR =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCPS)(HOST = hostname)(PORT = port)
)
(CONNECT_DATA =
(SERVICE_NAME= SRVC_NAME)
)

After the change i can connect to database from SQLPLUS command line and Developer app without any issues.

But my cx_Oracle module has issues connecting to the database, did check in many forums and blogs and stack overflow, but there is no answer for the same.

Hoping that the issue can be sorted here.

Connection logs:

$ sqlplus username/password@TNS_LSNR
SQL*Plus: Release 12.1.0.2.0 Production on Tue Mar 28 16:07:13 2017
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
Last Successful login time: Tue Mar 28 2017 15:45:01 +05:30
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Advanced Analytics, Real Application Testing and Unified Auditing options
 
SQL>
 
>>> cx_Oracle.connect('username','password','TNS_LSNR')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cx_Oracle.DatabaseError: ORA-12560: TNS:protocol adapter error

System information:

Oracle 12c
Protocol: TCPS
Instant client Version: 12_1
Local system type: MAC
cx_Oracle Version : 5.3

Version 6 fails to find OCI libs where version 5 succeeded

We are preparing to replace cx_Oracle 5 with version 6 in our application. Updating the requirements lead to our tests to fail.

The reason is quite obvious but I think cx_Oracle 5 was more robust: On our build slave the instantclient packages are installed but nothing else of the Oracle database. This always worked fine:

(venv) (python27)[jenkins@build-rhel6-v2 ~]$ pip install cx_Oracle==5.3
Collecting cx_Oracle==5.3
[...]
Successfully installed cx-Oracle-5.3
(venv) (python27)[jenkins@build-rhel6-v2 ~]$ python -c "import cx_Oracle; print cx_Oracle.version"
5.3

After upgrading to 6.0b1 we get this:

(venv) (python27)[jenkins@build-rhel6-v2 ~]$ pip install cx_Oracle==6.0b1
Collecting cx_Oracle==6.0b1
Installing collected packages: cx-Oracle
  Found existing installation: cx-Oracle 5.3
    Uninstalling cx-Oracle-5.3:
      Successfully uninstalled cx-Oracle-5.3
Successfully installed cx-Oracle-6.0b1
(venv) (python27)[jenkins@build-rhel6-v2 ~]$ python -c "import cx_Oracle; print cx_Oracle.version"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
cx_Oracle.DatabaseError: DPI-1047: Oracle Client library cannot be loaded: libclntsh.so: cannot open shared object file: No such file or directory. See https://oracle.github.io/odpi/doc/installation.html for help

The version of instant client installed is a bit old:

(venv) (python27)[jenkins@build-rhel6-v2 ~]$ rpm -qa|grep instant
oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64
oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64
(venv) (python27)[jenkins@build-rhel6-v2 ~]$ rpm -ql oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64|grep libclnt
/usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1

The obvious way to fix this is to extend LD_LIBRARY_PATH:

$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/11.2/client64/lib python -c "import cx_Oracle; print cx_Oracle.version"
6.0b1

For easing the upgrade to users of cx_Oracle it would make sense though to keep the behaviour to guess the instant client installations like setup.py did for cx_Oracle 5.3.

Feel free to close this if you disagree.

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 100: invalid continuation byte

Hello,

I have Python 3.6.1 64 bit,
Oracle client 12.2 x64,
OS windows 10 x64,
compiler MS C/C++ 19.10.25017 x64

Tried install

pip install cx_Oracle

end got error

Collecting cx_Oracle
  Using cached cx_Oracle-5.3.tar.gz
Installing collected packages: cx-Oracle
  Running setup.py install for cx-Oracle ... error
Exception:
Traceback (most recent call last):
  File "c:\python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
    return s.decode(sys.__stdout__.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 100: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\python36\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:\python36\lib\site-packages\pip\commands\install.py", line 342, in run
    prefix=options.prefix_path,
  File "c:\python36\lib\site-packages\pip\req\req_set.py", line 784, in install
    **kwargs
  File "c:\python36\lib\site-packages\pip\req\req_install.py", line 878, in install
    spinner=spinner,
  File "c:\python36\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "c:\python36\lib\site-packages\pip\compat\__init__.py", line 75, in console_to_str
    return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 100: invalid continuation byte

How to solve this problem?

prefer .whl to .exe for windows

It seems more friendly to use wheel files for windows.
.whl will not affect Windows Control Panel. When there are multiple python envs in one system, .exe will have multiple entries in the Uninstall Panel.

UnicodeDecodeError appears when importing module

  1. What is your version of Python? Is it 32-bit or 64-bit?
    3.6.1, 64-bit, package from Python.org, installed system-wide (for all users)

  2. What is your version of cx_Oracle?
    cx_Oracle-6.0rc1-cp36-cp36m-win_amd64.whl

  3. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?
    instantclient-basic-windows.x64-12.2.0.1.0, extracted to location - C:\Oracle\instantclient_12_2

  4. What is your OS and version?
    Windows 10.0.14393

  5. What environment variables did you set? How exactly did you set them?
    Instant client location was added to PATH and set as ORACLE_HOME

  6. What exact command caused the problem (e.g. what command did you try to
    install with)? Who were you logged in as?
    import cx_Oracle

  7. What error(s) you are seeing?

	File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcd in position 50: invalid continuation byte

ORA-24816 with cx_Oracle 6.0rc1

When using cx_Oracle 6.0rc1, I encounter the ORA-24816 DatabaseError on specific queries:

ORA-24816: Expanded non LONG bind data supplied after actual LONG or LOB column

The query does not seem special and the error is only triggered inside Django (not when it is run from the command line, even if the code is the same) so I think this may be related to previous queries, the context or configuration settings.

I have the same error when using Oracle Client 11.2, 12.1 or 12.2.
I have the same error when using current master (3243261)
I don't have the error when using cx_Oracle 5.3.

The error description is somewhat cryptic for me, so I don't know how to continue the analysis.

Is there a reason it is now raised by cx_Oracle 6.0rc1? What information can be retrieved to diagnose this issue?

While fetch data like '€' from table, it will raise a UnicodeDecodeError exception.

For general questions:

While fetch data like '€' from table, it will raise a UnicodeDecodeError exception.

Answer the following questions:

  1. What is your version of Python? Is it 32-bit or 64-bit?
    64-bit

  2. What is your version of cx_Oracle?
    cx_Oracle-5.2.1-12c.win-amd64-py3.5

  3. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?
    Python 3.5

  4. What is your OS and version?
    Windows 10 64bit enterprise.

  5. What compiler version did you use? For example, with GCC, run
    gcc --version.
    python 3.5

  6. What environment variables did you set? How exactly did you set them?
    Through the shell command.

  7. What exact command caused the problem (e.g. what command did you try to
    install with)? Who were you logged in as?
    I write a program and try to fetch data from my DB. It will raise a UnicodeDecodeError exception while fetch data like '€' from table.
    My db CHARSET = ALU32UTF8.
    My python code is listed below:
    strSample = cur.fetchone()

  8. What error(s) you are seeing?
    It will raise a UnicodeDecodeError exception.

[6.0b1] Decimal parameter edge case.

I think that there is regression in cx_Oracle==6.0b1. Passing Decimal('0.000') as a parameter to the cursor doesn't return correct result, moreover passing Decimal('0'), '0', '0.000' works. Please find below regression test that fails in cx_Oracle==6.0b1 and works in cx_Oracle==5.3:

import cx_Oracle
connection = cx_Oracle.connect("user", "password", "TNS")
cursor = connection.cursor()
cursor.execute('CREATE TABLE "TEST"("DATA" NUMBER(5,3) PRIMARY KEY)')
cursor.execute('INSERT INTO "TEST"("DATA") VALUES (0)')
cursor.execute(
    'SELECT 1 FROM "TEST" WHERE "TEST"."DATA" = :arg0',
    {':arg0': Decimal('0.000')},
)
row = cursor.fetchone()
assert row is not None
assert row[0] == 1
  • Python 3.4.3 (64-bit)

Broken date value handling

Dear Anthony
I have some old DB, which contains broken DATE values, with invalid format.
It looks like this:

Query:

SELECT
    r.request_id,
    usr_actual_start_date date_date,
    TO_CHAR(
        w.usr_actual_start_date,
        'DD.MM.YYYY HH24:MI:SS'
    ) char_date,
    dump(usr_actual_start_date) dump_date
FROM
    requests r

Oracle SQL Developer with JDBC driver:

sqlplus from the latest instant client:

As you can see, for request_id=46541 it returns different values for date, but they are near.

But if I try to get this data through cx_Oracle it throws "ValueError: hour must be between 0..23".

Don't you think that it'll be more user-firendly or more expected to get behaviour like SQL Developer or sqlplus?

Thank you!

Regards,
Andrey

Crash when using bool values as query parameters with cx_Oracle 6.0rc1 and Oracle Client 11.2

Initial note: I'm unsure if this is a valid usage but this was working with cx_Oracle 5.3 and (very) old versions of Django seems to trigger that bug.

The crash is triggered by providing a boolean value as a query parameter with Oracle Client 11.2.

$ gdb python
[...]
(gdb) run
Starting program: /usr/bin/python 
[...]
>>> import cx_Oracle
>>> cx_Oracle.version
'6.0rc1'
>>> cx_Oracle.clientversion()
(11, 2, 0, 4, 0)
>>> connection = cx_Oracle.Connection('...')
>>> connection.cursor().execute('SELECT * FROM TABLENAME WHERE TABLENAME.ARG = :arg0', [True])

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff3e115d2 in kpubsuuc () from /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1
(gdb) bt
#0  0x00007ffff3e115d2 in kpubsuuc () from /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1
#1  0x00007ffff3e114a7 in kpubndp () from /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1
#2  0x00007ffff3e10b54 in kpubndp0 () from /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1
#3  0x00007ffff3dede87 in OCIBindByPos () from /usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1
#4  0x00007ffff633a4ba in dpiOci__bindByPos (stmt=0xaa1720, bindHandle=0x7fffffffd6c0, pos=1, 
    dynamicBind=<optimized out>, var=<optimized out>, error=0x7fffffffd720) at odpi/src/dpiOci.c:683
#5  0x00007ffff6354d8e in dpiStmt__bind (stmt=stmt@entry=0xaa1720, var=var@entry=0xaa17e0, 
    addReference=addReference@entry=1, pos=pos@entry=1, name=name@entry=0x0, nameLength=nameLength@entry=0, 
    error=0x7fffffffd720) at odpi/src/dpiStmt.c:149
#6  0x00007ffff63551c7 in dpiStmt_bindByPos (stmt=0xaa1720, pos=pos@entry=1, var=0xaa17e0) at odpi/src/dpiStmt.c:1036
#7  0x00007ffff6355391 in Variable_Bind (var=<optimized out>, cursor=0x7ffff7e92cb0, cursor=0x7ffff7e92cb0, pos=1, 
    name=0x0) at src/Variable.c:677
#8  Cursor_PerformBind (self=0x7ffff7e92cb0) at src/Cursor.c:866
#9  0x00007ffff635a63a in Cursor_Execute (self=0x7ffff7e92cb0, args=<optimized out>, keywordArgs=<optimized out>)
    at src/Cursor.c:1415
#10 0x00000000004c468a in PyEval_EvalFrameEx ()
#11 0x00000000004c2765 in PyEval_EvalCodeEx ()
#12 0x00000000004c2509 in PyEval_EvalCode ()
#13 0x00000000004f1def in ?? ()
#14 0x000000000044c6ed in PyRun_InteractiveOneFlags ()
#15 0x000000000044c4b2 in PyRun_InteractiveLoopFlags ()
#16 0x000000000042e88a in ?? ()
#17 0x000000000049e14a in Py_Main ()
#18 0x00007ffff7810830 in __libc_start_main (main=0x49dab0 <main>, argc=1, argv=0x7fffffffdd88, init=<optimized out>, 
    fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdd78) at ../csu/libc-start.c:291
#19 0x000000000049d9d9 in _start ()

Using cx_Oracle 5.3:

$ python
[...]
>>> import cx_Oracle
>>> cx_Oracle.version
'5.3'
>>> cx_Oracle.clientversion()
(11, 2, 0, 4, 0)
>>> connection = cx_Oracle.Connection('...')
>>> c = connection.cursor().execute('SELECT * FROM TABLENAME WHERE TABLENAME.ARG = :arg0', [True])
>>> c.fetchall()
[(... result ...)]
>>> c.bindvars
[<cx_Oracle.NUMBER with value True>]

When using Oracle Client 12.x, the ORA-03115 (unsupported network datatype or representation) error is raised instead.

Answer the following questions:

  1. What is your version of Python? Is it 32-bit or 64-bit?

Same behaviour with 32-bit or 64-bit

  1. What is your version of cx_Oracle?

6.0rc1

  1. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?

11.2.0.4.0. Installed from Oracle RPM

  1. What is your version of the Oracle Database?

11.2.0.1.0

  1. What is your OS and version?

Ubuntu 16.04, CentOS 7

  1. What compiler version did you use? For example, with GCC, run
    gcc --version.
  • gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  • gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
  1. What environment variables did you set? How exactly did you set them?

PYTHONPATH and LD_LIBRARY_PATH are set to correctly load the expected libraries.

  1. What exact command caused the problem (e.g. what command did you try to
    install with)? Who were you logged in as?

See above

  1. What error(s) you are seeing?

See above

Process exit with code 9

I use cx_oracle to fetch a large amount data to csv file, but the process has crashed occasionally, the process exit code is 9.

It's seems only happened on frozen app for now.

I use cx_freeze build a frozen app in this environment:

python version & platform:

Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'Linux-2.6.32-504.el6.x86_64-x86_64-with-centos-6.6-Final'

python package:

cx_freeze==4.3.4
cx_Oracle==5.2.1

oracle instant client:

instantclient_11_2

the app running on:

platform:

Linux-2.6.32-573.12.1.el6.x86_64-x86_64-with-centos-6.7-Final

oracle instant:

instantclient_11_2

oracle server:

10.2.0.5

cx_Oracle 6 Plans

Thanks for all of the feedback so far on cx_Oracle 6 beta 1. The current plan is to make a release candidate next week containing the bug fixes made so far and, if nothing significant is found, to make the final release after I return from my vacation (likely mid June). Please comment here to provide feedback or create a new issue if you discover something that needs to be addressed. Thanks!

cx_Oracle does not correctly convert TIMESTAMP WITH TIMEZONE

cx_Oracle 5.3 does not correctly handle TIMESTAMP WITH TIMEZONE

When a TIMESTAMP WITH TIMEZONE is returned from a query and converted to a Python datetime object, its time zone information is simply truncated.

Simple demonstration, where current_timestamp and systimestamp are in different time zones, and the Python objects returned for them are totally lacking in time zone information:

>>> import cx_Oracle
>>> conn = cx_Oracle.connect( user, pass, dns )
>>> print(conn.version)
12.1.0.2.0
>>> cur = conn.cursor()
>>> print( cur.execute(''' select to_char(current_timestamp), current_timestamp,
                                  to_char(systimestamp), systimestamp from dual  ''').fetchone() )
('19-APR-17 04.38.04.466727 PM -07:00',
 datetime.datetime(2017, 4, 19, 16, 38, 4, 466727),
 '20-APR-17 01.38.04.466724 AM +02:00',
 datetime.datetime(2017, 4, 20, 1, 38, 4, 466724))

This bug is observed by others as well: http://stackoverflow.com/questions/6125698/what-is-the-correct-way-to-retrieve-timezone-aware-datetime-objects-from-a-cx-or#comment7109898_6125840

The conversion in the other direction is broken as well.

When marshalling a Python timezone-aware datetime object into a bind variable… the bind variable ends up as a naïve Oracle DATE rather than a TIMESTAMP WITH TIME ZONE:

>>> from datetime import datetime, timezone, timedelta
>>> tzdate = datetime.now(tz=timezone(timedelta(hours=-1)))
>>> print(tzdate.isoformat())
'2017-04-19T22:43:53.189561-01:00'

>>> print( cur.execute("select to_char(:tzdate,'YYYY-MM-DD\"T\"HH24:MM:SS') from dual",
           {'tzdate':tzdate}).fetchone() )
('2017-04-19T22:04:53',)

>>> cur.execute("select extract(timezone_hour from :tzdate) from dual", {'tzdate':tzdate}).fetchone()
DatabaseError: ORA-30076: invalid extract field for extract source

Installing ODPI-C on Windows

I am trying to use cx_Oracle but am having issues connecting to the Oracle client. Installation succeeded without any problems but when I import I get the error below which refers me to ODPI-C. The documentation of ODPI-C has no installation instructions, simply saying to “include” it in my project. Is this something I need to do and if so, how do I?

  1. What is your version of Python? Is it 32-bit or 64-bit?
    32 bit Python 2.7
  2. What is your version of cx_Oracle?
    6.0b2
  3. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?
    OracleClient 11-2-0-3 x86 r1-6 is installed to c:\oracle\product\11.2.0\client_1
  4. What is your OS and version?
    Windows 7
  5. What compiler version did you use? For example, with GCC, run
    I am not aware of having compiled anything
  6. What environment variables did you set? How exactly did you set them?
    I have not set any, and the bin directory of the OracleClient install was added to my path by the installation.
  7. What exact command caused the problem? Who were you logged in as?
    import cx_Oracle
  8. What error(s) you are seeing?
    DPI-1047: Oracle client cannot be loaded: The specified module could not be found. See HTTPS://Oracle.github.io/odpi/doc/installation.html for help.

Error retrieving results from a table performing multiplication on column

In python 3.5.5 running cx_Oracle 6.0b2 and connecting to Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production.

If I run a query such as:

SELECT price*100
FROM my_table

and I try to retrieve the result using fetch, python seems to fail with the error: ValueError: invalid literal for int() with base 10: '0.0157'

Does anyone know what the issue could be? If I remove the multiplication by 100 it seems to work fine without any issues.

Moataz

Oracle Client Library Problem

I am using Python 3.6 x64 on Windows 10 in Spyder. I installed the cx_Oracle module but I am getting an error when I try to import it. It is giving me the error,

DatabaseError: DPI-1047: Oracle Client library cannot be loaded: %1 is not a valid Win32 application. See https://oracle.github.io/odpi/doc/installation.html for help

What does it mean by "%1 is not a valid Win32 application" and does anyone have any suggestions on how to fix this. Thanks

SessionPool won't accept unicode

Python 2.7 32 bit
cx_Oracle 5.3
Oracle instant client 12.1
Windows 7 64 bit
VCForPython27 Compiler

I have a case where it appears that the cx_Oracle.connect method will accept the login credentials as unicode strings but the cx_Oracle.SessionPool will not.

I have check this simply by using the same login credentials with both functions.

In my test case the user name, password, and dsn are all unicode strings. The exception I get when calling the session pool is below.

sessionPool = cx_oracle.SessionPool(*r_pargs, **r_kwargs)
TypeError: argument 1 must be str, not unicode

I guess this isn't really a bug so much as inconsistent behavior if the connect method accepts Unicode strings I would expect the SessionPool to as well, at least for the fields that is has in common with connect.

cx_Oracle - Oracle client on Mac OS X - RPATH issue

  1. What is your version of Python? Is it 32-bit or 64-bit?
    Python 2.7.10 64-bit
    Mac OS X Sierra

  2. What is your version of cx_Oracle?
    6.0rc1

  3. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?
    Oracle Instant client Mac OS X 12.1
    (actually I've installed it multiple times in multiple location)
    I have followed the Oracle method to the letter:
    http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html#ic_osx_inst
    (and I tired a number of other options including putting dynlib files in /usr/local/lib with no luck)

  4. What is your version of the Oracle Database?
    N/A

  5. What is your OS and version?
    Mac OS X Sierra 10.12.5

  6. What compiler version did you use? For example, with GCC, run
    gcc --version.

gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
  1. What environment variables did you set? How exactly did you set them?
    Ok, so I tried a lot of environment variables.
export OCI_LIB_DIR=$ORACLE_HOME'
export LD_LIBRARY_PATH=/usr/local/lib:~/lib:$ORACLE_HOME
export DYLD_LIBRARY_PATH=/usr/local/lib:~/lib:$ORACLE_HOME`

I also tried setting PYTHONPATH and adding the Oracle client directory to sys.path using .pth and the site.py configuration options.

  1. What exact command caused the problem (e.g. what command did you try to
    install with)? Who were you logged in as?
    python -c "import cx_Oracle; print cx_Oracle.version"

  2. What error(s) you are seeing?
    No matter what I tried I would get this error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "build/bdist.macosx-10.12-intel/egg/cx_Oracle.py", line 7, in <module>
  File "build/bdist.macosx-10.12-intel/egg/cx_Oracle.py", line 6, in __bootstrap__
cx_Oracle.DatabaseError: DPI-1047: Oracle Client library cannot be loaded: dlopen(libclntsh.dylib, 1): image not found. See https://oracle.github.io/odpi/doc/installation.html for help

So there are lots of antidotal references to this being related to SIP (System Integrity Protection), though I could find no specific technical note from Apple that says exactly what is causing the above error (inability to find dynamic linked library at run time).

So I did find a solution that did not require disabling SIP on Mac OS X. It is pretty simple, and seems to support the theory of SPI being an issue, and matches a lot of notes about discontinuing usage of the LD and DYLD paths.

From the source code download, I ran:
python setup.py build

once it is built I then modified the rpath of the cx_Oracle.so library to include the Oracle instant client location:
install_name_tool -add_rpath ~/instantclient_12_1 ./build/lib.macosx-10.12-intel-2.7/cx_Oracle.so

I could very it was added by using the otool command:
otool -l ./build/lib.macosx-10.12-intel-2.7/cx_Oracle.so

Load command 12
          cmd LC_RPATH
      cmdsize 48
         path /Users/ggordham/instantclient_12_1 (offset 12)

Now that it has been modified, I can do the normal install.

sudo python setup.py install

This puts the cx_oracle egg into the normal system path

Post this modification I can now call python and use cx_Oracle on Mac OS X normally.

The biggest issues for this are:

  • having Oracle client directory in a "known" location before building cx_Oracle
  • having to rebuild the cx_Oracle if you change Oracle client location (possibly due to version)

I beat my head on a wall for at least two days trying all the normal workarounds. This was the only model that worked.
Admiralty I didn't try any of this with Pip, I only did this from source code.
I also tied setting FORCE_RPATH=1 but on introspection it never updated the .so file correctly.

Hope this helps some future install issues.
Thanks,
Gary

cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

I know I am in a grey area here but I thought I would give it shot.
Any help would be greatly appreciated. If there is a better venue for this please advise.

cx_Oracle works perfectly from IDLE and sqlplus does also

I am trying to get it to work with PyCharm

/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Applications/PyCharm.app/Contents/helpers/pydev/pydevconsole.py 51803 51804
PyDev console: starting.
import sys;
print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['/Users/Face/PycharmProjects/PyTest'])
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
import os
os.environ['DYLD_LIBRARY_PATH'] = '/Users/Face/instantclient_12_1'
os.environ['LD_LIBRARY_PATH'] = '/Users/Face/instantclient_12_1'
import sys
sys.path.append("/usr/local/lib")
sys.path.append("/Users/Face/instantclient_12_1")
print(sys.path)
['/Applications/PyCharm.app/Contents/helpers/pydev', '/Users/Face/instantclient_12_1', '/Users/Face/anaconda/lib/python3.6/site-packages', '/Applications/PyCharm.app/Contents/helpers/pydev', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages', '/Users/Face/anaconda/lib/python3.6/site-packages/IPython/extensions', '/Users/Face/anaconda/lib/python3.6/site-packages/IPython/extensions', '/Users/Face/PycharmProjects/PyTest', '/usr/local/lib', '/Users/Face/instantclient_12_1']

import cx_Oracle
print(cx_Oracle.clientversion())
(12, 1, 0, 2, 0)
ip_addr = '192.168.1.19'
port = 1521
sid = 'xe'
dsn_tns = cx_Oracle.makedsn(ip_addr, port, sid)
db = cx_Oracle.connect('xxxxx', 'xxxxx', dsn_tns)
Traceback (most recent call last):
File "", line 5, in
cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

  1. What is your version of Python? Is it 32-bit or 64-bit?
    3.6 64bit
  2. What is your version of cx_Oracle?
    Client versions and database are aligned
  3. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?
    (12, 1, 0, 2, 0), Client downloaded from Oracle website, cx was installed via PIP, /Users/Face/instantclient_12_1'
  4. What is your version of the Oracle Database?
    Same
  5. What is your OS and version?
    El Capitan 10.11.6
  6. What compiler version did you use? For example, with GCC, run
    gcc --version.
    GCC 4.2.1
  7. What environment variables did you set? How exactly did you set them?
    See above since PyCharm doesn't see user environmental variables
  8. What exact command caused the problem (e.g. what command did you try to
    install with)? Who were you logged in as?
    When I try to run the application
  9. What error(s) you are seeing?
    cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

General question - does cx_Oracle support Py_LIMITED_API?

When I build cx_Oracle with Python 3.4.x, I end up with a wheel named:

cx_Oracle-5.3-cp34-cp34m-linux_x86_64.whl

I would like a way to build cx_Oracle so it will be compatible with all versions Python 3.4. Same issue is true on Windows.

It is OK if this is a somewhat manual process - e.g. I'm already building the wheel myself. If I need to pass obscure --global-option parameters to pip wheel, then this is OK, but the only time I tried to do this myself I ended up trying to modify setup.py, and I don't want to do that.

Debugging crash on connection

I am connecting to a set of Oracle 11g databases (11.2.0.3.0) to be precise, where I've found that cx_Oracle promptly crashes as soon as I connect. This is on Linux (amd64) with instantclient 12.1 drivers.

The same installation of cx_Oracle works fine with other 11g and 12c databases.

Is there any mechanism for fine-grained debug logging that I could use to narrow down the source

Answer the following questions:

  1. What is your version of Python? Is it 32-bit or 64-bit?

Python 2.7 (64-bit)

  1. What is your version of cx_Oracle?

5.3

  1. What is your version of the Oracle client (e.g. Instant Client)? How was it
    installed? Where is it installed?

12.1

  1. What is your OS and version?

Ubuntu Linux 14.04

  1. What compiler version did you use? For example, with GCC, run gcc --version.

4.8.2 (Ubuntu distribution package)

  1. What environment variables did you set? How exactly did you set them?

Set via a shell startup script:

$ cat /etc/profile.d/oracle.sh 
export ORACLE_HOME=/usr/lib/oracle/12.1/client64
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export TNS_ADMIN=$ORACLE_HOME/network/admin
  1. What exact command caused the problem (e.g. what command did you try to
    install with)? Who were you logged in as?
$ python
>>> import cx_Oracle
>>> conn = cx_Oracle.connect('user', 'password', 'server.name:1521/dbname')
Segmentation fault
  1. What error(s) you are seeing?

Immediate segfault upon connection attempt to specific Oracle 11g databases (but not to others).

Connection pooling with sharded db instance?

What would be the correct way to handle connection pooling with a sharded oracledb instance?

Right now we are creating a new connection string with each request/query depending on the shard key... is there a way to use the existing connection pooling within cx_Oracle for this use case?

cx_Oracle-5.3-11g.win-amd64-py3.5-2.exe seems to be the wrong version

Hopefully, I'm just an idiot, but
when I run cx_Oracle-5.3-11g.win-amd64-py3.5-2.exe the console indicates I need to be running Python 3.4:
UnsatisfiableError: The following specifications were found to be in conflict:

cx_oracle 5.2* -> python 3.4*
python 3.5*
I'm running Anaconda and have Python 3.5 using the root environment
H:>python --version
Python 3.5.3 :: Anaconda custom (64-bit)

so, is cx_Oracle-5.3-11g.win-amd64-py3.5-2.exe really what it claims to be?

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 631

Hi,

I'm trying to apply bag-of-Words to a text dataset by running the following code:
from sklearn.feature_extraction.text import CountVectorizer
vect = CountVectorizer().fit(text_train)
Xtrain = vect.transform(text_train)

But I get the following UnicodeDecodeError:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 631: invalid start byte

What does this mean and how can I fix this? What is position 631?

executemany problem with Python3?

I'm trying to insert bulk data into an oracle table using executemany(). I've done this countless times in Python2, but am encountering a weird behaviour under Python3:

I have created a test table manually to illustrate the problem:

CREATE TABLE TEST_DATA2
   ("SAMPLE" VARCHAR2(20 BYTE), 
	"KEY" VARCHAR2(10 BYTE), 
	"VALUE" NUMBER(8,0)
   )

When I insert data like this, I get the expected behaviour:

items = [['ABC', 'A', 1764], ['ABC', 'B', 23], ['ABC', 'C', 0]]  
query = "INSERT INTO test_data2 (sample, key, value) VALUES (:1, :2, :3)"    
cursor.prepare(query)  
cursor.executemany(None, items)  
conn.commit()  
Sample Key Value
ABC A 1764
ABC B 23
ABC C 0

However, when I change one of the keys to a longer string (note that the create statement allows for 10 characters!) I get this:

items = [['ABC', 'A', 1764], ['ABC', 'B', 23], ['ABC', 'CC', 0]]
Sample Key Value
ABC Null 1764
ABC Null 23
ABC CC 0

So some of the cells in the 'Key' column become Null for an unknown reason. I get no errors or warnings at all.

I have tested this with some other, similar tables (while creating this minimal example) - sometimes I can use a length of 3 characters but not 4 or more. When I insert more rows, sometimes some of them keep the right Key, some don't (usually the long Keys and some but not all of the short Keys get turned to Null). The last row always gets the right Key, though, no matter how long the Key.
(This also happens with differently named columns, but not with all of them. So far, I've only seen one column per table behave this way, and never the first one. Actually, I think it was always the last VARCHAR column.)

The exact same code works fine under Python2. It also works fine under Python3 if I insert the rows individually instead of using executemany.

I'm using Python 2.7.1 and Python 3.6.1 as 32 bit versions on a Windows10 machine.
The Oracle version is Oracle Database 11g Release 11.2.0.4.0 - 64bit Production.
Instantclient is 11_2

Can I do anything about this or is it a bug? Is there any hope to get around it by using a different version of cx_Orcale or Python3? (The script I'm writing is reqired to be in Python3, and performance is an issue, hence I need executemany().)

Thanks for any help!
Lastalda

ValueError: invalid literal for int() with base 10: '0b1

cx_Oracle 6.0b1 breaks SQLAlchemy compatibility. The following code works on previous versions:

from sqlalchemy import create_engine
engine = create_engine('oracle+cx_oracle://user:[email protected]:1521/ebs')

My Enviroment:

SO: Fedora Linux 25 (64 Bits)
Oracle Instant Client: 11.2.0.4.0 (64 Bits)

Python = 3.5.2 (64 Bits)
cx_Oracle = 6.0b1
SQLAlchemy = 1.1.9
gcc = 6.3.1 20161221 (Red Hat 6.3.1-1)

batcherrors parameter does not work for PL/SQL blocks

I'm attempting to use the cx_Oracle.Cursor.executemany method to execute a PL/SQL block, and I want to use the batcherrors parameter to catch any errors that might occur. However, my sample statement throws an error on the first execution rather than batching the errors.

>>> sql = """
>>> begin
>>>    raise_application_error(-20000, :0);
>>> end;
>>> """
>>> cursor.executemany(sql, [['a'], ['b']], batcherrors=True)
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
cx_Oracle.DatabaseError: ORA-20000: a
ORA-06512: at line 3

>>> cursor.getbatcherrors()
[]

Is this not the intended functionality of the batcherrors parameter and getbatcherrors method? And if not, can that be clarified in the documentation?

I'm running cx_Oracle 5.3 on 32-bit Python 2.7.11 on a 64-bit Windows 10 box.

(Note: I recognize that there's not really a good reason to use executemany on a PL/SQL block, but I think this should probably be clarified in the documentation.)

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.