diff options
author | Frederick Muriuki Muriithi | 2024-04-16 11:45:34 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-04-16 11:45:34 +0300 |
commit | be7b9b0936f35de21e745b87d222a63100959ff7 (patch) | |
tree | f468fc02d55725d9a206728d633383cd53309b13 /qc_app/db | |
parent | c8c1bf3049858948b76640a4fbabd49ee53198f0 (diff) | |
download | gn-uploader-be7b9b0936f35de21e745b87d222a63100959ff7.tar.gz |
Set InbredSet.InbredSetId value in a more robust way.
Diffstat (limited to 'qc_app/db')
-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 + } |