Quote:
Originally Posted by kovidgoyal
An exception that prevents further cleanup cannot cause a malformed database, I suggest you read up on how sqlite works if you dont understand why.
|
What you saying is wrong:
- The first cursor.execute is executed
- The second produces an exception
So the cleanup is partially executed on books.db.
But your reaction is for me suspicious: you simply say that your code work without investigating it. Googgle a little bit and you will see that I'm not alone with this issue, but since I'm able to reproduce it and I plan to investigate some time on it you should be happy to give me some advices on your code. This is obviously not the case!
Code:
def remove_orphaned_records(self, connection, dbpath):
from sqlite3 import DatabaseError
try:
cursor = connection.cursor()
debug_print("Removing Orphaned Collection Records")
# Purge any collections references that point into the abyss
query = 'DELETE FROM collections WHERE content_id NOT IN (SELECT _id FROM books)'
cursor.execute(query) <---- this was executed
query = 'DELETE FROM collections WHERE collection_id NOT IN (SELECT _id FROM collection)'
cursor.execute(query) <---- location of the exception
...........
except DatabaseError:
.......