Reputation: 425
This is my code:
title = "Importunate Widow"
conn = sqlite3.connect('parable.sqlite')
c = conn.cursor()
sqlite3.enable_callback_tracebacks(True)
c.executescript("""
CREATE TABLE IF NOT EXISTS _index(
title text NOT NULL,
context text NOT NULL
);
CREATE TABLE IF NOT EXISTS {}(
value int NOT NULL,
number int NOT NULL,
question text NOT NULL,
choice1 text,
choice2 text,
choice3 text,
choice4 text,
answer text NOT NULL,
explanation text,
see text
)""".format(title))
c.executemany('INSERT INTO _index(title,context) VALUES(?,?)', index)
c.executemany('INSERT INTO {}(value,number,question,choice1,choice2,choice3,choice4,answer,explanation,see) VALUES(?,?,?,?,?,?,?,?,?,?)'.format(title), quiz)
conn.commit()
conn.close()
This gives me:
OperationalError Traceback (most recent call last)
/home/user/Hobby/Quiz/quiz_sqlite.py in <module>()
sqlite3.enable_callback_tracebacks(True)
87
---> 88 c.executescript("""CREATE TABLE IF NOT EXISTS _index(title text NOT NULL,context text NOT NULL);CREATE TABLE IF NOT EXISTS {}(value int NOT NULL,number int NOT NULL,question text NOT NULL,choice1 text,choice2 text,choice3 text,choice4 text,answer text NOT NULL,explanation text,check text )""".format(title))
89
90 c.executemany('INSERT INTO _index(title,context) VALUES(?,?)', index)
OperationalError: near "Widow": syntax error
I am basically iterating over multiple files and inserting data into tables named after the files. I have searched the internet and have turned up with nothing.
What I tried:
;
after the )
before """
,
after see text
see
to refer
None of this helped!
What is the syntax error in the code?
Upvotes: 0
Views: 106
Reputation: 4549
You're trying to use Importunate Widow
as a table name. You're not allowed to use spaces in a table or field name.
Upvotes: 1