aboutsummaryrefslogtreecommitdiff
path: root/qc_app
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-04-17 02:40:03 +0300
committerFrederick Muriuki Muriithi2024-04-17 02:40:03 +0300
commitc316519b4b84f16234db2939a7c8544b33c0667d (patch)
tree73b8b74e7025c281a45bc08775efa39d63783887 /qc_app
parentbe7b9b0936f35de21e745b87d222a63100959ff7 (diff)
downloadgn-uploader-c316519b4b84f16234db2939a7c8544b33c0667d.tar.gz
Use `cursor.lastrowid` to get row identifier
Use the more robust `cursor.lastrowid` to get the row identifier value, rather than using the `SELECT MAX(Id) …` form. With the `cursor.lastrowid` form, we do not have to remember to add 1 to the value to avoid conflict.
Diffstat (limited to 'qc_app')
-rw-r--r--qc_app/dbinsert.py26
1 files changed, 12 insertions, 14 deletions
diff --git a/qc_app/dbinsert.py b/qc_app/dbinsert.py
index 150127d..ef08423 100644
--- a/qc_app/dbinsert.py
+++ b/qc_app/dbinsert.py
@@ -156,25 +156,24 @@ def create_study():
with database_connection() as conn:
with conn.cursor(cursorclass=DictCursor) as cursor:
- cursor.execute("SELECT MAX(Id) AS last_id FROM ProbeFreeze")
- new_studyid = cursor.fetchone()["last_id"] + 1
values = (
- new_studyid, new_studyid, form["genechipid"],
- form["tissueid"], form["studyname"],
+ form["genechipid"],
+ form["tissueid"],
+ form["studyname"],
form.get("studyfullname", ""),
form.get("studyshortname", ""),
datetime.now().date().strftime("%Y-%m-%d"),
form["inbredsetid"])
query = (
"INSERT INTO ProbeFreeze("
- "Id, ProbeFreezeId, ChipId, TissueId, Name, FullName, "
- "ShortName, CreateTime, InbredSetId) "
- "VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)")
+ "ChipId, TissueId, Name, FullName, ShortName, CreateTime, "
+ "InbredSetId"
+ ") VALUES (%s, %s, %s, %s, %s, %s, %s)")
cursor.execute(query, values)
- lastrowid = cursor.lastrowid
+ new_studyid = cursor.lastrowid
cursor.execute(
"UPDATE ProbeFreeze SET ProbeFreezeId=%s WHERE Id=%s",
- (lastrowid, lastrowid))
+ (new_studyid, new_studyid))
flash("Study created successfully", "alert-success")
return render_template(
"continue_from_create_study.html",
@@ -266,10 +265,8 @@ def create_dataset():
flash("A dataset with that name already exists.",
"alert-error")
return redirect(url_for("dbinsert.select_dataset"), code=307)
- cursor.execute("SELECT MAX(Id) AS last_id FROM ProbeSetFreeze")
- new_datasetid = cursor.fetchone()["last_id"] + 1
values = (
- new_datasetid, form["studyid"], form["avgid"],
+ form["studyid"], form["avgid"],
datasetname, form["datasetname2"],
form["datasetfullname"], form["datasetshortname"],
datetime.now().date().strftime("%Y-%m-%d"),
@@ -277,12 +274,13 @@ def create_dataset():
"williamslab", form["datasetdatascale"])
query = (
"INSERT INTO ProbeSetFreeze("
- "Id, ProbeFreezeId, AvgID, Name, Name2, FullName, "
+ "ProbeFreezeId, AvgID, Name, Name2, FullName, "
"ShortName, CreateTime, OrderList, public, "
"confidentiality, AuthorisedUsers, DataScale) "
"VALUES"
- "(%s, %s, %s, %s, %s, %s, %s, %s, NULL, %s, %s, %s, %s)")
+ "(%s, %s, %s, %s, %s, %s, %s, NULL, %s, %s, %s, %s)")
cursor.execute(query, values)
+ new_datasetid = cursor.lastrowid
return render_template(
"continue_from_create_dataset.html",
filename=form["filename"], filetype=form["filetype"],