DB-API: get_family_handles(sort_handles=True) now fixed

This commit is contained in:
Doug Blank 2016-04-30 16:48:11 -04:00
parent 1c06a07156
commit 0a0a450b45

View File

@ -377,11 +377,21 @@ class DBAPI(DbGeneric):
If sort_handles is True, the list is sorted by surnames. If sort_handles is True, the list is sorted by surnames.
""" """
if sort_handles: if sort_handles:
self.dbapi.execute("""SELECT DISTINCT family.handle FROM family self.dbapi.execute("""SELECT f.handle FROM
JOIN person (SELECT family.*
ON family.father_handle = person.handle FROM family LEFT JOIN
ORDER BY person.primary_name__surname_list__0__surname, person AS father
person.primary_name__first_name;""") ON family.father_handle = father.handle LEFT JOIN
person AS mother
on family.mother_handle = mother.handle
order by (case when father.handle is null
then mother.primary_name__surname_list__0__surname
else father.primary_name__surname_list__0__surname
end),
(case when family.handle is null
then mother.primary_name__first_name
else father.primary_name__first_name
end)) AS f;""")
else: else:
self.dbapi.execute("SELECT handle FROM family;") self.dbapi.execute("SELECT handle FROM family;")
rows = self.dbapi.fetchall() rows = self.dbapi.fetchall()
@ -627,7 +637,7 @@ class DBAPI(DbGeneric):
emit = "family-add" emit = "family-add"
self.dbapi.execute("""INSERT INTO family (handle, gramps_id, father_handle, mother_handle, blob_data) self.dbapi.execute("""INSERT INTO family (handle, gramps_id, father_handle, mother_handle, blob_data)
VALUES(?, ?, ?, ?, ?);""", VALUES(?, ?, ?, ?, ?);""",
[family.handle, [family.handle,
family.gramps_id, family.gramps_id,
family.father_handle, family.father_handle,
family.mother_handle, family.mother_handle,
@ -1112,7 +1122,7 @@ class DBAPI(DbGeneric):
if order_by is None: if order_by is None:
query = "SELECT blob_data FROM %s;" % class_.__name__.lower() query = "SELECT blob_data FROM %s;" % class_.__name__.lower()
else: else:
order_phrases = ["%s %s" % (self._hash_name(class_.__name__, class_.get_field_alias(field)), direction) order_phrases = ["%s %s" % (self._hash_name(class_.__name__, class_.get_field_alias(field)), direction)
for (field, direction) in order_by] for (field, direction) in order_by]
query = "SELECT blob_data FROM %s ORDER BY %s;" % (class_.__name__.lower(), ", ".join(order_phrases)) query = "SELECT blob_data FROM %s ORDER BY %s;" % (class_.__name__.lower(), ", ".join(order_phrases))
self.dbapi.execute(query) self.dbapi.execute(query)
@ -1617,7 +1627,7 @@ class DBAPI(DbGeneric):
# do a select on all; if it works, then it is ok; else, check them all # do a select on all; if it works, then it is ok; else, check them all
table_name = table.lower() table_name = table.lower()
try: try:
fields = [self._hash_name(table, field) for (field, ptype) in fields = [self._hash_name(table, field) for (field, ptype) in
self.get_table_func(table,"class_func").get_secondary_fields()] self.get_table_func(table,"class_func").get_secondary_fields()]
if fields: if fields:
self.dbapi.execute("select %s from %s limit 1;" % (", ".join(fields), table_name)) self.dbapi.execute("select %s from %s limit 1;" % (", ".join(fields), table_name))
@ -1759,7 +1769,7 @@ class DBAPI(DbGeneric):
order_by - [(field, "ASC" | "DESC"), ...] order_by - [(field, "ASC" | "DESC"), ...]
""" """
if order_by: if order_by:
order_clause = ", ".join(["%s %s" % (self._hash_name(table, field), dir) order_clause = ", ".join(["%s %s" % (self._hash_name(table, field), dir)
for (field, dir) in order_by]) for (field, dir) in order_by])
return "ORDER BY " + order_clause return "ORDER BY " + order_clause
else: else:
@ -1830,8 +1840,8 @@ class DBAPI(DbGeneric):
["NOT", where] ["NOT", where]
order_by - [[fieldname, "ASC" | "DESC"], ...] order_by - [[fieldname, "ASC" | "DESC"], ...]
""" """
secondary_fields = ([self._hash_name(table, field) for (field, ptype) in secondary_fields = ([self._hash_name(table, field) for (field, ptype) in
self.get_table_func(table,"class_func").get_secondary_fields()] + self.get_table_func(table,"class_func").get_secondary_fields()] +
["handle"]) # handle is a sql field, but not listed in secondaries ["handle"]) # handle is a sql field, but not listed in secondaries
# If no fields, then we need objects: # If no fields, then we need objects:
# Check to see if where matches SQL fields: # Check to see if where matches SQL fields: