Explicitly close sqlite connection
The context manage on Connection only commit the connection but it should still be explicitly closed. Closes #13859 (grafted from b529128ca42c72ed76c0b19c71277f917488d05c) --HG-- branch : 7.0
This commit is contained in:
1 parent
0a3cbcb67c
commit
16034d1882
2 files changed
+17
-14
No files matched your search
@@ -485,8 +485,8 @@ class Database(DatabaseInterface):
|
||||
path = os.path.join(config.get('database', 'path'),
|
||||
database_name + '.sqlite')
|
||||
with sqlite.connect(path) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.close()
|
||||
conn.cursor()
|
||||
conn.close()
|
||||
|
||||
@classmethod
|
||||
def drop(cls, connection, database_name):
|
||||
|
||||
@@ -165,19 +165,22 @@ def _sqlite_copy(file_, restore=False):
|
||||
finally:
|
||||
database.put_connection(connection, True)
|
||||
|
||||
with Transaction().start(DB_NAME, 0) as transaction, \
|
||||
sqlite.connect(file_) as conn2:
|
||||
with Transaction().start(DB_NAME, 0) as transaction:
|
||||
conn1 = transaction.connection
|
||||
if restore:
|
||||
conn2, conn1 = conn1, conn2
|
||||
if hasattr(conn1, 'backup'):
|
||||
conn1.backup(conn2)
|
||||
else:
|
||||
try:
|
||||
import sqlitebck
|
||||
except ImportError:
|
||||
return False
|
||||
sqlitebck.copy(conn1, conn2)
|
||||
with sqlite.connect(file_) as conn2:
|
||||
if restore:
|
||||
in_, out = conn2, conn1
|
||||
else:
|
||||
in_, out = conn1, conn2
|
||||
if hasattr(in_, 'backup'):
|
||||
in_.backup(out)
|
||||
else:
|
||||
try:
|
||||
import sqlitebck
|
||||
except ImportError:
|
||||
return False
|
||||
sqlitebck.copy(in_, out)
|
||||
conn2.close()
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user