Add additional check for calling setinputsizes() with an empty dictionary in

order to avoid the error "cx_Oracle.ProgrammingError: positional and named
binds cannot be intermixed"
(https://github.com/oracle/python-cx_Oracle/issues/199).
This commit is contained in:
Anthony Tuininga 2019-01-08 14:41:01 -07:00
parent b340771c37
commit 43a485042f
2 changed files with 27 additions and 4 deletions

View File

@ -1743,16 +1743,23 @@ static PyObject *cxoCursor_setInputSizes(cxoCursor *cursor, PyObject *args,
// eliminate existing bind variables
Py_CLEAR(cursor->bindVariables);
// if no values passed, do nothing further, but return an empty list or
// dictionary as appropriate
if (numKeywordArgs == 0 && numPositionalArgs == 0) {
if (keywordArgs)
return PyDict_New();
return PyList_New(0);
}
// retain bind variables
cursor->setInputSizes = 1;
if (numKeywordArgs > 0)
cursor->bindVariables = PyDict_New();
else cursor->bindVariables = PyList_New(numPositionalArgs);
if (!cursor->bindVariables)
return NULL;
// retain bind variables if any were set
if (numKeywordArgs > 0 || numPositionalArgs > 0)
cursor->setInputSizes = 1;
// process each input
if (numKeywordArgs > 0) {
i = 0;

View File

@ -538,6 +538,22 @@ class TestCursor(BaseTestCase):
self.cursor.execute("select :val from dual", val = "Test Value")
self.assertEqual(self.cursor.fetchall(), [("Test Value",)])
def testSetInputSizesEmptyDict(self):
"test setting input sizes with an empty dictionary"
emptyDict = {}
self.cursor.prepare("select 236 from dual")
self.cursor.setinputsizes(**emptyDict)
self.cursor.execute(None, emptyDict)
self.assertEqual(self.cursor.fetchall(), [(236,)])
def testSetInputSizesEmptyList(self):
"test setting input sizes with an empty list"
emptyList = {}
self.cursor.prepare("select 239 from dual")
self.cursor.setinputsizes(*emptyList)
self.cursor.execute(None, emptyList)
self.assertEqual(self.cursor.fetchall(), [(239,)])
def testSetInputSizesByPosition(self):
"""test setting input sizes with positional args"""
var = self.cursor.var(cx_Oracle.STRING, 100)