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.
This commit is contained in:
Anthony Tuininga 2008-10-17 16:39:30 +00:00
parent 8f099cfbc1
commit ebc2437935
2 changed files with 11 additions and 6 deletions

View File

@ -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

View File

@ -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):