View Single Post
Old 09-20-2013, 07:29 AM   #9
tetanos
Junior Member
tetanos began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Apr 2013
Device: PTS-T2
Quote:
Originally Posted by kovidgoyal View Post
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:
  1. The first cursor.execute is executed
  2. 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:
           .......
tetanos is offline   Reply With Quote