comparison src/memory/sqlite.py @ 1705:3765e10ec52f

core (sqlite storage): do explicit delete to profile linked tables for deleteProfile
author Goffi <goffi@goffi.org>
date Mon, 30 Nov 2015 20:42:14 +0100
parents 4fb3280c4568
children d17772b0fe22
comparison
equal deleted inserted replaced
1704:292f9c2712f2 1705:3765e10ec52f
172 def deletionError(failure): 172 def deletionError(failure):
173 log.error(_(u"Can't delete profile [%s]") % name) 173 log.error(_(u"Can't delete profile [%s]") % name)
174 return failure 174 return failure
175 175
176 def delete(txn): 176 def delete(txn):
177 del self.profiles[name] 177 profile_id = self.profiles.pop(name)
178 txn.execute("PRAGMA foreign_keys = ON") 178 txn.execute("PRAGMA foreign_keys = ON")
179 txn.execute("DELETE FROM profiles WHERE name = ?", (name,)) 179 txn.execute("DELETE FROM profiles WHERE name = ?", (name,))
180 # FIXME: the following queries should be done by the ON DELETE CASCADE
181 # but it seems they are not, so we explicitly do them by security
182 # this need more investigation
183 txn.execute("DELETE FROM history WHERE profile_id = ?", (profile_id,))
184 txn.execute("DELETE FROM param_ind WHERE profile_id = ?", (profile_id,))
185 txn.execute("DELETE FROM private_ind WHERE profile_id = ?", (profile_id,))
186 txn.execute("DELETE FROM private_ind_bin WHERE profile_id = ?", (profile_id,))
180 return None 187 return None
181 188
182 d = self.dbpool.runInteraction(delete) 189 d = self.dbpool.runInteraction(delete)
183 d.addCallback(lambda ignore: log.info(_("Profile [%s] deleted") % name)) 190 d.addCallback(lambda ignore: log.info(_("Profile [%s] deleted") % name))
184 d.addErrback(deletionError) 191 d.addErrback(deletionError)