From 5868ff52b9ad0b09639bc14678df9d9fff2cd667 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 26 Aug 2011 22:28:35 +0900 Subject: [PATCH] handle duplicate fact creation times --- anki/storage.py | 16 ++++++++++------ tests/support/anki12.anki | Bin 196608 -> 196608 bytes 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/anki/storage.py b/anki/storage.py index 675189bee..59f5ac130 100644 --- a/anki/storage.py +++ b/anki/storage.py @@ -252,13 +252,17 @@ from facts order by created""") # bold/italics/underline cruft. map = {} data = [] - factmap = {} + factidmap = {} + times = {} from anki.utils import minimizeHTML for c, row in enumerate(facts): oldid = row[0] row = list(row) # get rid of old created column and update id - factmap[row[0]] = row[3] + while row[3] in times: + row[3] += 1 + times[row[3]] = True + factidmap[row[0]] = row[3] row[0] = row[3] del row[3] map[oldid] = row[0] @@ -276,7 +280,7 @@ from facts order by created""") # it's not unique and update the fact id times = {} rows = [] - cardmap = {} + cardidmap = {} for row in db.execute(""" select id, cast(created*1000 as int), factId, ordinal, cast(modified as int), @@ -298,9 +302,9 @@ order by created"""): row[1] += 1 times[row[1]] = True # rewrite fact id - row[2] = factmap[row[2]] + row[2] = factidmap[row[2]] # note id change and save all but old id - cardmap[row[0]] = row[1] + cardidmap[row[0]] = row[1] rows.append(row[1:]) # drop old table and rewrite db.execute("drop table cards") @@ -336,7 +340,7 @@ yesCount from reviewHistory"""): row = list(row) # new card ids try: - row[1] = cardmap[row[1]] + row[1] = cardidmap[row[1]] except: # id doesn't exist continue diff --git a/tests/support/anki12.anki b/tests/support/anki12.anki index 7fd7be092867e304b055d784c0160e8cfa558331..3ee5fe744f6d325a004594dce901cbc5bf0e04e3 100644 GIT binary patch delta 65 zcmZo@;Av>!nIO%`Hc`fzm5o97k?h8loBLRJEakf1qA>t;v2DK*}eoEP!8#nLBA~o3f&ivlXAZ?1QEfT XzmuoGNdcRK@xO=hzX7-LzXA_H0jnB#