def ClearDataSetData(self, data_sets, analyte_table_lst):
# Clears all the data from the database for the define data sets
# append the DataSetConcentrations table so it too will be included in the data clearing
analyte_table_lst.append('DataSetConcentrations')
# Create a single string that contains all the forigen keys in the sample table
# that has data to be removed (which is comma space delimited)
ForeignKeyColumn_lst = [col + '_foreignkey' for col in analyte_table_lst]
ForeignKeyColumn_Columns = ', '.join(ForeignKeyColumn_lst)
# Get condition string from data sets
data_set_condition = self.CreateConditionClause_OrSeriesStr(data_sets, "DataSetName")
# Resulting df: columns correspond to tables that contain data to be removed, the values in each column
# are the primary keys of records within that table that need to be deleted.
sql_statement = 'SELECT %s FROM Sample WHERE %s;' % (ForeignKeyColumn_Columns, data_set_condition)
df = pd.read_sql_query(sql_statement, self.conn)
df.columns = analyte_table_lst
# Iterate through the dataframe by column to delete each record from the db
# note: column = table name
for column in df:
condition = self.CreateConditionClause_OrSeriesStr(set(df[column]), "id")
self.conn.execute('DELETE FROM %s WHERE %s' % (column, condition))
# Finally remove the defined records from the sample table as well
self.conn.execute('DELETE FROM Sample WHERE %s' % data_set_condition)
self.CommitDB()
评论列表
文章目录