Close the SQLite connection to memory database when the database has been dropped

Instead of relying on the garbage collector to close the connection by deleting
the object, this ensures that the memory database is actually dropped before a
new connection is instantiated and keep the database.

Closes #13796
(grafted from 0a2239fb548b5b20a9ae4d4a8c8c6c34cfed5683)

--HG--
branch : 6.0
This commit is contained in:
Cédric Krier
2025-01-16 09:47:25 +01:00
parent 6caa2667d4
commit ddc997adee
+16 -5
View File
@@ -441,14 +441,25 @@ class Database(DatabaseInterface):
return self._conn
def put_connection(self, connection=None, close=False):
pass
assert connection == self._conn or self._conn is None
if self.name == ':memory:':
if (self._local.memory_database._conn is None
and connection and close):
connection.close()
self._conn = None
elif close:
connection.close()
self._conn = None
def close(self):
if self.name == ':memory:':
return
if self._conn is None:
return
self._conn = None
if (self._local.memory_database._conn is None
and self._conn):
self._conn.close()
self._conn = None
elif self._conn:
self._conn.close()
self._conn = None
@classmethod
def create(cls, connection, database_name):