0

I am not sure why this isn't working. I am trying to delete an entry from the database I created. Here is sample of parts of the python code that is erroring out.

delete_domain = 'm.com'

sql.execute('''CREATE TABLE if not exists domains
(name TEXT NOT NULL PRIMARY KEY,
clock CHAR(100) NOT NULL,
person TEXT,
reason TEXT);''')


def searchdb(name):
sql.execute("DELETE FROM domains WHERE name = name;", (name))
sql.commit() # Commit changes to the DB
print("Record successfully deleted")
cursor.close()

searchdb(delete_domain) # Testing method

ERROR below:

sql.execute("DELETE FROM domains WHERE name = name;", (name)) sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 5 supplied.

  • Change `(name))` to `(name,))` (with the comma) to make a tuple. Currently it's trying to unpack the characters of your string one-by-one. It expects an iterable, which a string is, so it ends up iterating the individual characters and looks for a placeholder to put them in your query string... but there's only 1 available. – roganjosh Mar 22 '18 at 19:18
  • Thank you for the advice! I am not long getting that error but a new one appeared. sql.execute("DELETE FROM domains WHERE name = name;" (name,)) TypeError: 'str' object is not callable – James Middleton Mar 22 '18 at 19:21
  • You're welcome. It's a really common issue, I was looking for the canonical dupe but got beaten to it. – roganjosh Mar 22 '18 at 19:22
  • Yes, because now you got rid of the comma after the query string. The fix is to add a comma only, you should not remove the comma between `WHERE name = name;"` and `(name,))` – roganjosh Mar 22 '18 at 19:26

0 Answers0