From bb846a3c975186fac14d77a3001eae10d55c64c1 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 25 Feb 2023 14:14:21 -0800 Subject: [PATCH] Use randomized uris for memory databases. --- voussoirkit/worms.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/voussoirkit/worms.py b/voussoirkit/worms.py index e9cbaba..f3978f9 100644 --- a/voussoirkit/worms.py +++ b/voussoirkit/worms.py @@ -139,6 +139,7 @@ class Database(metaclass=abc.ABCMeta): # But if your application uses string IDs, set self.id_type = str self.id_type = int self.last_commit_id = None + self._memdb_random = RNG.getrandbits(16) @abc.abstractmethod def _init_column_index(self): @@ -173,7 +174,7 @@ class Database(metaclass=abc.ABCMeta): if isinstance(path, pathclass.Path): path = path.absolute_path if path == ':memory:': - sql_read = sqlite3.connect('file:memdb1?mode=memory&cache=shared&mode=ro', uri=True) + sql_read = sqlite3.connect(f'file:{self._memdb_random}?mode=memory&cache=shared', uri=True) sql_read.row_factory = sqlite3.Row else: log.debug('Connecting to sqlite file "%s".', path) @@ -186,7 +187,7 @@ class Database(metaclass=abc.ABCMeta): path = path.absolute_path if path == ':memory:': - sql_write = sqlite3.connect('file:memdb1?mode=memory&cache=shared', uri=True) + sql_write = sqlite3.connect(f'file:{self._memdb_random}?mode=memory&cache=shared', uri=True) sql_write.row_factory = sqlite3.Row else: log.debug('Connecting to sqlite file "%s".', path)