🚧 Save Python types for later conversion

fix/use-temp-sqlite3
Mike Gerber 3 days ago
parent 8bc443f9fb
commit 14172e3b81

@ -315,7 +315,8 @@ def column_names_csv(columns):
"""
return ",".join('"' + c + '"' for c in columns)
current_columns = defaultdict(list)
current_columns: defaultdict = defaultdict(list)
current_columns_types: dict[dict] = defaultdict(dict)
def insert_into_db(con, table, d: Dict):
"""Insert the values from the dict into the table, creating columns if necessary"""
@ -334,6 +335,11 @@ def insert_into_db(con, table, d: Dict):
current_columns[table].append(k)
con.execute(f'ALTER TABLE {table} ADD COLUMN "{k}"')
# Save types
for k in d.keys():
if k not in current_columns_types[table]:
current_columns_types[table][k] = type(d[k]).__name__
# Insert
# Unfortunately, Python3's sqlite3 does not like named placeholders with spaces, so we
# have use qmark style here.

Loading…
Cancel
Save