9742: Rewrite remove_* methods
Avoid using table maps in _do_remove.
This commit is contained in:
parent
6092065fe3
commit
a3718e23ab
@ -1605,77 +1605,75 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
|
|||||||
return self.get_table_func(table_name,"gramps_id_func")(gramps_id)
|
return self.get_table_func(table_name,"gramps_id_func")(gramps_id)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def remove_person(self, handle, transaction):
|
||||||
|
"""
|
||||||
|
Remove the Person specified by the database handle from the
|
||||||
|
database, preserving the change in the passed transaction.
|
||||||
|
"""
|
||||||
|
self._do_remove(handle, transaction, PERSON_KEY)
|
||||||
|
|
||||||
def remove_source(self, handle, transaction):
|
def remove_source(self, handle, transaction):
|
||||||
"""
|
"""
|
||||||
Remove the Source specified by the database handle from the
|
Remove the Source specified by the database handle from the
|
||||||
database, preserving the change in the passed transaction.
|
database, preserving the change in the passed transaction.
|
||||||
"""
|
"""
|
||||||
self._do_remove(handle, transaction, self.source_map,
|
self._do_remove(handle, transaction, SOURCE_KEY)
|
||||||
self.source_id_map, SOURCE_KEY)
|
|
||||||
|
|
||||||
def remove_citation(self, handle, transaction):
|
def remove_citation(self, handle, transaction):
|
||||||
"""
|
"""
|
||||||
Remove the Citation specified by the database handle from the
|
Remove the Citation specified by the database handle from the
|
||||||
database, preserving the change in the passed transaction.
|
database, preserving the change in the passed transaction.
|
||||||
"""
|
"""
|
||||||
self._do_remove(handle, transaction, self.citation_map,
|
self._do_remove(handle, transaction, CITATION_KEY)
|
||||||
self.citation_id_map, CITATION_KEY)
|
|
||||||
|
|
||||||
def remove_event(self, handle, transaction):
|
def remove_event(self, handle, transaction):
|
||||||
"""
|
"""
|
||||||
Remove the Event specified by the database handle from the
|
Remove the Event specified by the database handle from the
|
||||||
database, preserving the change in the passed transaction.
|
database, preserving the change in the passed transaction.
|
||||||
"""
|
"""
|
||||||
self._do_remove(handle, transaction, self.event_map,
|
self._do_remove(handle, transaction, EVENT_KEY)
|
||||||
self.event_id_map, EVENT_KEY)
|
|
||||||
|
|
||||||
def remove_media(self, handle, transaction):
|
def remove_media(self, handle, transaction):
|
||||||
"""
|
"""
|
||||||
Remove the MediaPerson specified by the database handle from the
|
Remove the MediaPerson specified by the database handle from the
|
||||||
database, preserving the change in the passed transaction.
|
database, preserving the change in the passed transaction.
|
||||||
"""
|
"""
|
||||||
self._do_remove(handle, transaction, self.media_map,
|
self._do_remove(handle, transaction, MEDIA_KEY)
|
||||||
self.media_id_map, MEDIA_KEY)
|
|
||||||
|
|
||||||
def remove_place(self, handle, transaction):
|
def remove_place(self, handle, transaction):
|
||||||
"""
|
"""
|
||||||
Remove the Place specified by the database handle from the
|
Remove the Place specified by the database handle from the
|
||||||
database, preserving the change in the passed transaction.
|
database, preserving the change in the passed transaction.
|
||||||
"""
|
"""
|
||||||
self._do_remove(handle, transaction, self.place_map,
|
self._do_remove(handle, transaction, PLACE_KEY)
|
||||||
self.place_id_map, PLACE_KEY)
|
|
||||||
|
|
||||||
def remove_family(self, handle, transaction):
|
def remove_family(self, handle, transaction):
|
||||||
"""
|
"""
|
||||||
Remove the Family specified by the database handle from the
|
Remove the Family specified by the database handle from the
|
||||||
database, preserving the change in the passed transaction.
|
database, preserving the change in the passed transaction.
|
||||||
"""
|
"""
|
||||||
self._do_remove(handle, transaction, self.family_map,
|
self._do_remove(handle, transaction, FAMILY_KEY)
|
||||||
self.family_id_map, FAMILY_KEY)
|
|
||||||
|
|
||||||
def remove_repository(self, handle, transaction):
|
def remove_repository(self, handle, transaction):
|
||||||
"""
|
"""
|
||||||
Remove the Repository specified by the database handle from the
|
Remove the Repository specified by the database handle from the
|
||||||
database, preserving the change in the passed transaction.
|
database, preserving the change in the passed transaction.
|
||||||
"""
|
"""
|
||||||
self._do_remove(handle, transaction, self.repository_map,
|
self._do_remove(handle, transaction, REPOSITORY_KEY)
|
||||||
self.repository_id_map, REPOSITORY_KEY)
|
|
||||||
|
|
||||||
def remove_note(self, handle, transaction):
|
def remove_note(self, handle, transaction):
|
||||||
"""
|
"""
|
||||||
Remove the Note specified by the database handle from the
|
Remove the Note specified by the database handle from the
|
||||||
database, preserving the change in the passed transaction.
|
database, preserving the change in the passed transaction.
|
||||||
"""
|
"""
|
||||||
self._do_remove(handle, transaction, self.note_map,
|
self._do_remove(handle, transaction, NOTE_KEY)
|
||||||
self.note_id_map, NOTE_KEY)
|
|
||||||
|
|
||||||
def remove_tag(self, handle, transaction):
|
def remove_tag(self, handle, transaction):
|
||||||
"""
|
"""
|
||||||
Remove the Tag specified by the database handle from the
|
Remove the Tag specified by the database handle from the
|
||||||
database, preserving the change in the passed transaction.
|
database, preserving the change in the passed transaction.
|
||||||
"""
|
"""
|
||||||
self._do_remove(handle, transaction, self.tag_map,
|
self._do_remove(handle, transaction, TAG_KEY)
|
||||||
None, TAG_KEY)
|
|
||||||
|
|
||||||
def is_empty(self):
|
def is_empty(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1181,23 +1181,7 @@ class DBAPI(DbGeneric):
|
|||||||
ref_class_name])
|
ref_class_name])
|
||||||
# This function is followed by a commit.
|
# This function is followed by a commit.
|
||||||
|
|
||||||
def remove_person(self, handle, transaction):
|
def _do_remove(self, handle, transaction, obj_key):
|
||||||
"""
|
|
||||||
Remove the Person specified by the database handle from the database,
|
|
||||||
preserving the change in the passed transaction.
|
|
||||||
"""
|
|
||||||
if isinstance(handle, bytes):
|
|
||||||
handle = str(handle, "utf-8")
|
|
||||||
if self.readonly or not handle:
|
|
||||||
return
|
|
||||||
if handle in self.person_map:
|
|
||||||
person = Person.create(self.person_map[handle])
|
|
||||||
self.dbapi.execute("DELETE FROM person WHERE handle = ?;", [handle])
|
|
||||||
if not transaction.batch:
|
|
||||||
transaction.add(PERSON_KEY, TXNDEL, person.handle,
|
|
||||||
person.serialize(), None)
|
|
||||||
|
|
||||||
def _do_remove(self, handle, transaction, data_map, data_id_map, key):
|
|
||||||
if isinstance(handle, bytes):
|
if isinstance(handle, bytes):
|
||||||
handle = str(handle, "utf-8")
|
handle = str(handle, "utf-8")
|
||||||
key2table = {
|
key2table = {
|
||||||
@ -1214,13 +1198,12 @@ class DBAPI(DbGeneric):
|
|||||||
}
|
}
|
||||||
if self.readonly or not handle:
|
if self.readonly or not handle:
|
||||||
return
|
return
|
||||||
if handle in data_map:
|
if self.has_handle(obj_key, handle):
|
||||||
self.dbapi.execute(
|
sql = "DELETE FROM %s WHERE handle = ?;" % key2table[obj_key]
|
||||||
"DELETE FROM %s WHERE handle = ?;" % key2table[key],
|
self.dbapi.execute(sql, [handle])
|
||||||
[handle])
|
|
||||||
if not transaction.batch:
|
if not transaction.batch:
|
||||||
data = data_map[handle]
|
data = self.get_raw_data(obj_key, handle)
|
||||||
transaction.add(key, TXNDEL, handle, data, None)
|
transaction.add(obj_key, TXNDEL, handle, data, None)
|
||||||
|
|
||||||
def find_backlink_handles(self, handle, include_classes=None):
|
def find_backlink_handles(self, handle, include_classes=None):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user