Skip to content

Commit

Permalink
Fix bug in database clean up after word is removed from config
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Nov 20, 2024
1 parent 0721ed3 commit 264d8e0
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions language_practice/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,12 @@ def update_set(

words_to_delete = current_words - config_words
for word in words_to_delete:
self.delete(SqliteHandle.WORD_TABLE_NAME, "word = '{word}'")
res = self.cursor.execute(
"SELECT name FROM sqlite_master WHERE type='table';"
)
names = res.fetchall()
names_to_drop = [
name[0]
for name in names
if name[0] != "" and not name[0].isspace() and name[0].startswith(word)
]
for name in names_to_drop:
self.drop_table(name)
self.delete(SqliteHandle.WORD_TABLE_NAME, f"word = '{word}'")
res = self.cursor.execute(f"SELECT table_uuids FROM '{SqliteHandle.WORD_TABLE_NAME}' WHERE word='{word}';")
table_uuids = res.fetchone()[0]
if table_uuids is not None:
for table_uuid in table_uuids.split(","):
self.drop_table(table_uuid)

# pylint: disable=too-many-branches
# pylint: disable=too-many-statements
Expand Down Expand Up @@ -236,7 +230,7 @@ def update_word(self, entry: Entry, scraped: list[list[list[str]]] | None):
else:
final_charts = [charts]

res = self.cursor.execute(f"SELECT table_uuids FROM words WHERE word='{word}';")
res = self.cursor.execute(f"SELECT table_uuids FROM '{SqliteHandle.WORD_TABLE_NAME}' where word = '{word}';")
table_uuids = res.fetchone()[0]
if table_uuids is not None:
for table_uuid in table_uuids.split(","):
Expand Down Expand Up @@ -332,7 +326,7 @@ def delete_set(self, set_id: int):
Delete a set from the database.
"""
res = self.cursor.execute(
f"SELECT table_uuids FROM 'words' WHERE flashcard_set_id = {set_id};"
f"SELECT table_uuids FROM '{SqliteHandle.WORD_TABLE_NAME}' WHERE flashcard_set_id = {set_id};"
)
for uuids in res:
if uuids[0] is not None:
Expand Down

0 comments on commit 264d8e0

Please sign in to comment.