diff src/memory/sqlite.py @ 934:34dd9287dfe5

plugin account: bug fix profile deletion from the database + unsubscribe the contacts
author souliane <souliane@mailoo.org>
date Mon, 24 Mar 2014 16:21:14 +0100
parents c2f6ada7858f
children 6404df5305e3
line wrap: on
line diff
--- a/src/memory/sqlite.py	Mon Mar 24 10:16:07 2014 +0100
+++ b/src/memory/sqlite.py	Mon Mar 24 16:21:14 2014 +0100
@@ -85,6 +85,9 @@
         self.dbpool = adbapi.ConnectionPool("sqlite3", db_filename, check_same_thread=False)
 
         # init_defer is the initialisation deferred, initialisation is ok when all its callbacks have been done
+        # XXX: foreign_keys activation doesn't seem to work, probably because of the multi-threading
+        # All the requests that need to use this feature should be run with runInteraction instead,
+        # so you can set the PRAGMA as it is done in self.deleteProfile
         init_defer = self.dbpool.runOperation("PRAGMA foreign_keys = ON").addErrback(lambda x: error(_("Can't activate foreign keys")))
 
         def getNewBaseSql():
@@ -162,8 +165,13 @@
             error(_("Can't delete profile [%s]") % name)
             return failure
 
-        del self.profiles[name]
-        d = self.dbpool.runQuery("DELETE FROM profiles WHERE name = ?", (name, ))
+        def delete(txn):
+            del self.profiles[name]
+            txn.execute("PRAGMA foreign_keys = ON")
+            txn.execute("DELETE FROM profiles WHERE name = ?", (name,))
+            return None
+
+        d = self.dbpool.runInteraction(delete)
         d.addCallback(lambda ignore: info(_("Profile [%s] deleted") % name))
         d.addErrback(deletionError)
         return d