1

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)
4
  • 3
    Why didn't you post the Python code? Commented May 30, 2022 at 14:32
  • Wild guess: You forgot to commit the changes in your code. Commented May 30, 2022 at 14:35
  • @Matthias AttributeError: 'sqlite3.Cursor' object has no attribute 'commit' I thought about that too Commented May 30, 2022 at 14:35
  • 2
    stackoverflow.com/questions/20860127/… Commented May 30, 2022 at 15:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.