From 983dfdab9fa9657036ca77a36cc531758eff1a6d Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Wed, 17 Apr 2019 15:31:40 -0600 Subject: [PATCH] Adjust return value of cursor.callproc() to follow documentation so that only positional arguments are returned (https://github.com/oracle/python-cx_Oracle/pull/287). --- src/cxoCursor.c | 4 ++-- test/Cursor.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/cxoCursor.c b/src/cxoCursor.c index d901b67..ac0302e 100644 --- a/src/cxoCursor.c +++ b/src/cxoCursor.c @@ -1326,8 +1326,8 @@ static PyObject *cxoCursor_callProc(cxoCursor *cursor, PyObject *args, keywordArguments) < 0) return NULL; - // create the return value - numArgs = PyList_GET_SIZE(cursor->bindVariables); + // create the return value (only positional arguments are returned) + numArgs = (listOfArguments) ? PySequence_Size(listOfArguments) : 0; results = PyList_New(numArgs); if (!results) return NULL; diff --git a/test/Cursor.py b/test/Cursor.py index 6afaa8a..6bb943a 100644 --- a/test/Cursor.py +++ b/test/Cursor.py @@ -86,6 +86,30 @@ class TestCase(TestEnv.BaseTestCase): results = self.cursor.callproc("proc_Test", ("hi", 5, var)) self.assertEqual(results, ["hi", 10, 2.0]) + def testCallProcAllKeywords(self): + "test executing a stored procedure with args in keywordParameters" + kwargs = dict(a_InOutValue=self.cursor.var(cx_Oracle.NUMBER), + a_InValue="hi", a_OutValue=self.cursor.var(cx_Oracle.NUMBER)) + kwargs['a_InOutValue'].setvalue(0, 5) + results = self.cursor.callproc("proc_Test", keywordParameters=kwargs) + self.assertEqual(results, []) + self.assertEqual(kwargs['a_InOutValue'].getvalue(), 10) + self.assertEqual(kwargs['a_OutValue'].getvalue(), 2.0) + + def testCallProcOnlyLastKeyword(self): + "test executing a stored procedure with last arg in keywordParameters" + kwargs = dict(a_OutValue = self.cursor.var(cx_Oracle.NUMBER)) + results = self.cursor.callproc("proc_Test", ("hi", 5), kwargs) + self.assertEqual(results, ["hi", 10]) + self.assertEqual(kwargs['a_OutValue'].getvalue(), 2.0) + + def testCallProcRepeatedKeywordParameters(self): + "test executing a stored procedure, repeated arg in keywordParameters" + kwargs = dict(a_InValue="hi", + a_OutValue=self.cursor.var(cx_Oracle.NUMBER)) + self.assertRaises(cx_Oracle.DatabaseError, self.cursor.callproc, + "proc_Test", parameters=("hi", 5), keywordParameters=kwargs) + def testCallProcNoArgs(self): """test executing a stored procedure without any arguments""" results = self.cursor.callproc(u"proc_TestNoArgs")