Problem:
I have a problem with inserting data into SQlite with python. At this moment i am new to python so this must be beginner mistake.
Errors :
OperationalError: unrecognized token: "{"
What I have tried:
I have read many tutorials and tried many options as shown below in the code examples.But i cannot get this to work without error for some reason.
Some examples :
cursor.execute("INSERT INTO wanted_movie (tmdb_id, name, year) VALUES ({tmdb_id}, {name}, {year})".format(
tmdb_id=str(data['id']), name=str(data['title']), year=str(data['release_date']).split('-')[0]))
cursor.execute("INSERT INTO wanted_movie (tmdb_id, name, year) VALUES ({tmdb_id}, {name}, {year})", {
"tmdb_id": str(data['id']), "name": str(data['title']), "year": str(data['release_date']).split('-')[0]})
conn.commit()
Question :
Can someone help me to insert a row correctly with SQlite3 in a pythonic way?
**to unpack the dictionary in the second example. However, please read docs.python.org/2/library/sqlite3.html and don't usestr.formatto interpolate variables!