properly lock the DB

This commit is contained in:
Damien Elmes 2011-03-15 06:33:43 +09:00
parent c17758b01c
commit 9226922af8
3 changed files with 10 additions and 4 deletions

View file

@ -14,9 +14,8 @@ except ImportError:
from anki.hooks import runHook
class DB(object):
def __init__(self, path, level="EXCLUSIVE", text=None):
self._db = sqlite.connect(
path, timeout=0, isolation_level=level)
def __init__(self, path, text=None):
self._db = sqlite.connect(path, timeout=0, isolation_level=None)
if text:
self._db.text_factory = text
self._path = path

View file

@ -113,9 +113,14 @@ qconf=?, conf=?, data=?""",
simplejson.dumps(self.conf), simplejson.dumps(self.data))
def save(self):
"Flush, then commit DB."
"Flush, commit DB, and take out another write lock."
self.flush()
self.db.commit()
self.lock()
def lock(self):
self.db.execute("begin exclusive")
self.db.execute("update deck set mod=mod")
def close(self, save=True):
"Disconnect from DB."
@ -135,6 +140,7 @@ qconf=?, conf=?, data=?""",
def rollback(self):
self.db.rollback()
self.lock()
def modSchema(self):
if not self.schemaDirty():

View file

@ -34,6 +34,7 @@ def Deck(path, queue=True):
elif create:
deck.addModel(BasicModel(deck))
deck.save()
deck.lock()
if not queue:
return deck
# rebuild queue