I have a simple insert statement in sqlite3, but somehow the python version doesn't work, but the exact same statement works fine in console. And python doesn't show any insert error. Any suggestion on how to fix this insert statement in python?
Insert statement:
INSERT INTO facilities (facility_id,facility_name) VALUES ('239SIE39', 'Lobby A');
Table creation statement:
CREATE TABLE IF NOT EXISTS facilities (id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, facility_id, facility_name)
Function to store data:
def store_data(table_name: str, rec: dict):
keys = ','.join(rec.keys())
values = tuple(rec.values())
stmt = f"INSERT INTO {table_name} ({keys}) VALUES {values}"
cur.execute(stmt)
AttributeError: 'sqlite3.Cursor' object has no attribute 'commit'I thought about that too