identify whether it's a dupe or empty

This commit is contained in:
Damien Elmes 2011-11-28 16:05:37 +09:00
parent 1235f8362a
commit c0e2a0ba50

View file

@ -132,17 +132,17 @@ insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?,?)""",
################################################## ##################################################
def dupeOrEmpty(self): def dupeOrEmpty(self):
"True if first field is a duplicate or is empty." "1 if first is empty; 2 if first is a duplicate, False otherwise."
val = self.fields[0] val = self.fields[0]
if not val.strip(): if not val.strip():
return True return 1
csum = fieldChecksum(val) csum = fieldChecksum(val)
# find any matching csums and compare # find any matching csums and compare
for flds in self.col.db.list( for flds in self.col.db.list(
"select flds from notes where csum = ? and id != ? and mid = ?", "select flds from notes where csum = ? and id != ? and mid = ?",
csum, self.id or 0, self.mid): csum, self.id or 0, self.mid):
if splitFields(flds)[0] == self.fields[0]: if splitFields(flds)[0] == self.fields[0]:
return True return 2
return False return False
# Flushing cloze notes # Flushing cloze notes