fixes for sqlite on python 3.6
we need to switch to autocommit mode before executing vacuums & certain pragmas also removed the pysqlite version workaround; we just use the python-provided versions in all cases now as it is new enough
This commit is contained in:
parent
a05ebdbefb
commit
e6adc3c195
@ -201,6 +201,7 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
||||
self.modSchema(check=False)
|
||||
self.ls = self.scm
|
||||
# ensure db is compacted before upload
|
||||
self.db.setAutocommit(True)
|
||||
self.db.execute("vacuum")
|
||||
self.db.execute("analyze")
|
||||
self.close()
|
||||
@ -810,8 +811,10 @@ and queue = 0""", intTime(), self.usn())
|
||||
return ("\n".join(problems), ok)
|
||||
|
||||
def optimize(self):
|
||||
self.db.setAutocommit(True)
|
||||
self.db.execute("vacuum")
|
||||
self.db.execute("analyze")
|
||||
self.db.setAutocommit(False)
|
||||
self.lock()
|
||||
|
||||
# Logging
|
||||
|
15
anki/db.py
15
anki/db.py
@ -5,14 +5,7 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
try:
|
||||
from pysqlite2 import dbapi2 as sqlite
|
||||
vi = sqlite.version_info
|
||||
if vi[0] > 2 or vi[1] > 6:
|
||||
# latest pysqlite breaks anki
|
||||
raise ImportError()
|
||||
except ImportError:
|
||||
from sqlite3 import dbapi2 as sqlite
|
||||
from sqlite3 import dbapi2 as sqlite
|
||||
|
||||
Error = sqlite.Error
|
||||
|
||||
@ -103,3 +96,9 @@ class DB(object):
|
||||
|
||||
def interrupt(self):
|
||||
self._db.interrupt()
|
||||
|
||||
def setAutocommit(self, autocommit):
|
||||
if autocommit:
|
||||
self._db.isolation_level = None
|
||||
else:
|
||||
self._db.isolation_level = ''
|
||||
|
@ -46,8 +46,10 @@ class Anki2Importer(Importer):
|
||||
self._importCards()
|
||||
self._importStaticMedia()
|
||||
self._postImport()
|
||||
self.dst.db.setAutocommit(True)
|
||||
self.dst.db.execute("vacuum")
|
||||
self.dst.db.execute("analyze")
|
||||
self.dst.db.setAutocommit(False)
|
||||
|
||||
# Notes
|
||||
######################################################################
|
||||
|
@ -444,8 +444,10 @@ create table meta (dirMod int, lastUsn int); insert into meta values (0, 0);
|
||||
def forceResync(self):
|
||||
self.db.execute("delete from media")
|
||||
self.db.execute("update meta set lastUsn=0,dirMod=0")
|
||||
self.db.execute("vacuum analyze")
|
||||
self.db.commit()
|
||||
self.db.setAutocommit(True)
|
||||
self.db.execute("vacuum analyze")
|
||||
self.db.setAutocommit(False)
|
||||
|
||||
# Media syncing: zips
|
||||
##########################################################################
|
||||
|
@ -2,7 +2,6 @@
|
||||
# Copyright: Damien Elmes <anki@ichi2.net>
|
||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
import os
|
||||
import copy
|
||||
import re
|
||||
|
||||
@ -14,7 +13,6 @@ from anki.consts import *
|
||||
from anki.stdmodels import addBasicModel, addClozeModel, addForwardReverse, \
|
||||
addForwardOptionalReverse
|
||||
|
||||
|
||||
def Collection(path, lock=True, server=False, sync=True, log=False):
|
||||
"Open a new or existing collection. Path must be unicode."
|
||||
assert path.endswith(".anki2")
|
||||
@ -26,6 +24,7 @@ def Collection(path, lock=True, server=False, sync=True, log=False):
|
||||
assert c not in base
|
||||
# connect
|
||||
db = DB(path)
|
||||
db.setAutocommit(True)
|
||||
if create:
|
||||
ver = _createDB(db)
|
||||
else:
|
||||
@ -36,6 +35,7 @@ def Collection(path, lock=True, server=False, sync=True, log=False):
|
||||
db.execute("pragma journal_mode = wal")
|
||||
else:
|
||||
db.execute("pragma synchronous = off")
|
||||
db.setAutocommit(False)
|
||||
# add db to col and do any remaining upgrades
|
||||
col = _Collection(db, server, log)
|
||||
if ver < SCHEMA_VERSION:
|
||||
|
Loading…
Reference in New Issue
Block a user