Skip to content

Commit

Permalink
Simplify URI opening configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dspinellis committed Jan 30, 2025
1 parent f78beb4 commit b06020a
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/alexandria3k/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit b06020a

Please sign in to comment.