1
    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

0

1 Answer 1

1

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:

  1. The parameter placeholder for sqlite3 is ?.
  2. The parameter value should be the second argument to .execute()
  3. That parameter should be passed to .execute() as a sequence. A tuple is fine.
Sign up to request clarification or add additional context in comments.

3 Comments

I'm not sure whether this is related to your answer but it says that the current statement uses 1 binding when there are 3 supplied?
Ok what is self.ID?
Sorry, I completely missed this comment, I forgot to add the comma xD thanks for your help though

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.