In certain cases where non-long values follow LOB values in the list of bind

variables, the error "ORA-24816: Expanded non LONG bind data supplied after
actual LONG or LOB column" is raised; this occurs if the length of the supplied
value, when expanded, might exceed 4000 bytes
(https://github.com/oracle/python-cx_Oracle/issues/50).
This commit is contained in:
Anthony Tuininga 2017-07-25 12:16:54 -06:00
parent af01c81a1b
commit 1f917aafbb
2 changed files with 34 additions and 0 deletions

View File

@ -449,6 +449,8 @@ static udt_VariableType *Variable_TypeByValue(PyObject* value, uint32_t* size,
}
if (cxString_Check(value)) {
*size = (uint32_t) cxString_GetSize(value);
if (*size == 0)
*size = 1;
return &vt_String;
}
if (PyBool_Check(value)) {
@ -459,6 +461,8 @@ static udt_VariableType *Variable_TypeByValue(PyObject* value, uint32_t* size,
#if PY_MAJOR_VERSION < 3
if (PyUnicode_Check(value)) {
*size = (uint32_t) PyUnicode_GET_SIZE(value);
if (*size == 0)
*size = 1;
return &vt_NationalCharString;
}
if (PyInt_Check(value))

View File

@ -341,3 +341,33 @@ class TestStringVar(BaseTestCase):
(2, "long string " * 30))
self.connection.commit()
def testIssue50(self):
"test issue 50 - avoid error ORA-24816"
cursor = self.connection.cursor()
try:
cursor.execute("drop table issue_50 purge")
except cx_Oracle.DatabaseError:
pass
cursor.execute("""
create table issue_50 (
Id number(11) primary key,
Str1 nvarchar2(256),
Str2 nvarchar2(256),
Str3 nvarchar2(256),
NClob1 nclob,
NClob2 nclob
)""")
idVar = cursor.var(cx_Oracle.NUMBER)
cursor.execute("""
insert into issue_50 (Id, Str2, Str3, NClob1, NClob2, Str1)
values (:arg0, :arg1, :arg2, :arg3, :arg4, :arg5)
returning id into :arg6""",
[1, '555a4c78', 'f319ef0e', '23009914', '', '', idVar])
cursor = self.connection.cursor()
cursor.execute("""
insert into issue_50 (Id, Str2, Str3, NClob1, NClob2, Str1)
values (:arg0, :arg1, :arg2, :arg3, :arg4, :arg5)
returning id into :arg6""",
[2, u'd5ff845a', u'94275767', u'bf161ff6', u'', u'', idVar])
cursor.execute("drop table issue_50 purge")