Skip to content

Commit 9516d7c

Browse files
committed
close cursor connections
1 parent 34b3629 commit 9516d7c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

satcfdi/catalogs/__init__.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@
1111

1212

1313
def select(catalog_name, key):
14-
with conn:
15-
c = conn.cursor()
14+
c = conn.cursor()
15+
try:
1616
c.execute(f"SELECT value FROM {catalog_name} WHERE key = ?", (pickle.dumps(key),))
1717
if ds := c.fetchone():
1818
return pickle.loads(ds[0])
19+
finally:
20+
c.close()
1921

2022

2123
def select_all(catalog_name):
22-
with conn:
23-
c = conn.cursor()
24+
c = conn.cursor()
25+
try:
2426
c.execute(f"SELECT key, value FROM {catalog_name}")
2527
return {pickle.loads(k): pickle.loads(v) for k, v in c.fetchall()}
28+
finally:
29+
c.close()
2630

2731

2832
def catalog_code(catalog_name, key, index=None):
@@ -63,10 +67,13 @@ def split_at_upper_itr(word: str):
6367

6468

6569
def trans(k):
66-
with conn:
67-
c = conn.cursor()
70+
c = conn.cursor()
71+
try:
6872
c.execute(f"SELECT value FROM Translations WHERE key = ?", (k,))
6973
if res := c.fetchone():
7074
return res[0]
71-
7275
return split_at_upper(k)
76+
finally:
77+
c.close()
78+
79+

0 commit comments

Comments
 (0)