From fc2a05dedd9ef02d3711f1bd0abb2b3cf84453c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fukan=20=C3=9Crker?= Date: Thu, 28 Dec 2023 19:56:20 +0300 Subject: [PATCH] Comments been removed after parent post deleted --- delete.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/delete.py b/delete.py index 2064903..3a647ea 100644 --- a/delete.py +++ b/delete.py @@ -8,6 +8,14 @@ def deletePost(postID): cursor.execute(f"delete from posts where id = {postID}") cursor.execute(f"update sqlite_sequence set seq = seq-1") connection.commit() + connection.close() + connection = sqlite3.connect("db/comments.db") + cursor = connection.cursor() + cursor.execute(f"select count(*) from comments where post = {postID}") + commentCount = list(cursor)[0][0] + cursor.execute(f"delete from comments where post = {postID}") + cursor.execute(f"update sqlite_sequence set seq = seq - {commentCount}") + connection.commit() message("2", f'POST: "{postID}" DELETED')