DB-API: sql clean up; some FIXME's still left

This commit is contained in:
Doug Blank 2015-05-25 22:31:36 -04:00
parent dce0b82155
commit 3cbc012f6f

View File

@ -10,6 +10,7 @@ import re
import os import os
import logging import logging
import shutil import shutil
import bisect
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -865,12 +866,12 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.emit('home-person-changed') self.emit('home-person-changed')
def get_name_group_keys(self): def get_name_group_keys(self):
cur = self.dbapi.execute("select name from name_group order by name;") cur = self.dbapi.execute("SELECT name FROM name_group ORDER BY name;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_name_group_mapping(self, key): def get_name_group_mapping(self, key):
cur = self.dbapi.execute("select grouping from name_group where name = ?;", cur = self.dbapi.execute("SELECT grouping FROM name_group WHERE name = ?;",
[key]) [key])
row = cur.fetchone() row = cur.fetchone()
if row: if row:
@ -885,62 +886,62 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return [row[0] for row in rows] return [row[0] for row in rows]
def get_family_handles(self): def get_family_handles(self):
cur = self.dbapi.execute("select handle from family;") cur = self.dbapi.execute("SELECT handle FROM family;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_event_handles(self): def get_event_handles(self):
cur = self.dbapi.execute("select handle from event;") cur = self.dbapi.execute("SELECT handle FROM event;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_citation_handles(self, sort_handles=False): def get_citation_handles(self, sort_handles=False):
if sort_handles: if sort_handles:
cur = self.dbapi.execute("select handle from citation ORDER BY order_by;") cur = self.dbapi.execute("SELECT handle FROM citation ORDER BY order_by;")
else: else:
cur = self.dbapi.execute("select handle from citation;") cur = self.dbapi.execute("SELECT handle FROM citation;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_source_handles(self, sort_handles=False): def get_source_handles(self, sort_handles=False):
if sort_handles: if sort_handles:
cur = self.dbapi.execute("select handle from source ORDER BY order_by;") cur = self.dbapi.execute("SELECT handle FROM source ORDER BY order_by;")
else: else:
cur = self.dbapi.execute("select handle from source;") cur = self.dbapi.execute("SELECT handle from source;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_place_handles(self, sort_handles=False): def get_place_handles(self, sort_handles=False):
if sort_handles: if sort_handles:
cur = self.dbapi.execute("select handle from place ORDER BY order_by;") cur = self.dbapi.execute("SELECT handle FROM place ORDER BY order_by;")
else: else:
cur = self.dbapi.execute("select handle from place;") cur = self.dbapi.execute("SELECT handle FROM place;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_repository_handles(self): def get_repository_handles(self):
cur = self.dbapi.execute("select handle from repository;") cur = self.dbapi.execute("SELECT handle FROM repository;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_media_object_handles(self, sort_handles=False): def get_media_object_handles(self, sort_handles=False):
if sort_handles: if sort_handles:
cur = self.dbapi.execute("select handle from media ORDER BY order_by;") cur = self.dbapi.execute("SELECT handle FROM media ORDER BY order_by;")
else: else:
cur = self.dbapi.execute("select handle from media;") cur = self.dbapi.execute("SELECT handle FROM media;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_note_handles(self): def get_note_handles(self):
cur = self.dbapi.execute("select handle from note;") cur = self.dbapi.execute("SELECT handle FROM note;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_tag_handles(self, sort_handles=False): def get_tag_handles(self, sort_handles=False):
if sort_handles: if sort_handles:
cur = self.dbapi.execute("select handle from tag ORDER BY order_by;") cur = self.dbapi.execute("SELECT handle FROM tag ORDER BY order_by;")
else: else:
cur = self.dbapi.execute("select handle from tag;") cur = self.dbapi.execute("SELECT handle FROM tag;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
@ -1097,52 +1098,52 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return None return None
def get_number_of_people(self): def get_number_of_people(self):
cur = self.dbapi.execute("select count(handle) from person;") cur = self.dbapi.execute("SELECT count(handle) FROM person;")
row = cur.fetchone() row = cur.fetchone()
return row[0] return row[0]
def get_number_of_events(self): def get_number_of_events(self):
cur = self.dbapi.execute("select count(handle) from event;") cur = self.dbapi.execute("SELECT count(handle) FROM event;")
row = cur.fetchone() row = cur.fetchone()
return row[0] return row[0]
def get_number_of_places(self): def get_number_of_places(self):
cur = self.dbapi.execute("select count(handle) from place;") cur = self.dbapi.execute("SELECT count(handle) FROM place;")
row = cur.fetchone() row = cur.fetchone()
return row[0] return row[0]
def get_number_of_tags(self): def get_number_of_tags(self):
cur = self.dbapi.execute("select count(handle) from tag;") cur = self.dbapi.execute("SELECT count(handle) FROM tag;")
row = cur.fetchone() row = cur.fetchone()
return row[0] return row[0]
def get_number_of_families(self): def get_number_of_families(self):
cur = self.dbapi.execute("select count(handle) from family;") cur = self.dbapi.execute("SELECT count(handle) FROM family;")
row = cur.fetchone() row = cur.fetchone()
return row[0] return row[0]
def get_number_of_notes(self): def get_number_of_notes(self):
cur = self.dbapi.execute("select count(handle) from note;") cur = self.dbapi.execute("SELECT count(handle) FROM note;")
row = cur.fetchone() row = cur.fetchone()
return row[0] return row[0]
def get_number_of_citations(self): def get_number_of_citations(self):
cur = self.dbapi.execute("select count(handle) from citation;") cur = self.dbapi.execute("SELECT count(handle) FROM citation;")
row = cur.fetchone() row = cur.fetchone()
return row[0] return row[0]
def get_number_of_sources(self): def get_number_of_sources(self):
cur = self.dbapi.execute("select count(handle) from source;") cur = self.dbapi.execute("SELECT count(handle) FROM source;")
row = cur.fetchone() row = cur.fetchone()
return row[0] return row[0]
def get_number_of_media_objects(self): def get_number_of_media_objects(self):
cur = self.dbapi.execute("select count(handle) from media;") cur = self.dbapi.execute("SELECT count(handle) FROM media;")
row = cur.fetchone() row = cur.fetchone()
return row[0] return row[0]
def get_number_of_repositories(self): def get_number_of_repositories(self):
cur = self.dbapi.execute("select count(handle) from repository;") cur = self.dbapi.execute("SELECT count(handle) FROM repository;")
row = cur.fetchone() row = cur.fetchone()
return row[0] return row[0]
@ -1221,20 +1222,20 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return handle in self.media_map return handle in self.media_map
def has_name_group_key(self, key): def has_name_group_key(self, key):
cur = self.dbapi.execute("select grouping from name_group where name = ?;", cur = self.dbapi.execute("SELECT grouping FROM name_group WHERE name = ?;",
[key]) [key])
row = cur.fetchone() row = cur.fetchone()
return True if row else False return True if row else False
def set_name_group_mapping(self, name, grouping): def set_name_group_mapping(self, name, grouping):
sname = name.encode("utf-8") sname = name.encode("utf-8")
cur = self.dbapi.execute("SELECT * from name_group where name = ?;", cur = self.dbapi.execute("SELECT * FROM name_group WHERE name = ?;",
[sname]) [sname])
row = cur.fetchone() row = cur.fetchone()
if row: if row:
cur = self.dbapi.execute("DELETE from name_group where name = ?;", cur = self.dbapi.execute("DELETE FROM name_group WHERE name = ?;",
[sname]) [sname])
cur = self.dbapi.execute("INSERT into name_group (name, grouping) VALUES(?, ?);", cur = self.dbapi.execute("INSERT INTO name_group (name, grouping) VALUES(?, ?);",
[sname, grouping]) [sname, grouping])
self.dbapi.commit() self.dbapi.commit()
@ -1403,15 +1404,15 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.genderStats.count_person(person) self.genderStats.count_person(person)
self.add_to_surname_list(person, trans.batch) self.add_to_surname_list(person, trans.batch)
# Insert the person: # Insert the person:
self.dbapi.execute("""insert into person (handle, order_by, gramps_id, blob) self.dbapi.execute("""INSERT INTO person (handle, order_by, gramps_id, blob)
values(?, ?, ?, ?);""", VALUES(?, ?, ?, ?);""",
[person.handle, [person.handle,
self._order_by_person_key(person), self._order_by_person_key(person),
person.gramps_id, person.gramps_id,
pickle.dumps(person.serialize())]) pickle.dumps(person.serialize())])
if not trans.batch: if not trans.batch:
self.dbapi.commit()
self.update_backlinks(person) self.update_backlinks(person)
self.dbapi.commit()
# Other misc update tasks: # Other misc update tasks:
self.individual_attributes.update( self.individual_attributes.update(
[str(attr.type) for attr in person.attribute_list [str(attr.type) for attr in person.attribute_list
@ -1450,13 +1451,21 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
""" """
if batch_transaction: if batch_transaction:
return return
#name = self._order_by_person_key(person) # TODO: check to see if this is correct
#i = bisect.bisect(self.surname_list, name) name = None
#if 0 < i <= len(self.surname_list): primary_name = person.get_primary_name()
# if self.surname_list[i-1] != name: if primary_name:
# self.surname_list.insert(i, name) surname_list = primary_name.get_surname_list()
#else: if len(surname_list) > 0:
# self.surname_list.insert(i, name) name = surname_list[0].surname
if name is None:
return
i = bisect.bisect(self.surname_list, name)
if 0 < i <= len(self.surname_list):
if self.surname_list[i-1] != name:
self.surname_list.insert(i, name)
else:
self.surname_list.insert(i, name)
def remove_from_surname_list(self, person): def remove_from_surname_list(self, person):
""" """
@ -1466,13 +1475,16 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
If not then we need to remove the name from the list. If not then we need to remove the name from the list.
The function must be overridden in the derived class. The function must be overridden in the derived class.
""" """
name = self._order_by_person_key(person) name = None
#if isinstance(name, str): primary_name = person.get_primary_name()
# uname = name if primary_name:
# name = name.encode('utf-8') surname_list = primary_name.get_surname_list()
#else: if len(surname_list) > 0:
# uname = str(name) name = surname_list[0].surname
# FIXME: check database if name is None:
return
if name in self.surname_list:
self.surname_list.remove(name)
def commit_family(self, family, trans, change_time=None): def commit_family(self, family, trans, change_time=None):
emit = None emit = None
@ -1486,13 +1498,13 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
family.handle]) family.handle])
else: else:
emit = "family-add" emit = "family-add"
self.dbapi.execute("""insert into family (handle, gramps_id, blob) self.dbapi.execute("""INSERT INTO family (handle, gramps_id, blob)
values(?, ?, ?);""", VALUES(?, ?, ?);""",
[family.handle, family.gramps_id, [family.handle, family.gramps_id,
pickle.dumps(family.serialize())]) pickle.dumps(family.serialize())])
if not trans.batch: if not trans.batch:
self.dbapi.commit()
self.update_backlinks(family) self.update_backlinks(family)
self.dbapi.commit()
# Misc updates: # Misc updates:
self.family_attributes.update( self.family_attributes.update(
[str(attr.type) for attr in family.attribute_list [str(attr.type) for attr in family.attribute_list
@ -1537,15 +1549,15 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
citation.handle]) citation.handle])
else: else:
emit = "citation-add" emit = "citation-add"
self.dbapi.execute("""insert into citation (handle, order_by, gramps_id, blob) self.dbapi.execute("""INSERT INTO citation (handle, order_by, gramps_id, blob)
values(?, ?, ?, ?);""", VALUES(?, ?, ?, ?);""",
[citation.handle, [citation.handle,
self._order_by_citation_key(citation), self._order_by_citation_key(citation),
citation.gramps_id, citation.gramps_id,
pickle.dumps(citation.serialize())]) pickle.dumps(citation.serialize())])
if not trans.batch: if not trans.batch:
self.dbapi.commit()
self.update_backlinks(citation) self.update_backlinks(citation)
self.dbapi.commit()
# Misc updates: # Misc updates:
attr_list = [] attr_list = []
for mref in citation.media_list: for mref in citation.media_list:
@ -1576,15 +1588,15 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
source.handle]) source.handle])
else: else:
emit = "source-add" emit = "source-add"
self.dbapi.execute("""insert into source (handle, order_by, gramps_id, blob) self.dbapi.execute("""INSERT INTO source (handle, order_by, gramps_id, blob)
values(?, ?, ?, ?);""", VALUES(?, ?, ?, ?);""",
[source.handle, [source.handle,
self._order_by_source_key(source), self._order_by_source_key(source),
source.gramps_id, source.gramps_id,
pickle.dumps(source.serialize())]) pickle.dumps(source.serialize())])
if not trans.batch: if not trans.batch:
self.dbapi.commit()
self.update_backlinks(source) self.update_backlinks(source)
self.dbapi.commit()
# Misc updates: # Misc updates:
self.source_media_types.update( self.source_media_types.update(
[str(ref.media_type) for ref in source.reporef_list [str(ref.media_type) for ref in source.reporef_list
@ -1615,12 +1627,12 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
repository.handle]) repository.handle])
else: else:
emit = "repository-add" emit = "repository-add"
self.dbapi.execute("""insert into repository (handle, gramps_id, blob) self.dbapi.execute("""INSERT INTO repository (handle, gramps_id, blob)
values(?, ?, ?);""", VALUES(?, ?, ?);""",
[repository.handle, repository.gramps_id, pickle.dumps(repository.serialize())]) [repository.handle, repository.gramps_id, pickle.dumps(repository.serialize())])
if not trans.batch: if not trans.batch:
self.dbapi.commit()
self.update_backlinks(repository) self.update_backlinks(repository)
self.dbapi.commit()
# Misc updates: # Misc updates:
if repository.type.is_custom(): if repository.type.is_custom():
self.repository_types.add(str(repository.type)) self.repository_types.add(str(repository.type))
@ -1644,12 +1656,12 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
note.handle]) note.handle])
else: else:
emit = "note-add" emit = "note-add"
self.dbapi.execute("""insert into note (handle, gramps_id, blob) self.dbapi.execute("""INSERT INTO note (handle, gramps_id, blob)
values(?, ?, ?);""", VALUES(?, ?, ?);""",
[note.handle, note.gramps_id, pickle.dumps(note.serialize())]) [note.handle, note.gramps_id, pickle.dumps(note.serialize())])
if not trans.batch: if not trans.batch:
self.dbapi.commit()
self.update_backlinks(note) self.update_backlinks(note)
self.dbapi.commit()
# Misc updates: # Misc updates:
if note.type.is_custom(): if note.type.is_custom():
self.note_types.add(str(note.type)) self.note_types.add(str(note.type))
@ -1672,15 +1684,15 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
place.handle]) place.handle])
else: else:
emit = "place-add" emit = "place-add"
self.dbapi.execute("""insert into place (handle, order_by, gramps_id, blob) self.dbapi.execute("""INSERT INTO place (handle, order_by, gramps_id, blob)
values(?, ?, ?, ?);""", VALUES(?, ?, ?, ?);""",
[place.handle, [place.handle,
self._order_by_place_key(place), self._order_by_place_key(place),
place.gramps_id, place.gramps_id,
pickle.dumps(place.serialize())]) pickle.dumps(place.serialize())])
if not trans.batch: if not trans.batch:
self.dbapi.commit()
self.update_backlinks(place) self.update_backlinks(place)
self.dbapi.commit()
# Misc updates: # Misc updates:
if place.get_type().is_custom(): if place.get_type().is_custom():
self.place_types.add(str(place.get_type())) self.place_types.add(str(place.get_type()))
@ -1710,14 +1722,14 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
event.handle]) event.handle])
else: else:
emit = "event-add" emit = "event-add"
self.dbapi.execute("""insert into event (handle, gramps_id, blob) self.dbapi.execute("""INSERT INTO event (handle, gramps_id, blob)
values(?, ?, ?);""", VALUES(?, ?, ?);""",
[event.handle, [event.handle,
event.gramps_id, event.gramps_id,
pickle.dumps(event.serialize())]) pickle.dumps(event.serialize())])
if not trans.batch: if not trans.batch:
self.dbapi.commit()
self.update_backlinks(event) self.update_backlinks(event)
self.dbapi.commit()
# Misc updates: # Misc updates:
self.event_attributes.update( self.event_attributes.update(
[str(attr.type) for attr in event.attribute_list [str(attr.type) for attr in event.attribute_list
@ -1736,27 +1748,19 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def update_backlinks(self, obj): def update_backlinks(self, obj):
# First, delete the current references: # First, delete the current references:
self.dbapi.execute("DELETE FROM reference where obj_handle = ?;", self.dbapi.execute("DELETE FROM reference WHERE obj_handle = ?;",
[obj.handle]) [obj.handle])
# Now, add the current ones: # Now, add the current ones:
references = set(obj.get_referenced_handles_recursively()) references = set(obj.get_referenced_handles_recursively())
for (ref_class_name, ref_handle) in references: for (ref_class_name, ref_handle) in references:
self.dbapi.execute("""INSERT into reference self.dbapi.execute("""INSERT INTO reference
(obj_handle, obj_class, ref_handle, ref_class) (obj_handle, obj_class, ref_handle, ref_class)
VALUES(?, ?, ?, ?);""", VALUES(?, ?, ?, ?);""",
[obj.handle, [obj.handle,
obj.__class__.__name__, obj.__class__.__name__,
ref_handle, ref_handle,
ref_class_name]) ref_class_name])
# Will commit later # This function is followed by a commit.
def update_event_attributes(self, attr_list):
# FIXME
pass
def update_event_names(self, event_type):
# FIXME
pass
def commit_tag(self, tag, trans, change_time=None): def commit_tag(self, tag, trans, change_time=None):
emit = None emit = None
@ -1770,14 +1774,14 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
tag.handle]) tag.handle])
else: else:
emit = "tag-add" emit = "tag-add"
self.dbapi.execute("""insert into tag (handle, order_by, blob) self.dbapi.execute("""INSERT INTO tag (handle, order_by, blob)
values(?, ?, ?);""", VALUES(?, ?, ?);""",
[tag.handle, [tag.handle,
self._order_by_tag_key(tag), self._order_by_tag_key(tag),
pickle.dumps(tag.serialize())]) pickle.dumps(tag.serialize())])
if not trans.batch: if not trans.batch:
self.dbapi.commit()
self.update_backlinks(tag) self.update_backlinks(tag)
self.dbapi.commit()
# Emit after added: # Emit after added:
if emit: if emit:
self.emit(emit, ([tag.handle],)) self.emit(emit, ([tag.handle],))
@ -1796,15 +1800,15 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
media.handle]) media.handle])
else: else:
emit = "media-add" emit = "media-add"
self.dbapi.execute("""insert into media (handle, order_by, gramps_id, blob) self.dbapi.execute("""INSERT INTO media (handle, order_by, gramps_id, blob)
values(?, ?, ?, ?);""", VALUES(?, ?, ?, ?);""",
[media.handle, [media.handle,
self._order_by_media_key(media), self._order_by_media_key(media),
media.gramps_id, media.gramps_id,
pickle.dumps(media.serialize())]) pickle.dumps(media.serialize())])
if not trans.batch: if not trans.batch:
self.dbapi.commit()
self.update_backlinks(media) self.update_backlinks(media)
self.dbapi.commit()
# Misc updates: # Misc updates:
self.media_attributes.update( self.media_attributes.update(
[str(attr.type) for attr in media.attribute_list [str(attr.type) for attr in media.attribute_list
@ -1910,7 +1914,7 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
person = Person.create(self.person_map[handle]) person = Person.create(self.person_map[handle])
#del self.person_map[handle] #del self.person_map[handle]
#del self.person_id_map[person.gramps_id] #del self.person_id_map[person.gramps_id]
self.dbapi.execute("DELETE from person WHERE handle = ?;", [handle]) self.dbapi.execute("DELETE FROM person WHERE handle = ?;", [handle])
self.emit("person-delete", ([handle],)) self.emit("person-delete", ([handle],))
if not transaction.batch: if not transaction.batch:
self.dbapi.commit() self.dbapi.commit()
@ -2011,7 +2015,7 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
if self.readonly or not handle: if self.readonly or not handle:
return return
if handle in data_map: if handle in data_map:
self.dbapi.execute("DELETE from %s WHERE handle = ?;" % key2table[key], self.dbapi.execute("DELETE FROM %s WHERE handle = ?;" % key2table[key],
[handle]) [handle])
self.emit(KEY_TO_NAME_MAP[key] + "-delete", ([handle],)) self.emit(KEY_TO_NAME_MAP[key] + "-delete", ([handle],))
if not transaction.batch: if not transaction.batch:
@ -2078,7 +2082,7 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
result_list = list(find_backlink_handles(handle)) result_list = list(find_backlink_handles(handle))
""" """
cur = self.dbapi.execute("SELECT * from reference WHERE ref_handle = ?;", cur = self.dbapi.execute("SELECT * FROM reference WHERE ref_handle = ?;",
[handle]) [handle])
rows = cur.fetchall() rows = cur.fetchall()
for row in rows: for row in rows:
@ -2553,7 +2557,7 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
references = set(obj.get_referenced_handles_recursively()) references = set(obj.get_referenced_handles_recursively())
# handle addition of new references # handle addition of new references
for (ref_class_name, ref_handle) in references: for (ref_class_name, ref_handle) in references:
self.dbapi.execute("""INSERT into reference (obj_handle, obj_class, ref_handle, ref_class) self.dbapi.execute("""INSERT INTO reference (obj_handle, obj_class, ref_handle, ref_class)
VALUES(?, ?, ?, ?);""", VALUES(?, ?, ?, ?);""",
[obj.handle, [obj.handle,
obj.__class__.__name__, obj.__class__.__name__,
@ -2564,199 +2568,217 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
callback(5) callback(5)
def rebuild_secondary(self, update): def rebuild_secondary(self, update):
self.reindex_reference_map(update) pass
# FIXME: rebuild the secondary databases/maps:
## gender stats
## event_names
## fattr_names
## pattr_names
## sattr_names
## marker_names
## child_refs
## family_rels
## event_roles
## name_types
## origin_types
## repo_types
## note_types
## sm_types
## url_types
## mattr_names
## eattr_names
## place_types
# surname list
def prepare_import(self): def prepare_import(self):
""" """
DBAPI does not commit data on gedcom import, but saves them Do anything needed before an import.
for later commit.
""" """
pass pass
def commit_import(self): def commit_import(self):
""" """
Commits the items that were queued up during the last gedcom Do anything needed after an import.
import for two step adding.
""" """
self.reindex_reference_map(lambda n: n) self.reindex_reference_map(lambda n: n)
def has_handle_for_person(self, key): def has_handle_for_person(self, key):
cur = self.dbapi.execute("select * from person where handle = ?", [key]) cur = self.dbapi.execute("SELECT * FROM person WHERE handle = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_handle_for_family(self, key): def has_handle_for_family(self, key):
cur = self.dbapi.execute("select * from family where handle = ?", [key]) cur = self.dbapi.execute("SELECT * FROM family WHERE handle = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_handle_for_source(self, key): def has_handle_for_source(self, key):
cur = self.dbapi.execute("select * from source where handle = ?", [key]) cur = self.dbapi.execute("SELECT * FROM source WHERE handle = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_handle_for_citation(self, key): def has_handle_for_citation(self, key):
cur = self.dbapi.execute("select * from citation where handle = ?", [key]) cur = self.dbapi.execute("SELECT * FROM citation WHERE handle = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_handle_for_event(self, key): def has_handle_for_event(self, key):
cur = self.dbapi.execute("select * from event where handle = ?", [key]) cur = self.dbapi.execute("SELECT * FROM event WHERE handle = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_handle_for_media(self, key): def has_handle_for_media(self, key):
cur = self.dbapi.execute("select * from media where handle = ?", [key]) cur = self.dbapi.execute("SELECT * FROM media WHERE handle = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_handle_for_place(self, key): def has_handle_for_place(self, key):
cur = self.dbapi.execute("select * from place where handle = ?", [key]) cur = self.dbapi.execute("SELECT * FROM place WHERE handle = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_handle_for_repository(self, key): def has_handle_for_repository(self, key):
cur = self.dbapi.execute("select * from repository where handle = ?", [key]) cur = self.dbapi.execute("SELECT * FROM repository WHERE handle = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_handle_for_note(self, key): def has_handle_for_note(self, key):
cur = self.dbapi.execute("select * from note where handle = ?", [key]) cur = self.dbapi.execute("SELECT * FROM note WHERE handle = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_handle_for_tag(self, key): def has_handle_for_tag(self, key):
cur = self.dbapi.execute("select * from tag where handle = ?", [key]) cur = self.dbapi.execute("SELECT * FROM tag WHERE handle = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_gramps_id_for_person(self, key): def has_gramps_id_for_person(self, key):
cur = self.dbapi.execute("select * from person where gramps_id = ?", [key]) cur = self.dbapi.execute("SELECT * FROM person WHERE gramps_id = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_gramps_id_for_family(self, key): def has_gramps_id_for_family(self, key):
cur = self.dbapi.execute("select * from family where gramps_id = ?", [key]) cur = self.dbapi.execute("SELECT * FROM family WHERE gramps_id = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_gramps_id_for_source(self, key): def has_gramps_id_for_source(self, key):
cur = self.dbapi.execute("select * from source where gramps_id = ?", [key]) cur = self.dbapi.execute("SELECT * FROM source WHERE gramps_id = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_gramps_id_for_citation(self, key): def has_gramps_id_for_citation(self, key):
cur = self.dbapi.execute("select * from citation where gramps_id = ?", [key]) cur = self.dbapi.execute("SELECT * FROM citation WHERE gramps_id = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_gramps_id_for_event(self, key): def has_gramps_id_for_event(self, key):
cur = self.dbapi.execute("select * from event where gramps_id = ?", [key]) cur = self.dbapi.execute("SELECT * FROM event WHERE gramps_id = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_gramps_id_for_media(self, key): def has_gramps_id_for_media(self, key):
cur = self.dbapi.execute("select * from media where gramps_id = ?", [key]) cur = self.dbapi.execute("SELECT * FROM media WHERE gramps_id = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_gramps_id_for_place(self, key): def has_gramps_id_for_place(self, key):
cur = self.dbapi.execute("select * from place where gramps_id = ?", [key]) cur = self.dbapi.execute("SELECT * FROM place WHERE gramps_id = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_gramps_id_for_repository(self, key): def has_gramps_id_for_repository(self, key):
cur = self.dbapi.execute("select * from repository where gramps_id = ?", [key]) cur = self.dbapi.execute("SELECT * FROM repository WHERE gramps_id = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def has_gramps_id_for_note(self, key): def has_gramps_id_for_note(self, key):
cur = self.dbapi.execute("select * from note where gramps_id = ?", [key]) cur = self.dbapi.execute("SELECT * FROM note WHERE gramps_id = ?", [key])
return cur.fetchone() != None return cur.fetchone() != None
def get_person_gramps_ids(self): def get_person_gramps_ids(self):
cur = self.dbapi.execute("select gramps_id from person;") cur = self.dbapi.execute("SELECT gramps_id FROM person;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_family_gramps_ids(self): def get_family_gramps_ids(self):
cur = self.dbapi.execute("select gramps_id from family;") cur = self.dbapi.execute("SELECT gramps_id FROM family;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_source_gramps_ids(self): def get_source_gramps_ids(self):
cur = self.dbapi.execute("select gramps_id from source;") cur = self.dbapi.execute("SELECT gramps_id FROM source;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_citation_gramps_ids(self): def get_citation_gramps_ids(self):
cur = self.dbapi.execute("select gramps_id from citation;") cur = self.dbapi.execute("SELECT gramps_id FROM citation;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_event_gramps_ids(self): def get_event_gramps_ids(self):
cur = self.dbapi.execute("select gramps_id from event;") cur = self.dbapi.execute("SELECT gramps_id FROM event;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_media_gramps_ids(self): def get_media_gramps_ids(self):
cur = self.dbapi.execute("select gramps_id from media;") cur = self.dbapi.execute("SELECT gramps_id FROM media;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_place_gramps_ids(self): def get_place_gramps_ids(self):
cur = self.dbapi.execute("select gramps from place;") cur = self.dbapi.execute("SELECT gramps FROM place;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_repository_gramps_ids(self): def get_repository_gramps_ids(self):
cur = self.dbapi.execute("select gramps_id from repository;") cur = self.dbapi.execute("SELECT gramps_id FROM repository;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def get_note_gramps_ids(self): def get_note_gramps_ids(self):
cur = self.dbapi.execute("select gramps_id from note;") cur = self.dbapi.execute("SELECT gramps_id FROM note;")
rows = cur.fetchall() rows = cur.fetchall()
return [row[0] for row in rows] return [row[0] for row in rows]
def _get_raw_person_data(self, key): def _get_raw_person_data(self, key):
cur = self.dbapi.execute("select blob from person where handle = ?", [key]) cur = self.dbapi.execute("SELECT blob FROM person WHERE handle = ?", [key])
row = cur.fetchone() row = cur.fetchone()
if row: if row:
return pickle.loads(row[0]) return pickle.loads(row[0])
def _get_raw_family_data(self, key): def _get_raw_family_data(self, key):
cur = self.dbapi.execute("select blob from family where handle = ?", [key]) cur = self.dbapi.execute("SELECT blob FROM family WHERE handle = ?", [key])
row = cur.fetchone() row = cur.fetchone()
if row: if row:
return pickle.loads(row[0]) return pickle.loads(row[0])
def _get_raw_source_data(self, key): def _get_raw_source_data(self, key):
cur = self.dbapi.execute("select blob from source where handle = ?", [key]) cur = self.dbapi.execute("SELECT blob FROM source WHERE handle = ?", [key])
row = cur.fetchone() row = cur.fetchone()
if row: if row:
return pickle.loads(row[0]) return pickle.loads(row[0])
def _get_raw_citation_data(self, key): def _get_raw_citation_data(self, key):
cur = self.dbapi.execute("select blob from citation where handle = ?", [key]) cur = self.dbapi.execute("SELECT blob FROM citation WHERE handle = ?", [key])
row = cur.fetchone() row = cur.fetchone()
if row: if row:
return pickle.loads(row[0]) return pickle.loads(row[0])
def _get_raw_event_data(self, key): def _get_raw_event_data(self, key):
cur = self.dbapi.execute("select blob from event where handle = ?", [key]) cur = self.dbapi.execute("SELECT blob FROM event WHERE handle = ?", [key])
row = cur.fetchone() row = cur.fetchone()
if row: if row:
return pickle.loads(row[0]) return pickle.loads(row[0])
def _get_raw_media_data(self, key): def _get_raw_media_data(self, key):
cur = self.dbapi.execute("select blob from media where handle = ?", [key]) cur = self.dbapi.execute("SELECT blob FROM media WHERE handle = ?", [key])
row = cur.fetchone() row = cur.fetchone()
if row: if row:
return pickle.loads(row[0]) return pickle.loads(row[0])
def _get_raw_place_data(self, key): def _get_raw_place_data(self, key):
cur = self.dbapi.execute("select blob from place where handle = ?", [key]) cur = self.dbapi.execute("SELECT blob FROM place WHERE handle = ?", [key])
row = cur.fetchone() row = cur.fetchone()
if row: if row:
return pickle.loads(row[0]) return pickle.loads(row[0])
def _get_raw_repository_data(self, key): def _get_raw_repository_data(self, key):
cur = self.dbapi.execute("select blob from repository where handle = ?", [key]) cur = self.dbapi.execute("SELECT blob FROM repository WHERE handle = ?", [key])
row = cur.fetchone() row = cur.fetchone()
if row: if row:
return pickle.loads(row[0]) return pickle.loads(row[0])
def _get_raw_note_data(self, key): def _get_raw_note_data(self, key):
cur = self.dbapi.execute("select blob from note where handle = ?", [key]) cur = self.dbapi.execute("SELECT blob FROM note WHERE handle = ?", [key])
row = cur.fetchone() row = cur.fetchone()
if row: if row:
return pickle.loads(row[0]) return pickle.loads(row[0])
def _get_raw_tag_data(self, key): def _get_raw_tag_data(self, key):
cur = self.dbapi.execute("select blob from tag where handle = ?", [key]) cur = self.dbapi.execute("SELECT blob FROM tag WHERE handle = ?", [key])
row = cur.fetchone() row = cur.fetchone()
if row: if row:
return pickle.loads(row[0]) return pickle.loads(row[0])