code clean up

This commit is contained in:
Mateusz779 2023-04-18 14:16:25 +02:00
parent 3edab06328
commit 7993ca75ea

10
db.py
View File

@ -66,9 +66,7 @@ def add_conf_image(name, token):
def get_conf(columns, param, value): def get_conf(columns, param, value):
connect() connect()
with get_cur() as cur: with get_cur() as cur:
cur.execute(""" cur.execute(f"SELECT {columns} FROM image WHERE {param} = {value}")
SELECT %s FROM image WHERE %s = %s
""",(columns, param, value,))
try: try:
return cur.fetchone()[0] return cur.fetchone()[0]
except: except:
@ -186,9 +184,7 @@ def get_image_allocation_all():
def get_image_allocation(column, param, value): def get_image_allocation(column, param, value):
connect() connect()
with get_cur() as cur: with get_cur() as cur:
cur.execute(""" cur.execute(f"SELECT {column} FROM image_allocation WHERE {param} = {value} ")
SELECT %s FROM image_allocation WHERE %s = %s
""",(column, param, value,))
try: try:
return cur.fetchone()[0] return cur.fetchone()[0]
except: except:
@ -277,7 +273,7 @@ def del_image_allocation(column, value):
connect() connect()
with get_cur() as cur: with get_cur() as cur:
cur.execute(""" cur.execute("""
DELETE FROM image_allocation WHERE %s = %s DELETE FROM image_allocation WHERE `%s` = %s
""",(column,value, )) """,(column,value, ))
try: try:
conn.commit() conn.commit()