add sorted family handles to DB-API
This commit is contained in:
parent
7dc9379909
commit
6b86b154fb
@ -86,6 +86,8 @@ class DBAPI(DbGeneric):
|
|||||||
);""")
|
);""")
|
||||||
self.dbapi.try_execute("""CREATE TABLE family (
|
self.dbapi.try_execute("""CREATE TABLE family (
|
||||||
handle VARCHAR(50) PRIMARY KEY NOT NULL,
|
handle VARCHAR(50) PRIMARY KEY NOT NULL,
|
||||||
|
father_handle VARCHAR(50),
|
||||||
|
mother_handle VARCHAR(50),
|
||||||
gramps_id TEXT ,
|
gramps_id TEXT ,
|
||||||
blob_data BLOB
|
blob_data BLOB
|
||||||
);""")
|
);""")
|
||||||
@ -331,6 +333,10 @@ class DBAPI(DbGeneric):
|
|||||||
|
|
||||||
def get_person_handles(self, sort_handles=False):
|
def get_person_handles(self, sort_handles=False):
|
||||||
"""
|
"""
|
||||||
|
Return a list of database handles, one handle for each Person in
|
||||||
|
the database.
|
||||||
|
|
||||||
|
If sort_handles is True, the list is sorted by surnames.
|
||||||
"""
|
"""
|
||||||
if sort_handles:
|
if sort_handles:
|
||||||
self.dbapi.execute("SELECT handle FROM person ORDER BY order_by;")
|
self.dbapi.execute("SELECT handle FROM person ORDER BY order_by;")
|
||||||
@ -339,8 +345,21 @@ class DBAPI(DbGeneric):
|
|||||||
rows = self.dbapi.fetchall()
|
rows = self.dbapi.fetchall()
|
||||||
return [bytes(row[0], "utf-8") for row in rows]
|
return [bytes(row[0], "utf-8") for row in rows]
|
||||||
|
|
||||||
def get_family_handles(self):
|
def get_family_handles(self, sort_handles=False):
|
||||||
self.dbapi.execute("SELECT handle FROM family;")
|
"""
|
||||||
|
Return a list of database handles, one handle for each Family in
|
||||||
|
the database.
|
||||||
|
|
||||||
|
If sort_handles is True, the list is sorted by surnames.
|
||||||
|
"""
|
||||||
|
if sort_handles:
|
||||||
|
self.dbapi.execute("""SELECT DISTINCT family.handle FROM family
|
||||||
|
JOIN person
|
||||||
|
ON (family.father_handle = person.handle OR
|
||||||
|
family.mother_handle = person.handle)
|
||||||
|
ORDER BY person.primary_name__surname_list__0__surname;""")
|
||||||
|
else:
|
||||||
|
self.dbapi.execute("SELECT handle FROM family;")
|
||||||
rows = self.dbapi.fetchall()
|
rows = self.dbapi.fetchall()
|
||||||
return [bytes(row[0], "utf-8") for row in rows]
|
return [bytes(row[0], "utf-8") for row in rows]
|
||||||
|
|
||||||
@ -573,16 +592,23 @@ class DBAPI(DbGeneric):
|
|||||||
emit = "family-update"
|
emit = "family-update"
|
||||||
old_family = self.get_family_from_handle(family.handle).serialize()
|
old_family = self.get_family_from_handle(family.handle).serialize()
|
||||||
self.dbapi.execute("""UPDATE family SET gramps_id = ?,
|
self.dbapi.execute("""UPDATE family SET gramps_id = ?,
|
||||||
|
father_handle = ?,
|
||||||
|
mother_handle = ?,
|
||||||
blob_data = ?
|
blob_data = ?
|
||||||
WHERE handle = ?;""",
|
WHERE handle = ?;""",
|
||||||
[family.gramps_id,
|
[family.gramps_id,
|
||||||
|
family.father_handle,
|
||||||
|
family.mother_handle,
|
||||||
pickle.dumps(family.serialize()),
|
pickle.dumps(family.serialize()),
|
||||||
family.handle])
|
family.handle])
|
||||||
else:
|
else:
|
||||||
emit = "family-add"
|
emit = "family-add"
|
||||||
self.dbapi.execute("""INSERT INTO family (handle, gramps_id, blob_data)
|
self.dbapi.execute("""INSERT INTO family (handle, gramps_id, father_handle, mother_handle, blob_data)
|
||||||
VALUES(?, ?, ?);""",
|
VALUES(?, ?, ?, ?, ?);""",
|
||||||
[family.handle, family.gramps_id,
|
[family.handle,
|
||||||
|
family.gramps_id,
|
||||||
|
family.father_handle,
|
||||||
|
family.mother_handle,
|
||||||
pickle.dumps(family.serialize())])
|
pickle.dumps(family.serialize())])
|
||||||
self.update_secondary_values(family)
|
self.update_secondary_values(family)
|
||||||
if not trans.batch:
|
if not trans.batch:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user