diff --git a/main.py b/main.py index f10928f..bfbeb69 100644 --- a/main.py +++ b/main.py @@ -59,17 +59,18 @@ class DBConn: # there might be a scenario that new cols might appear at a later stage, if so, # we shall accommodate by adding it to the database tbl_cols = self.table_mapping[tbl] - not_found = [] - for col in col_names: - if col not in tbl_cols: - not_found.append(col) + if len(tbl_cols) < len(col_names): + not_found = [] + for col in col_names: + if col not in tbl_cols: + not_found.append(col) - if len(not_found) > 0: - for new_col in not_found: - self.cur.execute(f"alter table \"{tbl}\" add column \"{new_col}\" text") + if len(not_found) > 0: + for new_col in not_found: + self.cur.execute(f"alter table \"{tbl}\" add column \"{new_col}\" text") - print(f"added {not_found} cols to {tbl}") - self.table_mapping[tbl] = column_data + print(f"added {not_found} cols to {tbl}") + self.table_mapping[tbl] = column_data sql = f"insert into \"{tbl}\" ({col_names}) values({value_placeholders})" self.cur.execute(sql, values)