Skip to content

Commit

Permalink
Can't WAL or optimize read only databases
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerbinns committed Oct 7, 2024
1 parent 28c224d commit ec62bda
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions apsw/bestpractice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def connection_wal(connection: apsw.Connection) -> None:
Reduces contention and improves write performance. WAL is
`described here <https://www.sqlite.org/wal.html>`__.
"""
connection.pragma("journal_mode", "wal")
try:
connection.pragma("journal_mode", "wal")
except apsw.ReadOnlyError:
pass


def connection_busy_timeout(connection: apsw.Connection, duration_ms: int = 100) -> None:
Expand Down Expand Up @@ -70,7 +73,10 @@ def connection_optimize(connection: apsw.Connection) -> None:
There is more detail in the `documentation
<https://sqlite.org/lang_analyze.html>`__.
"""
connection.pragma("optimize", 0x10002)
try:
connection.pragma("optimize", 0x10002)
except apsw.ReadOnlyError:
pass

def connection_recursive_triggers(connection: apsw.Connection) -> None:
"""Recursive triggers are off for historical backwards compatibility
Expand Down
3 changes: 3 additions & 0 deletions apsw/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10132,6 +10132,9 @@ def testBestPractice(self) -> None:
with self.assertNoLogs():
self.assertRaises(apsw.SQLError, con.execute, dqs)

# can't optimize or WAL readonly databases
apsw.Connection(self.db.filename, flags = apsw.SQLITE_OPEN_READONLY)

def testExtDataClassRowFactory(self) -> None:
"apsw.ext.DataClassRowFactory"
dcrf = apsw.ext.DataClassRowFactory()
Expand Down

0 comments on commit ec62bda

Please sign in to comment.