make sure we set usn correctly on card gen; work even if no existing cards

This commit is contained in:
Damien Elmes 2011-12-14 10:22:09 +09:00
parent 47a170898a
commit 819bc326e0

View file

@ -293,23 +293,26 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
ts = maxID(self.db) ts = maxID(self.db)
now = intTime() now = intTime()
rem = [] rem = []
usn = self.usn()
for nid, mid, did, flds in self.db.execute( for nid, mid, did, flds in self.db.execute(
"select id, mid, did, flds from notes where id in "+snids): "select id, mid, did, flds from notes where id in "+snids):
model = self.models.get(mid) model = self.models.get(mid)
avail = self.models.availOrds(model, flds) avail = self.models.availOrds(model, flds)
ok = [] ok = []
for t in model['tmpls']: for t in model['tmpls']:
doHave = nid in have and t['ord'] in have[nid]
# if have ord but empty, add cid to remove list # if have ord but empty, add cid to remove list
if t['ord'] in have[nid] and t['ord'] not in avail: # (may not have nid if generating before any cards added)
if doHave and t['ord'] not in avail:
rem.append(have[nid][t['ord']]) rem.append(have[nid][t['ord']])
# if missing ord and is available, generate # if missing ord and is available, generate
if t['ord'] not in have[nid] and t['ord'] in avail: if not doHave and t['ord'] in avail:
data.append((ts, nid, t['did'] or did, t['ord'], data.append((ts, nid, t['did'] or did, t['ord'],
now, nid)) now, usn, nid))
ts += 1 ts += 1
# bulk update # bulk update
self.db.executemany(""" self.db.executemany("""
insert into cards values (?,?,?,?,?,-1,0,0,?,0,0,0,0,0,0,0,"")""", insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,"")""",
data) data)
return rem return rem