My code is this:
import sqlite3
def connect():
conn = sqlite3.connect("books.db")
cur = conn.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS book (id INTEGER PRIMARY KEY, title text, author text, year integer)")
conn.commit()
conn.close()
def insert(title, author, year):
conn = sqlite3.connect("books.db")
cur = conn.cursor()
cur.execute("INSERT INTO book VALUES (NULL, ?, ?, ?)", (title, author, year))
conn.commit()
conn.close()
connect()
insert("Title", "Author", 1950)
I would like to use the WHERE NOT EXISTS SQL statement in order to avoid duplicate inputs. I tried different ways of writing in the WHERE NOT EXISTS along the cur.execute() but keep getting:
sqlite3.OperationalError: near "WHERE": syntax error