Reputation: 962
I'm trying to add to the DB some keywords from a text file.
After having created the database and table and connected to it, I can not insert the data as I get an error no such a column.
Here is what I am trying:
conn = sqlite3.connect('AKeywords.db')
c = conn.cursor()
# Table structure here below as created.
# c.execute("CREATE TABLE Keywords(key text, initials text, words integer, special text, digit text)")
with open('C:/Users/CobraCommander/Desktop/keys.txt','r',encoding='utf-8') as key_text_file:
for key in key_text_file:
key = key.strip()
words = key.count(' ') + 1
initials = key[:2]
special = hasSpecial(key) # Function that looks for special char
digit = hasDigits(key) # Function that looks for digits
print('Keyword:',key,'Words No:',words,'Initials:',initials,'Special:',special,'Digits:',digit)
c.execute("INSERT INTO Keywords VALUES (key, initials, words, special, digit)")
conn.commit()
conn.close()
This is the error that I get:
sqlite3.OperationalError: no such column: key
How do I insert these values from the text file into the table?
Upvotes: 0
Views: 60
Reputation: 13026
updated this line
c.execute("INSERT INTO Keywords VALUES (key, initials, words, special, digit)")
to
c.execute("INSERT INTO Keywords VALUES (?, ?, ?, ?, ?)", (key,words, initials,special,digit));
Upvotes: 1