1
"""Functions used by all sqlite-backed stores."""
6
from pysqlite2 import dbapi2 as sqlite3
9
def with_cursor(method):
10
"""Decorator that encloses the method in a database transaction.
12
Even though SQLite is supposed to be useful in autocommit mode, we've
13
found cases where the database continued to be locked for writing
14
until the cursor was closed. With this in mind, instead of using
15
the autocommit mode, we explicitly terminate transactions and enforce
16
cursor closing with this decorator.
19
def inner(self, *args, **kwargs):
21
# Create the database connection only when we start to actually
22
# use it. This is essentially just a workaroud of a sqlite bug
23
# happening when 2 concurrent processes try to create the tables
24
# around the same time, the one which fails having an incorrect
25
# cache and not seeing the tables
26
self._db = sqlite3.connect(self._filename)
29
cursor = self._db.cursor()
31
result = method(self, cursor, *args, **kwargs)