catch notes with invalid field count in db check

This commit is contained in:
Damien Elmes 2013-05-14 18:12:31 +09:00
parent ab198c46be
commit 7ad33fea06

View file

@ -671,11 +671,10 @@ select id from notes where mid not in """ + ids2str(self.models.ids()))
"Deleted %d notes with missing note type.", len(ids))
% len(ids))
self.remNotes(ids)
# cards with invalid ordinal
# for each model
for m in self.models.all():
# ignore clozes
if m['type'] != MODEL_STD:
continue
# cards with invalid ordinal
if m['type'] == MODEL_STD:
ids = self.db.list("""
select id from cards where ord not in %s and nid in (
select id from notes where mid = ?)""" %
@ -687,6 +686,18 @@ select id from notes where mid = ?)""" %
"Deleted %d cards with missing template.",
len(ids)) % len(ids))
self.remCards(ids)
# notes with invalid field count
ids = []
for id, flds in self.db.execute(
"select id, flds from notes where mid = ?", m['id']):
if (flds.count("\x1f") + 1) != len(m['flds']):
ids.append(id)
if ids:
problems.append(
ngettext("Deleted %d note with wrong field count.",
"Deleted %d notes with wrong field count.",
len(ids)) % len(ids))
self.remNotes(ids)
# delete any notes with missing cards
ids = self.db.list("""
select id from notes where id not in (select distinct nid from cards)""")