Reputation: 167
db = sqlite3.connect("SQL database")
cursor = db.cursor()
query = 'DELETE FROM Item WHERE ItemID = {}'.format(self.ID)
cursor.execute(query)
db.commit()
cursor.close()
unsure why this error is coming up as my code seems to be correct. The error is that whatever value self.ID is the error states that that there is no such column that is that value.
For example self.ID = "hello"
The error would be:
no such column: "hello"
Any help would be appreciated, thanks
Upvotes: 1
Views: 776
Reputation: 169254
Your query looks like:
DELETE FROM Item WHERE ItemID = hello
The error message is helpful in this case.
Instead do:
db = sqlite3.connect("SQL database")
cursor = db.cursor()
query = 'DELETE FROM Item WHERE ItemID = ?'
cursor.execute(query, (self.ID,))
db.commit()
cursor.close()
Notes:
?
..execute()
.execute()
as a sequence. A tuple is fine.Upvotes: 1