Make use of db.cursor() in with blocks

This commit is contained in:
Stephan Kulow
2022-10-26 15:49:14 +02:00
parent 217bbcadb5
commit 4dc7e972a2
3 changed files with 103 additions and 95 deletions

View File

@@ -188,12 +188,14 @@ class DBRevision:
def files_list(self, db):
if self._files:
return self._files
cur = db.cursor()
cur.execute("SELECT * from files where revision_id=%s", (self.dbid,))
self._files = []
for row in cur.fetchall():
(_, _, name, md5, size, mtime) = row
self._files.append({"md5": md5, "size": size, "mtime": mtime, "name": name})
with db.cursor() as cur:
cur.execute("SELECT * from files where revision_id=%s", (self.dbid,))
self._files = []
for row in cur.fetchall():
(_, _, name, md5, size, mtime) = row
self._files.append(
{"md5": md5, "size": size, "mtime": mtime, "name": name}
)
self._files.sort(key=lambda x: x["name"])
return self._files