diff options
author | BonfaceKilz | 2022-03-02 15:41:02 +0300 |
---|---|---|
committer | BonfaceKilz | 2022-03-12 15:33:09 +0300 |
commit | 5a20d1a42990dc97c47ed4e7da286494693a7a05 (patch) | |
tree | 2d508708ea8d6a18dac919c1940d0476ad139d30 /gn3/db/sample_data.py | |
parent | ba006bdd5ae2053575e11539186d5c5041f070c1 (diff) | |
download | genenetwork3-5a20d1a42990dc97c47ed4e7da286494693a7a05.tar.gz |
Check whether publish data already exists before inserting
* gn3/db/sample_data.py (insert_sample_data): If data already exists in the
table, do not attempt an insert; otherwise, an error will be generated.
Diffstat (limited to 'gn3/db/sample_data.py')
-rw-r--r-- | gn3/db/sample_data.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py index e3e1676..7aacdc1 100644 --- a/gn3/db/sample_data.py +++ b/gn3/db/sample_data.py @@ -258,11 +258,16 @@ def insert_sample_data(conn: Any, # pylint: disable=[R0913] f"{_map.get(table)} " f"VALUES %s %s %s") with conn.cursor() as cursor: - cursor.execute((f"INSERT INTO {table} " - f"{_map.get(table)} " - f"VALUES (%s, %s, %s)"), - (strain_id, data_id, value)) - return cursor.rowcount + cursor.execute( + "SELECT Id FROM PublishData where Id = %s " + "AND StrainId = %s", + (data_id, strain_id)) + if not cursor.fetchone(): + cursor.execute((f"INSERT INTO {table} " + f"{_map.get(table)} " + f"VALUES (%s, %s, %s)"), + (strain_id, data_id, value)) + return cursor.rowcount return 0 def __insert_case_attribute(conn, strain_id, |