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
This commit is contained in:
@@ -567,14 +567,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):
|
||||
|
||||
Reference in New Issue
Block a user