From ce59a8a5c9e1fb35d296106226291115de137b7e Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Wed, 19 Oct 2016 22:18:25 +0100 Subject: [PATCH] 9744: Tidy up get_number_of_* methods --- gramps/plugins/db/dbapi/dbapi.py | 47 ++++++++++++-------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/gramps/plugins/db/dbapi/dbapi.py b/gramps/plugins/db/dbapi/dbapi.py index 5661a878b..4c28811b9 100644 --- a/gramps/plugins/db/dbapi/dbapi.py +++ b/gramps/plugins/db/dbapi/dbapi.py @@ -609,85 +609,72 @@ class DBAPI(DbGeneric): return self.get_tag_from_handle(row[0]) return None + def get_number_of(self, obj_key): + table = KEY_TO_NAME_MAP[obj_key] + sql = "SELECT count(1) FROM %s;" % table + self.dbapi.execute(sql) + row = self.dbapi.fetchone() + return row[0] + def get_number_of_people(self): """ Return the number of people currently in the database. """ - self.dbapi.execute("SELECT count(1) FROM person;") - row = self.dbapi.fetchone() - return row[0] + return self.get_number_of(PERSON_KEY) def get_number_of_events(self): """ Return the number of events currently in the database. """ - self.dbapi.execute("SELECT count(1) FROM event;") - row = self.dbapi.fetchone() - return row[0] + return self.get_number_of(EVENT_KEY) def get_number_of_places(self): """ Return the number of places currently in the database. """ - self.dbapi.execute("SELECT count(1) FROM place;") - row = self.dbapi.fetchone() - return row[0] + return self.get_number_of(PLACE_KEY) def get_number_of_tags(self): """ Return the number of tags currently in the database. """ - self.dbapi.execute("SELECT count(1) FROM tag;") - row = self.dbapi.fetchone() - return row[0] + return self.get_number_of(TAG_KEY) def get_number_of_families(self): """ Return the number of families currently in the database. """ - self.dbapi.execute("SELECT count(1) FROM family;") - row = self.dbapi.fetchone() - return row[0] + return self.get_number_of(FAMILY_KEY) def get_number_of_notes(self): """ Return the number of notes currently in the database. """ - self.dbapi.execute("SELECT count(1) FROM note;") - row = self.dbapi.fetchone() - return row[0] + return self.get_number_of(NOTE_KEY) def get_number_of_citations(self): """ Return the number of citations currently in the database. """ - self.dbapi.execute("SELECT count(1) FROM citation;") - row = self.dbapi.fetchone() - return row[0] + return self.get_number_of(CITATION_KEY) def get_number_of_sources(self): """ Return the number of sources currently in the database. """ - self.dbapi.execute("SELECT count(1) FROM source;") - row = self.dbapi.fetchone() - return row[0] + return self.get_number_of(SOURCE_KEY) def get_number_of_media(self): """ Return the number of media objects currently in the database. """ - self.dbapi.execute("SELECT count(1) FROM media;") - row = self.dbapi.fetchone() - return row[0] + return self.get_number_of(MEDIA_KEY) def get_number_of_repositories(self): """ Return the number of source repositories currently in the database. """ - self.dbapi.execute("SELECT count(1) FROM repository;") - row = self.dbapi.fetchone() - return row[0] + return self.get_number_of(REPOSITORY_KEY) def has_name_group_key(self, key): """