diff options
author | BonfaceKilz | 2022-02-08 08:01:04 +0300 |
---|---|---|
committer | BonfaceKilz | 2022-02-08 08:07:03 +0300 |
commit | 63716e121e0b546b158acd27349eae187546e7cc (patch) | |
tree | 2b73aa087055b9aa5e2b7f78e0b1c320dd529d7e | |
parent | 34aa1f04ded87af501bb34ecdd5937e082c010f6 (diff) | |
download | genenetwork3-63716e121e0b546b158acd27349eae187546e7cc.tar.gz |
db: traits: Allow insertions of "0" in resp. sample values tables
When editing values from "x" to "0"(or any other value) when editing data, an
"update" statement was being run; thereby no new value was being inserted. To
the end user, modifying an "x" value to something else meant that no value was
being inserted. This commit fixes that by doing an insert whenever a change
from "x" to "0" is performed.
* gn3/db/traits.py (update_sample_data): Add insert statements whenever an
"update" statement returns a 0 row-count.
-rw-r--r-- | gn3/db/traits.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/gn3/db/traits.py b/gn3/db/traits.py index e80f41b..772db52 100644 --- a/gn3/db/traits.py +++ b/gn3/db/traits.py @@ -140,6 +140,16 @@ def update_sample_data(conn: Any, #pylint: disable=[R0913] (None if value == "x" else value, strain_id, data_id)) updated_published_data = cursor.rowcount + if not updated_published_data: + cursor.execute( + "SELECT * FROM " + "PublishData WHERE StrainId = " + "%s AND Id = %s" % (strain_id, data_id)) + if not cursor.fetchone(): + cursor.execute(("INSERT INTO PublishData (Id, StrainId, " + " value) VALUES (%s, %s, %s)") % + (data_id, strain_id, value)) + updated_published_data = cursor.rowcount # Update the PublishSE table cursor.execute(("UPDATE PublishSE SET error = %s " @@ -147,13 +157,34 @@ def update_sample_data(conn: Any, #pylint: disable=[R0913] (None if error == "x" else error, strain_id, data_id)) updated_se_data = cursor.rowcount + if not updated_se_data: + cursor.execute( + "SELECT * FROM " + "PublishSE WHERE StrainId = " + "%s AND DataId = %s" % (strain_id, data_id)) + if not cursor.fetchone(): + cursor.execute(("INSERT INTO PublishSE (StrainId, DataId, " + " error) VALUES (%s, %s, %s)") % + (strain_id, data_id, + None if error == "x" else error)) + updated_se_data = cursor.rowcount # Update the NStrain table cursor.execute(("UPDATE NStrain SET count = %s " "WHERE StrainId = %s AND DataId = %s"), - (None if count == "x" else count, - strain_id, data_id)) + (count, strain_id, data_id)) updated_n_strains = cursor.rowcount + if not updated_n_strains: + cursor.execute( + "SELECT * FROM " + "NStrain WHERE StrainId = " + "%s AND DataId = %s" % (strain_id, data_id)) + if not cursor.fetchone(): + cursor.execute(("INSERT INTO NStrain " + "(StrainId, DataId, count) " + "VALUES (%s, %s, %s)") % + (strain_id, data_id, count)) + updated_n_strains = cursor.rowcount return (updated_published_data, updated_se_data, updated_n_strains) |