Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions things/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sqlite3
from textwrap import dedent
from typing import Optional, Union
import weakref


# --------------------------------------------------
Expand Down Expand Up @@ -186,6 +187,7 @@ def __init__(self, filepath=None, print_sql=False):
# See: https://sqlite.org/uri.html#recognized_query_parameters
uri = f"file:{self.filepath}?mode=ro"
self.connection = sqlite3.connect(uri, uri=True) # pylint: disable=E1101
self._finalizer = weakref.finalize(self, self._close_connection)

# Test for migrated database in Things 3.15.16+
# --------------------------------
Expand Down Expand Up @@ -510,6 +512,10 @@ def execute_query(self, sql_query, parameters=(), row_factory=None):

return cursor.fetchall()

def _close_connection(self):
"""Close the database connection."""
self.connection.close()


# Helper functions

Expand Down