From e858a54456ff5d0ed642bc49a2f2b662919f70cf Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Tue, 13 Jun 2006 19:59:14 +0000 Subject: [PATCH] 2006-06-13 Alex Roitman * src/GrampsDb/_GrampsBSDDB.py (gramps_upgrade_9): Avoid using secondary index when upgrading events; manually resolve duplicate IDs. svn: r6886 --- ChangeLog | 4 ++++ src/GrampsDb/_GrampsBSDDB.py | 41 ++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a0b8fb0e..b2e2ad6e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-06-13 Alex Roitman + * src/GrampsDb/_GrampsBSDDB.py (gramps_upgrade_9): Avoid using + secondary index when upgrading events; manually resolve duplicate IDs. + 2006-06-12 Brian Matherly * src/plugins/GraphVis.py: ues Mime instead of GrampsMime diff --git a/src/GrampsDb/_GrampsBSDDB.py b/src/GrampsDb/_GrampsBSDDB.py index 3107a3b5f..3513fd20e 100644 --- a/src/GrampsDb/_GrampsBSDDB.py +++ b/src/GrampsDb/_GrampsBSDDB.py @@ -31,6 +31,7 @@ Provides the Berkeley DB (BSDDB) database backend for GRAMPS #------------------------------------------------------------------------- import cPickle as pickle import os +import re import time import locale from gettext import gettext as _ @@ -424,7 +425,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): self.surnames = db.DB(self.env) self.surnames.set_flags(db.DB_DUP|db.DB_DUPSORT) self.surnames.open(self.full_name, "surnames", db.DB_BTREE, - flags=table_flags) + flags=table_flags) self.name_group = db.DB(self.env) self.name_group.set_flags(db.DB_DUP) @@ -1521,16 +1522,28 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): # Event upgrade # Turns out that a lof ot events have duplicate gramps IDs - # We need to fix this - table_flags = self.open_flags() - self.eid_trans = db.DB(self.env) - self.eid_trans.set_flags(db.DB_DUP) - self.eid_trans.open(self.full_name, "eidtrans", - db.DB_HASH, flags=table_flags) - self.event_map.associate(self.eid_trans,find_idmap,table_flags) - eid_list = self.eid_trans.keys() - dup_ids = [eid for eid in eid_list if eid_list.count(eid) > 1 ] + # We need to fix this. For some reason secondary index gets confused + # so we resolve duplicate IDs manually. + # First a quick pass via the cursor to get a list of event ids + eid_list = [] + cursor = self.get_event_cursor() + data = cursor.first() + while data: + handle,val = data + eid_list.append(val[1]) + data = cursor.next() + cursor.close() + # Find the largest ID and extract the integer: + # We can do this because in 2.0.x the event id is never exposed + eid_list.sort() + last_id = eid_list[-1] + nre = re.compile("\D+(\d+)") + max_id_number = int(nre.match(last_id).groups()[0]) + + # get the list of all IDs that are non-unique + dup_ids = [eid for eid in eid_list if eid_list.count(eid) > 1 ] + for handle in self.event_map.keys(): info = self.event_map[handle] event = Event() @@ -1540,9 +1553,12 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): event.source_list, event.note, witness_list, event.media_list, event.change) = info + # Change ID if it is non-unique if event.gramps_id in dup_ids: - event.gramps_id = self.find_next_event_gramps_id() + max_id_number += 1 + event.gramps_id = self.eprefix % max_id_number + # Convert old string-based type to GrampsType event.type.set_from_xml_str(old_type) # Cover attributes contained in MediaRefs @@ -1582,10 +1598,9 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback): _("Broken witness reference detected " "while upgrading database to version 9.") event.set_note(note_text) - + self.commit_event(event,trans) self.update() - self.eid_trans.close() # Place upgrade for handle in self.place_map.keys():