mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
catch notes with invalid field count in db check
This commit is contained in:
parent
ab198c46be
commit
7ad33fea06
1 changed files with 21 additions and 10 deletions
|
@ -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))
|
"Deleted %d notes with missing note type.", len(ids))
|
||||||
% len(ids))
|
% len(ids))
|
||||||
self.remNotes(ids)
|
self.remNotes(ids)
|
||||||
# cards with invalid ordinal
|
# for each model
|
||||||
for m in self.models.all():
|
for m in self.models.all():
|
||||||
# ignore clozes
|
# cards with invalid ordinal
|
||||||
if m['type'] != MODEL_STD:
|
if m['type'] == MODEL_STD:
|
||||||
continue
|
|
||||||
ids = self.db.list("""
|
ids = self.db.list("""
|
||||||
select id from cards where ord not in %s and nid in (
|
select id from cards where ord not in %s and nid in (
|
||||||
select id from notes where mid = ?)""" %
|
select id from notes where mid = ?)""" %
|
||||||
|
@ -687,6 +686,18 @@ select id from notes where mid = ?)""" %
|
||||||
"Deleted %d cards with missing template.",
|
"Deleted %d cards with missing template.",
|
||||||
len(ids)) % len(ids))
|
len(ids)) % len(ids))
|
||||||
self.remCards(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
|
# delete any notes with missing cards
|
||||||
ids = self.db.list("""
|
ids = self.db.list("""
|
||||||
select id from notes where id not in (select distinct nid from cards)""")
|
select id from notes where id not in (select distinct nid from cards)""")
|
||||||
|
|
Loading…
Reference in a new issue