Skip to content

Commit

Permalink
Allow Connection subclasses for backups
Browse files Browse the repository at this point in the history
Fixes issue #199
  • Loading branch information
rogerbinns committed Jan 26, 2016
1 parent 358d1ea commit 1be8f22
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Added SQLITE_INDEX_CONSTRAINT_LIKE, SQLITE_INDEX_CONSTRAINT_REGEXP,
SQLITE_INDEX_CONSTRAINT_GLOB,SQLITE_IOERR_AUTH, SQLITE_FCNTL_JOURNAL_POINTER,
and SQLITE_FCNTL_VFS_POINTER constants.

Allow :class:`Connection` subclasses for backup api (:issue:`199`).

3.9.2-r1
========

Expand Down
2 changes: 1 addition & 1 deletion src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ Connection_backup(Connection *self, PyObject *args)
STRENCODING, &databasename, &source, STRENCODING, &sourcedatabasename))
return NULL;

if(Py_TYPE(source)!=&ConnectionType)
if(!PyObject_IsInstance((PyObject*)source, (PyObject*)&ConnectionType))
{
PyErr_Format(PyExc_TypeError, "source connection needs to be a Connection instance");
goto finally;
Expand Down
13 changes: 13 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3341,6 +3341,19 @@ def dummy(x,y):
self.db.createcollation("dummy", None)
self.assertRaises(apsw.SQLError, cur.execute, "select * from foo order by x collate dummy")

def testIssue199(self):
"Backup API should accept Connection subclasses"
# https://github.com/rogerbinns/apsw/issues/199
class subclass(apsw.Connection):
pass

dbsub=subclass("")
dbsub.cursor().execute("create table a(b);insert into a values(3);")

with self.db.backup("main", dbsub, "main") as b:
while not b.done:
b.step(100)

def testPysqliteRecursiveIssue(self):
"Check an issue that affected pysqlite"
# https://code.google.com/p/pysqlite/source/detail?r=260ee266d6686e0f87b0547c36b68a911e6c6cdb
Expand Down

0 comments on commit 1be8f22

Please sign in to comment.