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:
parent
8f099cfbc1
commit
ebc2437935
8
Cursor.c
8
Cursor.c
@ -111,6 +111,8 @@ static PyMemberDef g_CursorMembers[] = {
|
|||||||
{ "connection", T_OBJECT_EX, offsetof(udt_Cursor, connection), READONLY },
|
{ "connection", T_OBJECT_EX, offsetof(udt_Cursor, connection), READONLY },
|
||||||
{ "numbersAsStrings", T_INT, offsetof(udt_Cursor, numbersAsStrings), 0 },
|
{ "numbersAsStrings", T_INT, offsetof(udt_Cursor, numbersAsStrings), 0 },
|
||||||
{ "rowfactory", T_OBJECT, offsetof(udt_Cursor, rowFactory), 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),
|
{ "inputtypehandler", T_OBJECT, offsetof(udt_Cursor, inputTypeHandler),
|
||||||
0 },
|
0 },
|
||||||
{ "outputtypehandler", T_OBJECT, offsetof(udt_Cursor, outputTypeHandler),
|
{ "outputtypehandler", T_OBJECT, offsetof(udt_Cursor, outputTypeHandler),
|
||||||
@ -1495,10 +1497,10 @@ static PyObject *Cursor_Execute(
|
|||||||
self->outputSize = -1;
|
self->outputSize = -1;
|
||||||
self->outputSizeColumn = -1;
|
self->outputSizeColumn = -1;
|
||||||
|
|
||||||
// for queries, return the defined variables for possible use
|
// for queries, return the cursor for convenience
|
||||||
if (isQuery) {
|
if (isQuery) {
|
||||||
Py_INCREF(self->fetchVariables);
|
Py_INCREF(self);
|
||||||
return self->fetchVariables;
|
return (PyObject*) self;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for all other statements, simply return None
|
// for all other statements, simply return None
|
||||||
|
|||||||
@ -71,20 +71,23 @@ class TestLongVar(BaseTestCase):
|
|||||||
def testSetOutputSizesAll(self):
|
def testSetOutputSizesAll(self):
|
||||||
"test setoutputsizes is valid (all)"
|
"test setoutputsizes is valid (all)"
|
||||||
self.cursor.setoutputsize(25000)
|
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)
|
self.failUnlessEqual(longVar.maxlength, 25004)
|
||||||
|
|
||||||
def testSetOutputSizesWrongColumn(self):
|
def testSetOutputSizesWrongColumn(self):
|
||||||
"test setoutputsizes is valid (wrong column)"
|
"test setoutputsizes is valid (wrong column)"
|
||||||
self.cursor.setoutputsize(25000, 1)
|
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,
|
self.failUnlessEqual(longVar.maxlength,
|
||||||
131072 * self.connection.maxBytesPerCharacter)
|
131072 * self.connection.maxBytesPerCharacter)
|
||||||
|
|
||||||
def testSetOutputSizesRightColumn(self):
|
def testSetOutputSizesRightColumn(self):
|
||||||
"test setoutputsizes is valid (right column)"
|
"test setoutputsizes is valid (right column)"
|
||||||
self.cursor.setoutputsize(35000, 2)
|
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)
|
self.failUnlessEqual(longVar.maxlength, 35004)
|
||||||
|
|
||||||
def testArraySizeTooLarge(self):
|
def testArraySizeTooLarge(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user