SQLite(Python apsw)无法回滚,因为它';她很忙

SQLite(Python apsw)无法回滚,因为它';她很忙,python,sqlite,Python,Sqlite,我正在使用Pythonapsw绑定处理SQLite数据库。代码如下所示: with apsw.Connection(path) as t: c = t.cursor() c.execute(...) ... more code ... if c.execute(...).next()[0]: raise Exception 我希望with语句放置一个保存点,而raise语句回滚到该保存点(或者,如果没有什么要提升的,提交事务)。它提交得很好,但当

我正在使用Python
apsw
绑定处理SQLite数据库。代码如下所示:

with apsw.Connection(path) as t:
    c = t.cursor()
    c.execute(...)
    ... more code ...
    if c.execute(...).next()[0]:
        raise Exception
我希望
with
语句放置一个保存点,而
raise
语句回滚到该保存点(或者,如果没有什么要提升的,提交事务)。它提交得很好,但当有什么东西要提升时,它拒绝回滚:

BusyError: BusyError: cannot rollback savepoint - SQL statements in progress
我不知道先去哪里看。据我所知,错误意味着有另一个连接阻止了访问,但从代码上看不是这样的,如果是这样的话,提交时不是也会失败吗

SQLite 3.7.7.1,匹配的
apsw
,Python 2.7。

我找到了它:

if c.execute(...).next()[0]:
    raise Exception
问题是,当我使用
next()
获取下一行时,底层游标保持活动状态,准备返回更多行。必须明确关闭:

if c.execute(...).next()[0]:
    c.close()
    raise Exception
或者通过读取所有数据隐式地:

if list(c.execute(...))[0][0]:
    raise Exception
更新。为了方便起见,我编写了一个Python类,它包装了
apsw.Cursor
,并提供了以下内容:

with Cursor(connection) as c:
    c.execute(...)

这是SQLite本身的一个问题。它于2012年3月在3.7.11版中修复。从:

挂起语句不再阻止回滚。相反,挂起语句将在回滚后的下一次访问时返回SQLITE_ABORT