From a6f1fc28141b002b4e6d956cedb58556ba17f8ef Mon Sep 17 00:00:00 2001 From: Andrew Olsen Date: Thu, 17 Aug 2023 12:14:51 +1200 Subject: [PATCH] Use journal_mode = WAL on annotations.db as originally intended --- kart/annotations/db.py | 2 +- kart/sqlalchemy/gpkg.py | 6 ++++-- kart/sqlalchemy/sqlite.py | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/kart/annotations/db.py b/kart/annotations/db.py index 7cd978bda..92d9beb53 100644 --- a/kart/annotations/db.py +++ b/kart/annotations/db.py @@ -57,7 +57,7 @@ def ignore_readonly_db(session): @contextlib.contextmanager def _annotations_session(db_path): - engine = sqlite_engine(db_path) + engine = sqlite_engine(db_path, journal_mode="WAL") sm = sessionmaker(bind=engine) inspector = sqlalchemy.inspect(engine) is_readonly = None diff --git a/kart/sqlalchemy/gpkg.py b/kart/sqlalchemy/gpkg.py index 740c23bf3..07f79536b 100644 --- a/kart/sqlalchemy/gpkg.py +++ b/kart/sqlalchemy/gpkg.py @@ -17,13 +17,15 @@ class Db_GPKG(BaseDb): preparer = SQLiteIdentifierPreparer(SQLiteDialect()) @classmethod - def create_engine(cls, path, **kwargs): + def create_engine(cls, path, *, journal_mode=None, **kwargs): def _on_connect(pysqlite_conn, connection_record): pysqlite_conn.isolation_level = None pysqlite_conn.enable_load_extension(True) pysqlite_conn.load_extension(spatialite_path) pysqlite_conn.enable_load_extension(False) dbcur = pysqlite_conn.cursor() + if journal_mode: + dbcur.execute(f"PRAGMA journal_mode = {journal_mode};") dbcur.execute("SELECT EnableGpkgMode();") dbcur.execute("PRAGMA foreign_keys = ON;") dbcur.execute(f"PRAGMA cache_size = -{cls.GPKG_CACHE_SIZE_MiB * 1024};") @@ -64,7 +66,7 @@ def list_tables(cls, sess, db_schema=None): @classmethod def pk_name(cls, sess, db_schema=None, table=None): - """ Find the primary key for a GeoPackage table """ + """Find the primary key for a GeoPackage table""" # Requirement 150: # A feature table or view SHALL have a column that uniquely identifies the diff --git a/kart/sqlalchemy/sqlite.py b/kart/sqlalchemy/sqlite.py index 9d02e0385..edf965ccf 100644 --- a/kart/sqlalchemy/sqlite.py +++ b/kart/sqlalchemy/sqlite.py @@ -5,7 +5,7 @@ import sqlalchemy -def sqlite_engine(path): +def sqlite_engine(path, *, journal_mode=None): """ An engine for non-spatial, non-GPKG sqlite databases. """ @@ -13,6 +13,8 @@ def sqlite_engine(path): def _on_connect(pysqlite_conn, connection_record): pysqlite_conn.isolation_level = None dbcur = pysqlite_conn.cursor() + if journal_mode: + dbcur.execute(f"PRAGMA journal_mode = {journal_mode};") dbcur.execute("PRAGMA foreign_keys = ON;") path = os.path.expanduser(path)