Always change db cursor settings
This commit is contained in:
parent
6b2f619096
commit
1aa741a25b
1 changed files with 12 additions and 9 deletions
21
src/Db/Db.py
21
src/Db/Db.py
|
@ -61,14 +61,6 @@ class Db(object):
|
||||||
self.conn.row_factory = sqlite3.Row
|
self.conn.row_factory = sqlite3.Row
|
||||||
self.conn.isolation_level = None
|
self.conn.isolation_level = None
|
||||||
self.cur = self.getCursor()
|
self.cur = self.getCursor()
|
||||||
if config.db_mode == "security":
|
|
||||||
self.cur.execute("PRAGMA journal_mode = WAL")
|
|
||||||
self.cur.execute("PRAGMA synchronous = NORMAL")
|
|
||||||
else:
|
|
||||||
self.cur.execute("PRAGMA journal_mode = MEMORY")
|
|
||||||
self.cur.execute("PRAGMA synchronous = OFF")
|
|
||||||
if self.foreign_keys:
|
|
||||||
self.execute("PRAGMA foreign_keys = ON")
|
|
||||||
self.log.debug(
|
self.log.debug(
|
||||||
"Connected to %s in %.3fs (opened: %s, sqlite version: %s)..." %
|
"Connected to %s in %.3fs (opened: %s, sqlite version: %s)..." %
|
||||||
(self.db_path, time.time() - s, len(opened_dbs), sqlite3.version)
|
(self.db_path, time.time() - s, len(opened_dbs), sqlite3.version)
|
||||||
|
@ -136,7 +128,18 @@ class Db(object):
|
||||||
def getCursor(self):
|
def getCursor(self):
|
||||||
if not self.conn:
|
if not self.conn:
|
||||||
self.connect()
|
self.connect()
|
||||||
return DbCursor(self.conn, self)
|
|
||||||
|
cur = DbCursor(self.conn, self)
|
||||||
|
if config.db_mode == "security":
|
||||||
|
cur.execute("PRAGMA journal_mode = WAL")
|
||||||
|
cur.execute("PRAGMA synchronous = NORMAL")
|
||||||
|
else:
|
||||||
|
cur.execute("PRAGMA journal_mode = MEMORY")
|
||||||
|
cur.execute("PRAGMA synchronous = OFF")
|
||||||
|
if self.foreign_keys:
|
||||||
|
cur.execute("PRAGMA foreign_keys = ON")
|
||||||
|
|
||||||
|
return cur
|
||||||
|
|
||||||
# Get the table version
|
# Get the table version
|
||||||
# Return: Table version or None if not exist
|
# Return: Table version or None if not exist
|
||||||
|
|
Loading…
Reference in a new issue