From 7b183fc79cc41e4bf78d3eaacc9380402148ea56 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Sun, 16 Oct 2016 19:35:19 +0100 Subject: [PATCH] 9742: Rewrite get_*_gramps_ids methods Use get_gramps_ids rather than table maps. --- gramps/gen/db/generic.py | 14 --------- gramps/plugins/db/dbapi/dbapi.py | 51 ++++++++++++++++---------------- 2 files changed, 25 insertions(+), 40 deletions(-) diff --git a/gramps/gen/db/generic.py b/gramps/gen/db/generic.py index 419321dc4..feac6b014 100644 --- a/gramps/gen/db/generic.py +++ b/gramps/gen/db/generic.py @@ -1544,20 +1544,6 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback): if name in self.surname_list: self.surname_list.remove(name) - def get_gramps_ids(self, obj_key): - key2table = { - PERSON_KEY: self.person_id_map, - FAMILY_KEY: self.family_id_map, - CITATION_KEY: self.citation_id_map, - SOURCE_KEY: self.source_id_map, - EVENT_KEY: self.event_id_map, - MEDIA_KEY: self.media_id_map, - PLACE_KEY: self.place_id_map, - REPOSITORY_KEY: self.repository_id_map, - NOTE_KEY: self.note_id_map, - } - return list(key2table[obj_key].keys()) - def set_researcher(self, owner): self.owner.set_from(owner) diff --git a/gramps/plugins/db/dbapi/dbapi.py b/gramps/plugins/db/dbapi/dbapi.py index 3832e65be..a88f4b4e6 100644 --- a/gramps/plugins/db/dbapi/dbapi.py +++ b/gramps/plugins/db/dbapi/dbapi.py @@ -1623,50 +1623,49 @@ class DBAPI(DbGeneric): def has_note_gramps_id(self, gramps_id): return self.has_gramps_id(NOTE_KEY, gramps_id) - def get_person_gramps_ids(self): - self.dbapi.execute("SELECT gramps_id FROM person;") + def get_gramps_ids(self, obj_key): + key2table = { + PERSON_KEY: 'person', + FAMILY_KEY: 'family', + SOURCE_KEY: 'source', + CITATION_KEY: 'citation', + EVENT_KEY: 'event', + MEDIA_KEY: 'media', + PLACE_KEY: 'place', + REPOSITORY_KEY: 'repository', + NOTE_KEY: 'note', + } + sql = "SELECT gramps_id FROM %s;" % key2table[obj_key] + self.dbapi.execute(sql) rows = self.dbapi.fetchall() return [row[0] for row in rows] + def get_person_gramps_ids(self): + return self.get_gramps_ids(PERSON_KEY) + def get_family_gramps_ids(self): - self.dbapi.execute("SELECT gramps_id FROM family;") - rows = self.dbapi.fetchall() - return [row[0] for row in rows] + return self.get_gramps_ids(FAMILY_KEY) def get_source_gramps_ids(self): - self.dbapi.execute("SELECT gramps_id FROM source;") - rows = self.dbapi.fetchall() - return [row[0] for row in rows] + return self.get_gramps_ids(SOURCE_KEY) def get_citation_gramps_ids(self): - self.dbapi.execute("SELECT gramps_id FROM citation;") - rows = self.dbapi.fetchall() - return [row[0] for row in rows] + return self.get_gramps_ids(CITATION_KEY) def get_event_gramps_ids(self): - self.dbapi.execute("SELECT gramps_id FROM event;") - rows = self.dbapi.fetchall() - return [row[0] for row in rows] + return self.get_gramps_ids(EVENT_KEY) def get_media_gramps_ids(self): - self.dbapi.execute("SELECT gramps_id FROM media;") - rows = self.dbapi.fetchall() - return [row[0] for row in rows] + return self.get_gramps_ids(MEDIA_KEY) def get_place_gramps_ids(self): - self.dbapi.execute("SELECT gramps FROM place;") - rows = self.dbapi.fetchall() - return [row[0] for row in rows] + return self.get_gramps_ids(PLACE_KEY) def get_repository_gramps_ids(self): - self.dbapi.execute("SELECT gramps_id FROM repository;") - rows = self.dbapi.fetchall() - return [row[0] for row in rows] + return self.get_gramps_ids(REPOSITORY_KEY) def get_note_gramps_ids(self): - self.dbapi.execute("SELECT gramps_id FROM note;") - rows = self.dbapi.fetchall() - return [row[0] for row in rows] + return self.get_gramps_ids(NOTE_KEY) def get_raw_person_data(self, key): if isinstance(key, bytes):