SQLiteAPI.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:SciData_08-17-2017 作者: kitestring 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号