From b06020a89fcdb512bb0b6b332fb56af430fb3f8a Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Thu, 30 Jan 2025 10:24:24 +0200 Subject: [PATCH] Simplify URI opening configuration See: https://github.com/rogerbinns/apsw/issues/553#issuecomment-2623201459 --- src/alexandria3k/data_source.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/alexandria3k/data_source.py b/src/alexandria3k/data_source.py index d1476f4..f774d45 100644 --- a/src/alexandria3k/data_source.py +++ b/src/alexandria3k/data_source.py @@ -546,23 +546,17 @@ class DataSource: # pylint: disable=too-many-instance-attributes - uri_configured = False instance_id = 0 + # pylint: disable-next=unsubscriptable-object + default_vfs = apsw.vfs_names()[0] + def __init__( self, data_source, tables, attach_databases=None, ): - # Configure files to use URIs before any other apsw - # interaction. - if not DataSource.uri_configured: - apsw.config(apsw.SQLITE_CONFIG_URI, 1) - DataSource.uri_configured = True - # pylint: disable-next=unsubscriptable-object - DataSource.default_vfs = apsw.vfs_names()[0] - # Name of root table self.root_name = tables[0].get_name() @@ -572,7 +566,9 @@ def __init__( # A unique per-instance named in-memory database # It can be attached by name to other databases. self.vdb_uri = f"file:/shared-tmp-{DataSource.instance_id}?vfs=memdb" - self.vdb = apsw.Connection(self.vdb_uri) + self.vdb = apsw.Connection( + self.vdb_uri, apsw.SQLITE_OPEN_READWRITE | apsw.SQLITE_OPEN_URI + ) DataSource.instance_id += 1 self.cursor = self.vdb.cursor() # Register the module as filesource @@ -753,7 +749,9 @@ def query(self, query, partition=False): # Run query on in-memory database # drop tables self.set_query_columns(query) - partition = apsw.Connection(":memory:", apsw.SQLITE_OPEN_READWRITE) + partition = apsw.Connection( + ":memory:", apsw.SQLITE_OPEN_READWRITE | apsw.SQLITE_OPEN_URI + ) partition.create_module("filesource", self.data_source) partition.execute( log_sql(f"ATTACH DATABASE '{self.vdb_uri}' AS virtual")