I have the following code to delete a row from a table called posts. For some reason, the post is not being deleted. I have also tried administering the command manually via command line and it worked just fine. I also know for sure the post_id is correct and not null as I have also tried passing it back and printing it and the ID shows up correctly. I should mention that it does not spit out an error. Just nothing happens.
def deletePost(post_id):
con = sql.connect("database.db")
cur = con.cursor()
cur.execute("DELETE FROM posts WHERE id = (?)", [post_id])
con.close()
You are not committing, before close commit the changes:
Check this.
cur.execute("DELETE FROM posts WHERE item = ?", (post_id,))
con.commit()
con.close()
General info for sqlite:
One import point is, the comma "," in tuple. if you have one item then adding the comma at end is mandatory but if you have more than one entries in tuple(which you are passing to sqlite) then no comma after last item.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With