aboutsummaryrefslogtreecommitdiffstats
path: root/python/db.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/db.py')
-rw-r--r--python/db.py22
1 files changed, 8 insertions, 14 deletions
diff --git a/python/db.py b/python/db.py
index 084a1c44..5a4e10c8 100644
--- a/python/db.py
+++ b/python/db.py
@@ -22,17 +22,11 @@ def with_connection(f):
@with_connection
def query_db(conn, sqlstr, params=None, one=True):
- c = conn.cursor()
- if params:
- c.execute(sqlstr, params)
- else:
- c.execute(sqlstr)
- conn.commit()
- if one:
- r = c.fetchone()
- c.close()
- return r
- else:
- r = c.fetchall()
- c.close()
- return r
+ with conn.cursor() as c:
+ if params:
+ c.execute(sqlstr, params)
+ else:
+ c.execute(sqlstr)
+ conn.commit()
+ r = c.fetchone() if one else c.fetchall()
+ return r