diff options
Diffstat (limited to 'qc_app/db/populations.py')
-rw-r--r-- | qc_app/db/populations.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/qc_app/db/populations.py b/qc_app/db/populations.py index 06ae773..48ead2e 100644 --- a/qc_app/db/populations.py +++ b/qc_app/db/populations.py @@ -29,21 +29,24 @@ def populations_by_species(conn: mdb.Connection, speciesid) -> tuple: def save_population(conn: mdb.Connection, population_details: dict) -> dict: """Save the population details to the db.""" with conn.cursor(cursorclass=DictCursor) as cursor: - cursor.execute("SELECT MAX(Id) AS last_id FROM InbredSet") - new_id = cursor.fetchone()["last_id"] + 1 cursor.execute( "INSERT INTO InbredSet(" - "Id, InbredSetId, InbredSetName, Name, SpeciesId, FullName, " - "MenuOrderId, Description" + "InbredSetName, Name, SpeciesId, FullName, MenuOrderId, Description" ") " "VALUES (" - "%(Id)s, %(InbredSetId)s, %(InbredSetName)s, %(Name)s, " - "%(SpeciesId)s, %(FullName)s, %(MenuOrderId)s, %(Description)s" + "%(InbredSetName)s, %(Name)s, %(SpeciesId)s, %(FullName)s, " + "%(MenuOrderId)s, %(Description)s" ")", { - "Id": new_id, - "InbredSetId": new_id, "MenuOrderId": 0, **population_details }) - return {**population_details, "population_id": new_id} + new_id = cursor.lastrowid + cursor.execute("UPDATE InbredSet SET InbredSetId=%s WHERE Id=%s" + (new_id, new_id)) + return { + **population_details, + "Id": new_id, + "InbredSetId": new_id, + "population_id": new_id + } |