2006-06-13 Alex Roitman <shura@gramps-project.org>

* src/GrampsDb/_GrampsBSDDB.py (gramps_upgrade_9): Avoid using
	secondary index when upgrading events; manually resolve duplicate IDs.



svn: r6886
This commit is contained in:
Alex Roitman 2006-06-13 19:59:14 +00:00
parent abded67021
commit 2668b38e24
2 changed files with 32 additions and 13 deletions

View File

@ -1,3 +1,7 @@
2006-06-13 Alex Roitman <shura@gramps-project.org>
* src/GrampsDb/_GrampsBSDDB.py (gramps_upgrade_9): Avoid using
secondary index when upgrading events; manually resolve duplicate IDs.
2006-06-12 Brian Matherly <brian@gramps-project.org> 2006-06-12 Brian Matherly <brian@gramps-project.org>
* src/plugins/GraphVis.py: ues Mime instead of GrampsMime * src/plugins/GraphVis.py: ues Mime instead of GrampsMime

View File

@ -31,6 +31,7 @@ Provides the Berkeley DB (BSDDB) database backend for GRAMPS
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import cPickle as pickle import cPickle as pickle
import os import os
import re
import time import time
import locale import locale
from gettext import gettext as _ from gettext import gettext as _
@ -424,7 +425,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
self.surnames = db.DB(self.env) self.surnames = db.DB(self.env)
self.surnames.set_flags(db.DB_DUP|db.DB_DUPSORT) self.surnames.set_flags(db.DB_DUP|db.DB_DUPSORT)
self.surnames.open(self.full_name, "surnames", db.DB_BTREE, 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 = db.DB(self.env)
self.name_group.set_flags(db.DB_DUP) self.name_group.set_flags(db.DB_DUP)
@ -1521,14 +1522,26 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
# Event upgrade # Event upgrade
# Turns out that a lof ot events have duplicate gramps IDs # Turns out that a lof ot events have duplicate gramps IDs
# We need to fix this # We need to fix this. For some reason secondary index gets confused
table_flags = self.open_flags() # so we resolve duplicate IDs manually.
self.eid_trans = db.DB(self.env) # First a quick pass via the cursor to get a list of event ids
self.eid_trans.set_flags(db.DB_DUP) eid_list = []
self.eid_trans.open(self.full_name, "eidtrans", cursor = self.get_event_cursor()
db.DB_HASH, flags=table_flags) data = cursor.first()
self.event_map.associate(self.eid_trans,find_idmap,table_flags) while data:
eid_list = self.eid_trans.keys() 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 ] dup_ids = [eid for eid in eid_list if eid_list.count(eid) > 1 ]
for handle in self.event_map.keys(): for handle in self.event_map.keys():
@ -1540,9 +1553,12 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
event.source_list, event.note, witness_list, event.source_list, event.note, witness_list,
event.media_list, event.change) = info event.media_list, event.change) = info
# Change ID if it is non-unique
if event.gramps_id in dup_ids: 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) event.type.set_from_xml_str(old_type)
# Cover attributes contained in MediaRefs # Cover attributes contained in MediaRefs
@ -1585,7 +1601,6 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
self.commit_event(event,trans) self.commit_event(event,trans)
self.update() self.update()
self.eid_trans.close()
# Place upgrade # Place upgrade
for handle in self.place_map.keys(): for handle in self.place_map.keys():