reduce checking
This commit is contained in:
parent
bb8800d47f
commit
efb2ea8a88
19
main.py
19
main.py
@ -59,17 +59,18 @@ class DBConn:
|
|||||||
# there might be a scenario that new cols might appear at a later stage, if so,
|
# 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
|
# we shall accommodate by adding it to the database
|
||||||
tbl_cols = self.table_mapping[tbl]
|
tbl_cols = self.table_mapping[tbl]
|
||||||
not_found = []
|
if len(tbl_cols) < len(col_names):
|
||||||
for col in col_names:
|
not_found = []
|
||||||
if col not in tbl_cols:
|
for col in col_names:
|
||||||
not_found.append(col)
|
if col not in tbl_cols:
|
||||||
|
not_found.append(col)
|
||||||
|
|
||||||
if len(not_found) > 0:
|
if len(not_found) > 0:
|
||||||
for new_col in not_found:
|
for new_col in not_found:
|
||||||
self.cur.execute(f"alter table \"{tbl}\" add column \"{new_col}\" text")
|
self.cur.execute(f"alter table \"{tbl}\" add column \"{new_col}\" text")
|
||||||
|
|
||||||
print(f"added {not_found} cols to {tbl}")
|
print(f"added {not_found} cols to {tbl}")
|
||||||
self.table_mapping[tbl] = column_data
|
self.table_mapping[tbl] = column_data
|
||||||
|
|
||||||
sql = f"insert into \"{tbl}\" ({col_names}) values({value_placeholders})"
|
sql = f"insert into \"{tbl}\" ({col_names}) values({value_placeholders})"
|
||||||
self.cur.execute(sql, values)
|
self.cur.execute(sql, values)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user