[go: nahoru, domu]

Skip to content

Commit

Permalink
Fixes #13. Since december 2005, row_factory is a feature of the Conne…
Browse files Browse the repository at this point in the history
…ction

class instead of the Cursor class. It was kept in the Cursor class for
backwards compatibility. Now it was time to finally remove it from the
Cursor class.
  • Loading branch information
ghaering committed Aug 18, 2015
1 parent c819a1e commit 10dbbe4
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 32 deletions.
19 changes: 1 addition & 18 deletions lib/test/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,6 @@ def CheckIsInstance(self):
MyCursor),
"cursor is not instance of MyCursor")

class RowFactoryTestsBackwardsCompat(unittest.TestCase):
def setUp(self):
self.con = sqlite.connect(":memory:")

def CheckIsProducedByFactory(self):
cur = self.con.cursor(factory=MyCursor)
cur.execute("select 4+5 as foo")
row = cur.fetchone()
self.assertTrue(isinstance(row,
dict),
"row is not instance of dict")
cur.close()

def tearDown(self):
self.con.close()

class RowFactoryTests(unittest.TestCase):
def setUp(self):
self.con = sqlite.connect(":memory:")
Expand Down Expand Up @@ -192,10 +176,9 @@ def tearDown(self):
def suite():
connection_suite = unittest.makeSuite(ConnectionFactoryTests, "Check")
cursor_suite = unittest.makeSuite(CursorFactoryTests, "Check")
row_suite_compat = unittest.makeSuite(RowFactoryTestsBackwardsCompat, "Check")
row_suite = unittest.makeSuite(RowFactoryTests, "Check")
text_suite = unittest.makeSuite(TextFactoryTests, "Check")
return unittest.TestSuite((connection_suite, cursor_suite, row_suite_compat, row_suite, text_suite))
return unittest.TestSuite((connection_suite, cursor_suite, row_suite, text_suite))

def test():
runner = unittest.TextTestRunner()
Expand Down
6 changes: 0 additions & 6 deletions src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,6 @@ PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args,

_pysqlite_drop_unused_cursor_references(self);

if (cursor && self->row_factory != Py_None) {
Py_XDECREF(((pysqlite_Cursor*)cursor)->row_factory);
Py_INCREF(self->row_factory);
((pysqlite_Cursor*)cursor)->row_factory = self->row_factory;
}

return cursor;
}

Expand Down
9 changes: 2 additions & 7 deletions src/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ static int pysqlite_cursor_init(pysqlite_Cursor* self, PyObject* args, PyObject*

self->rowcount = -1L;

Py_INCREF(Py_None);
self->row_factory = Py_None;

if (!pysqlite_check_thread(self->connection)) {
return -1;
}
Expand Down Expand Up @@ -137,7 +134,6 @@ static void pysqlite_cursor_dealloc(pysqlite_Cursor* self)
Py_XDECREF(self->row_cast_map);
Py_XDECREF(self->description);
Py_XDECREF(self->lastrowid);
Py_XDECREF(self->row_factory);
Py_XDECREF(self->next_row);

if (self->in_weakreflist != NULL) {
Expand Down Expand Up @@ -915,8 +911,8 @@ PyObject* pysqlite_cursor_iternext(pysqlite_Cursor *self)
next_row_tuple = self->next_row;
self->next_row = NULL;

if (self->row_factory != Py_None) {
next_row = PyObject_CallFunction(self->row_factory, "OO", self, next_row_tuple);
if (self->connection->row_factory != Py_None) {
next_row = PyObject_CallFunction(self->connection->row_factory, "OO", self, next_row_tuple);
Py_DECREF(next_row_tuple);
} else {
next_row = next_row_tuple;
Expand Down Expand Up @@ -1077,7 +1073,6 @@ static struct PyMemberDef cursor_members[] =
{"arraysize", T_INT, offsetof(pysqlite_Cursor, arraysize), 0},
{"lastrowid", T_OBJECT, offsetof(pysqlite_Cursor, lastrowid), RO},
{"rowcount", T_LONG, offsetof(pysqlite_Cursor, rowcount), RO},
{"row_factory", T_OBJECT, offsetof(pysqlite_Cursor, row_factory), 0},
{NULL}
};

Expand Down
1 change: 0 additions & 1 deletion src/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ typedef struct
int arraysize;
PyObject* lastrowid;
long rowcount;
PyObject* row_factory;
pysqlite_Statement* statement;
int closed;
int reset;
Expand Down

0 comments on commit 10dbbe4

Please sign in to comment.