aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/sample_data.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py
index 89e95fc..ccb03f2 100644
--- a/gn3/db/sample_data.py
+++ b/gn3/db/sample_data.py
@@ -252,19 +252,13 @@ def insert_sample_data(conn: Any, # pylint: disable=[R0913]
"""
def __insert_data(conn, table, value):
if value and value != "x":
-
with conn.cursor() as cursor:
- cursor.execute(
- "SELECT Id FROM PublishData where Id = %s "
- "AND StrainId = %s",
- (data_id, strain_id))
- if not cursor.fetchone():
- columns = ", ".join(_MAP.get(table))
- cursor.execute((f"INSERT INTO {table} "
- f"({columns}) "
- f"VALUES (%s, %s, %s)"),
- (strain_id, data_id, value))
- return cursor.rowcount
+ columns = ", ".join(_MAP.get(table))
+ cursor.execute((f"INSERT INTO {table} "
+ f"({columns}) "
+ f"VALUES (%s, %s, %s)"),
+ (strain_id, data_id, value))
+ return cursor.rowcount
return 0
def __insert_case_attribute(conn, case_attr, value):
@@ -304,6 +298,16 @@ def insert_sample_data(conn: Any, # pylint: disable=[R0913]
try:
count = 0
+
+ # Check if the data already exists:
+ with conn.cursor() as cursor:
+ cursor.execute(
+ "SELECT Id FROM PublishData where Id = %s "
+ "AND StrainId = %s",
+ (data_id, strain_id))
+ if cursor.fetchone(): # Data already exists
+ return count
+
for header, value in zip(csv_header.split(","), data.split(",")):
header = header.strip()
value = value.strip()