From ebc24379352d47418c104931aed9fc1ff6c1404f Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 17 Oct 2008 16:39:30 +0000 Subject: [PATCH] Make the bind variables and fetch variables accessible although they need to be treated carefully since they are used internally; return the cursor from the execute() method as a convenience. --- Cursor.c | 8 +++++--- test/LongVar.py | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Cursor.c b/Cursor.c index bcdbdbc..339262e 100644 --- a/Cursor.c +++ b/Cursor.c @@ -111,6 +111,8 @@ static PyMemberDef g_CursorMembers[] = { { "connection", T_OBJECT_EX, offsetof(udt_Cursor, connection), READONLY }, { "numbersAsStrings", T_INT, offsetof(udt_Cursor, numbersAsStrings), 0 }, { "rowfactory", T_OBJECT, offsetof(udt_Cursor, rowFactory), 0 }, + { "bindvars", T_OBJECT, offsetof(udt_Cursor, bindVariables), READONLY }, + { "fetchvars", T_OBJECT, offsetof(udt_Cursor, fetchVariables), READONLY }, { "inputtypehandler", T_OBJECT, offsetof(udt_Cursor, inputTypeHandler), 0 }, { "outputtypehandler", T_OBJECT, offsetof(udt_Cursor, outputTypeHandler), @@ -1495,10 +1497,10 @@ static PyObject *Cursor_Execute( self->outputSize = -1; self->outputSizeColumn = -1; - // for queries, return the defined variables for possible use + // for queries, return the cursor for convenience if (isQuery) { - Py_INCREF(self->fetchVariables); - return self->fetchVariables; + Py_INCREF(self); + return (PyObject*) self; } // for all other statements, simply return None diff --git a/test/LongVar.py b/test/LongVar.py index e1bd649..d763467 100644 --- a/test/LongVar.py +++ b/test/LongVar.py @@ -71,20 +71,23 @@ class TestLongVar(BaseTestCase): def testSetOutputSizesAll(self): "test setoutputsizes is valid (all)" self.cursor.setoutputsize(25000) - longVar = self.cursor.execute("select * from TestLongRaws")[1] + self.cursor.execute("select * from TestLongRaws") + longVar = self.cursor.fetchvars[1] self.failUnlessEqual(longVar.maxlength, 25004) def testSetOutputSizesWrongColumn(self): "test setoutputsizes is valid (wrong column)" self.cursor.setoutputsize(25000, 1) - longVar = self.cursor.execute("select * from TestLongs")[1] + self.cursor.execute("select * from TestLongs") + longVar = self.cursor.fetchvars[1] self.failUnlessEqual(longVar.maxlength, 131072 * self.connection.maxBytesPerCharacter) def testSetOutputSizesRightColumn(self): "test setoutputsizes is valid (right column)" self.cursor.setoutputsize(35000, 2) - longVar = self.cursor.execute("select * from TestLongRaws")[1] + self.cursor.execute("select * from TestLongRaws") + longVar = self.cursor.fetchvars[1] self.failUnlessEqual(longVar.maxlength, 35004) def testArraySizeTooLarge(self):