From 96d79f2b250603e42ee93ea33f5d1fe962402ec2 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 3 May 2018 19:02:53 -0700 Subject: [PATCH] Oops, let separate loading of pragmas for not-first-time load. Since DB_INIT was only run during first time setup, all future loads were not running the pragmas, not even the FK restriction. --- etiquette/constants.py | 5 ++++- etiquette/photodb.py | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/etiquette/constants.py b/etiquette/constants.py index c69424b..7092c4b 100644 --- a/etiquette/constants.py +++ b/etiquette/constants.py @@ -43,11 +43,14 @@ FILENAME_BADCHARS = '\\/:*?<>|"' # happens after the out-of-date check occurs, so no chance of accidentally # overwriting it. DATABASE_VERSION = 14 -DB_INIT = f''' +DB_PRAGMAS = f''' PRAGMA cache_size = 10000; PRAGMA count_changes = OFF; PRAGMA foreign_keys = ON; PRAGMA user_version = {DATABASE_VERSION}; +''' +DB_INIT = f''' +{DB_PRAGMAS} ---------------------------------------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS users( diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 9ee4dbf..1b56cdf 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -1314,6 +1314,7 @@ class PhotoDB( if existing_database: if not skip_version_check: self._check_version() + self._load_pragmas() else: self._first_time_setup() @@ -1356,10 +1357,12 @@ class PhotoDB( def _first_time_setup(self): self.log.debug('Running first-time setup.') cur = self.sql.cursor() + cur.executescript(constants.DB_INIT) + self.sql.commit() - statements = constants.DB_INIT.split(';') - for statement in statements: - cur.execute(statement) + def _load_pragmas(self): + cur = self.sql.cursor() + cur.executescript(constants.DB_PRAGMAS) self.sql.commit() def __del__(self):