hv-service/Objekte.py
2021-01-16 19:47:34 +01:00

47 lines
1.3 KiB
Python

from dbpool import getConnection
def get_objekte():
try:
dbh = getConnection()
objekte = []
cur = dbh.cursor()
cur.execute("SELECT id, shortname, flaeche FROM objekt")
for (id, shortname, flaeche) in cur:
objekte.append({
"id": id,
"shortname": shortname,
"flaeche": flaeche
})
return objekte
except Exception as err:
return str(err), 500
finally:
dbh.close()
def get_objekt(id=None):
try:
dbh = getConnection()
cur = dbh.cursor()
cur.execute("SELECT id, shortname, flaeche FROM objekt WHERE id = ?", (id,))
objekt = None
try:
(id, shortname, flaeche) = cur.next()
objekt = {
"id": id,
"shortname": shortname,
"flaeche": flaeche
}
except StopIteration:
return "Objekt not found", 404
try:
(id, shortname, flaeche) = cur.next()
return "More than one Objekt by that id ({}, {}, {})".format(id, shortname, flaeche), 500
except:
pass
return objekt
except Exception as err:
return str(err), 500
finally:
dbh.close()