9744: Tidy up has_*_handle methods
This commit is contained in:
parent
2f1f1f1b1e
commit
3149420f80
@ -1520,65 +1520,54 @@ class DBAPI(DbGeneric):
|
|||||||
[order_by, media.handle])
|
[order_by, media.handle])
|
||||||
row = self.dbapi.fetchone()
|
row = self.dbapi.fetchone()
|
||||||
|
|
||||||
def has_person_handle(self, key):
|
def has_handle(self, obj_key, handle):
|
||||||
if isinstance(key, bytes):
|
key2table = {
|
||||||
key = str(key, "utf-8")
|
PERSON_KEY: 'person',
|
||||||
self.dbapi.execute("SELECT 1 FROM person WHERE handle = ?", [key])
|
FAMILY_KEY: 'family',
|
||||||
return self.dbapi.fetchone() != None
|
SOURCE_KEY: 'source',
|
||||||
|
CITATION_KEY: 'citation',
|
||||||
|
EVENT_KEY: 'event',
|
||||||
|
MEDIA_KEY: 'media',
|
||||||
|
PLACE_KEY: 'place',
|
||||||
|
REPOSITORY_KEY: 'repository',
|
||||||
|
NOTE_KEY: 'note',
|
||||||
|
TAG_KEY: 'tag'
|
||||||
|
}
|
||||||
|
if isinstance(handle, bytes):
|
||||||
|
handle = str(handle, "utf-8")
|
||||||
|
sql = "SELECT 1 FROM %s WHERE handle = ?" % key2table[obj_key]
|
||||||
|
self.dbapi.execute(sql, [handle])
|
||||||
|
return self.dbapi.fetchone() is not None
|
||||||
|
|
||||||
def has_family_handle(self, key):
|
def has_person_handle(self, handle):
|
||||||
if isinstance(key, bytes):
|
return self.has_handle(PERSON_KEY, handle)
|
||||||
key = str(key, "utf-8")
|
|
||||||
self.dbapi.execute("SELECT 1 FROM family WHERE handle = ?", [key])
|
|
||||||
return self.dbapi.fetchone() != None
|
|
||||||
|
|
||||||
def has_source_handle(self, key):
|
def has_family_handle(self, handle):
|
||||||
if isinstance(key, bytes):
|
return self.has_handle(FAMILY_KEY, handle)
|
||||||
key = str(key, "utf-8")
|
|
||||||
self.dbapi.execute("SELECT 1 FROM source WHERE handle = ?", [key])
|
|
||||||
return self.dbapi.fetchone() != None
|
|
||||||
|
|
||||||
def has_citation_handle(self, key):
|
def has_source_handle(self, handle):
|
||||||
if isinstance(key, bytes):
|
return self.has_handle(SOURCE_KEY, handle)
|
||||||
key = str(key, "utf-8")
|
|
||||||
self.dbapi.execute("SELECT 1 FROM citation WHERE handle = ?", [key])
|
|
||||||
return self.dbapi.fetchone() != None
|
|
||||||
|
|
||||||
def has_event_handle(self, key):
|
def has_citation_handle(self, handle):
|
||||||
if isinstance(key, bytes):
|
return self.has_handle(CITATION_KEY, handle)
|
||||||
key = str(key, "utf-8")
|
|
||||||
self.dbapi.execute("SELECT 1 FROM event WHERE handle = ?", [key])
|
|
||||||
return self.dbapi.fetchone() != None
|
|
||||||
|
|
||||||
def has_media_handle(self, key):
|
def has_event_handle(self, handle):
|
||||||
if isinstance(key, bytes):
|
return self.has_handle(EVENT_KEY, handle)
|
||||||
key = str(key, "utf-8")
|
|
||||||
self.dbapi.execute("SELECT 1 FROM media WHERE handle = ?", [key])
|
|
||||||
return self.dbapi.fetchone() != None
|
|
||||||
|
|
||||||
def has_place_handle(self, key):
|
def has_media_handle(self, handle):
|
||||||
if isinstance(key, bytes):
|
return self.has_handle(MEDIA_KEY, handle)
|
||||||
key = str(key, "utf-8")
|
|
||||||
self.dbapi.execute("SELECT 1 FROM place WHERE handle = ?", [key])
|
|
||||||
return self.dbapi.fetchone() != None
|
|
||||||
|
|
||||||
def has_repository_handle(self, key):
|
def has_place_handle(self, handle):
|
||||||
if isinstance(key, bytes):
|
return self.has_handle(PLACE_KEY, handle)
|
||||||
key = str(key, "utf-8")
|
|
||||||
self.dbapi.execute("SELECT 1 FROM repository WHERE handle = ?", [key])
|
|
||||||
return self.dbapi.fetchone() != None
|
|
||||||
|
|
||||||
def has_note_handle(self, key):
|
def has_repository_handle(self, handle):
|
||||||
if isinstance(key, bytes):
|
return self.has_handle(REPOSITORY_KEY, handle)
|
||||||
key = str(key, "utf-8")
|
|
||||||
self.dbapi.execute("SELECT 1 FROM note WHERE handle = ?", [key])
|
|
||||||
return self.dbapi.fetchone() != None
|
|
||||||
|
|
||||||
def has_tag_handle(self, key):
|
def has_note_handle(self, handle):
|
||||||
if isinstance(key, bytes):
|
return self.has_handle(NOTE_KEY, handle)
|
||||||
key = str(key, "utf-8")
|
|
||||||
self.dbapi.execute("SELECT 1 FROM tag WHERE handle = ?", [key])
|
def has_tag_handle(self, handle):
|
||||||
return self.dbapi.fetchone() != None
|
return self.has_handle(TAG_KEY, handle)
|
||||||
|
|
||||||
def has_gramps_id(self, obj_key, gramps_id):
|
def has_gramps_id(self, obj_key, gramps_id):
|
||||||
key2table = {
|
key2table = {
|
||||||
|
Loading…
Reference in New Issue
Block a user