-
Notifications
You must be signed in to change notification settings - Fork 364
Closed
Description
- What versions are you using?
Database: 19.16.0.0.0
platform.platform: Linux-3.10.0-1160.76.1-el7.x86_64-x86_64-with-glibc2.17
sys.maxsize > 2**32: True
platform.python_version: 3.9.13
cx_Oracle.version: 8.1.0
cx_Oracle.clientversion: (18, 3, 0, 0, 0)
-
Is it an error or a hang or a crash?
It's an error that is returned from the Database. -
What error(s) or behavior you are seeing?
cx_Oracle.DatabaseError: DPI-1037: column at array position 0 fetched with error 1406
We have noticed a case where cx_Oracle is raising an error when thecursor.outputtypehandler
is set withdefaultType
ascx_Oracle.STRING
and works when it is set withcx_Oracle.LONG_STRING
.
The issue manifested in our codebase from a SQLAlchemy change, where settingcoerce_to_unicode
was causing thedefaultType
to change. Despite the change indefaultType
, should this error manifest?
We would expect cx_Oracle to handle it gracefully and show us the query result. -
Include a runnable Python script that shows the problem.
def cx_conn():
import cx_Oracle
cx_dsn= cx_Oracle.makedsn("hostname", "12345", service_name="SERVICE_NAME")
connection = cx_Oracle.connect(user="username", password="password1234", dsn=cx_dsn)
cursor = connection.cursor()
cursor.arraysize = 500
def OutputTypeHandler(cursor, name, defaultType, size, precision, scale):
# return cursor.var(cx_Oracle.LONG_STRING, arraysize=cursor.arraysize) # works
return cursor.var(cx_Oracle.STRING, arraysize=cursor.arraysize) # doesn't work
cursor.outputtypehandler = OutputTypeHandler
view_name = 'VW_TEST_CX_ORACLE'
view_def = f"CREATE OR REPLACE VIEW {view_name} AS SELECT '{'A' * 4000}' AS a, '{'B' * 4000}' AS b, '{'C' * 4000}' AS c, '{'D' * 3950}' AS d FROM DUAL"
cursor.execute(view_def)
print(f'''This creates a long view definition. It is {len(view_def)} characters long.
This is the threshold where "sqlalchemy.exc.DatabaseError: (cx_Oracle.DatabaseError) DPI-1037: column at array position 0 fetched with error 1406" error starts.
Our production view definitions are often much longer''')
test_cmd = f"SELECT text FROM all_views WHERE view_name='{view_name}'"
result = cursor.execute(test_cmd)
x = result.fetchone()
print(x)