This commit is contained in:
Kovid Goyal 2015-02-15 12:33:46 +05:30
parent 12271efe3d
commit bbbcc7774e

View File

@ -106,10 +106,15 @@ class DBPrefs(dict): # {{{
self.db.execute('DELETE FROM preferences WHERE key=?', (key,)) self.db.execute('DELETE FROM preferences WHERE key=?', (key,))
def __setitem__(self, key, val): def __setitem__(self, key, val):
if not self.disable_setting and val != self[key]: if not self.disable_setting:
raw = self.to_raw(val) try:
self.db.execute('INSERT OR REPLACE INTO preferences (key,val) VALUES (?,?)', (key, raw)) current_val = self[key]
dict.__setitem__(self, key, val) except KeyError:
current_val = object()
if val != current_val:
raw = self.to_raw(val)
self.db.execute('INSERT OR REPLACE INTO preferences (key,val) VALUES (?,?)', (key, raw))
dict.__setitem__(self, key, val)
def set(self, key, val): def set(self, key, val):
self.__setitem__(key, val) self.__setitem__(key, val)