Use transactions when writing metadata

This commit is contained in:
Nick Hall 2017-03-03 19:52:41 +00:00
parent 49c5ec5977
commit 0813ba25db

View File

@ -378,6 +378,7 @@ class DBAPI(DbGeneric):
key: string key: string
value: item, will be serialized here value: item, will be serialized here
""" """
self._txn_begin()
self.dbapi.execute("SELECT 1 FROM metadata WHERE setting = ?", [key]) self.dbapi.execute("SELECT 1 FROM metadata WHERE setting = ?", [key])
row = self.dbapi.fetchone() row = self.dbapi.fetchone()
if row: if row:
@ -388,6 +389,7 @@ class DBAPI(DbGeneric):
self.dbapi.execute( self.dbapi.execute(
"INSERT INTO metadata (setting, value) VALUES (?, ?)", "INSERT INTO metadata (setting, value) VALUES (?, ?)",
[key, pickle.dumps(value)]) [key, pickle.dumps(value)])
self._txn_commit()
def get_name_group_keys(self): def get_name_group_keys(self):
""" """
@ -871,6 +873,7 @@ class DBAPI(DbGeneric):
return gstats return gstats
def save_gender_stats(self, gstats): def save_gender_stats(self, gstats):
self._txn_begin()
self.dbapi.execute("DELETE FROM gender_stats") self.dbapi.execute("DELETE FROM gender_stats")
for key in gstats.stats: for key in gstats.stats:
female, male, unknown = gstats.stats[key] female, male, unknown = gstats.stats[key]
@ -878,6 +881,7 @@ class DBAPI(DbGeneric):
"(given_name, female, male, unknown) " "(given_name, female, male, unknown) "
"VALUES (?, ?, ?, ?)", "VALUES (?, ?, ?, ?)",
[key, female, male, unknown]) [key, female, male, unknown])
self._txn_commit()
def get_surname_list(self): def get_surname_list(self):
""" """