comparison 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
comparison
equal deleted inserted replaced
933:955e5c781a40 934:34dd9287dfe5
83 info(_("Connecting database")) 83 info(_("Connecting database"))
84 new_base = not os.path.exists(db_filename) # do we have to create the database ? 84 new_base = not os.path.exists(db_filename) # do we have to create the database ?
85 self.dbpool = adbapi.ConnectionPool("sqlite3", db_filename, check_same_thread=False) 85 self.dbpool = adbapi.ConnectionPool("sqlite3", db_filename, check_same_thread=False)
86 86
87 # init_defer is the initialisation deferred, initialisation is ok when all its callbacks have been done 87 # init_defer is the initialisation deferred, initialisation is ok when all its callbacks have been done
88 # XXX: foreign_keys activation doesn't seem to work, probably because of the multi-threading
89 # All the requests that need to use this feature should be run with runInteraction instead,
90 # so you can set the PRAGMA as it is done in self.deleteProfile
88 init_defer = self.dbpool.runOperation("PRAGMA foreign_keys = ON").addErrback(lambda x: error(_("Can't activate foreign keys"))) 91 init_defer = self.dbpool.runOperation("PRAGMA foreign_keys = ON").addErrback(lambda x: error(_("Can't activate foreign keys")))
89 92
90 def getNewBaseSql(): 93 def getNewBaseSql():
91 info(_("The database is new, creating the tables")) 94 info(_("The database is new, creating the tables"))
92 database_creation = ["PRAGMA user_version=%d" % CURRENT_DB_VERSION] 95 database_creation = ["PRAGMA user_version=%d" % CURRENT_DB_VERSION]
160 @return: deferred triggered once profile is actually deleted""" 163 @return: deferred triggered once profile is actually deleted"""
161 def deletionError(failure): 164 def deletionError(failure):
162 error(_("Can't delete profile [%s]") % name) 165 error(_("Can't delete profile [%s]") % name)
163 return failure 166 return failure
164 167
165 del self.profiles[name] 168 def delete(txn):
166 d = self.dbpool.runQuery("DELETE FROM profiles WHERE name = ?", (name, )) 169 del self.profiles[name]
170 txn.execute("PRAGMA foreign_keys = ON")
171 txn.execute("DELETE FROM profiles WHERE name = ?", (name,))
172 return None
173
174 d = self.dbpool.runInteraction(delete)
167 d.addCallback(lambda ignore: info(_("Profile [%s] deleted") % name)) 175 d.addCallback(lambda ignore: info(_("Profile [%s] deleted") % name))
168 d.addErrback(deletionError) 176 d.addErrback(deletionError)
169 return d 177 return d
170 178
171 #Params 179 #Params