From 582a9dd2909f31db3015d9470a0795a6d305f606 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 5 Feb 2010 12:27:32 +0900 Subject: [PATCH] don't create empty tags on export --- anki/exporting.py | 3 ++- anki/tags.py | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/anki/exporting.py b/anki/exporting.py index cd7bf8d13..181dd9c44 100644 --- a/anki/exporting.py +++ b/anki/exporting.py @@ -54,7 +54,8 @@ class Exporter(object): if not self.limitTags: cards = self.deck.s.column0("select id from cards") else: - d = tagIds(self.deck.s, self.limitTags) + d = tagIds(self.deck.s, self.limitTags, create=False) + print d cards = self.deck.s.column0( "select cardId from cardTags where tagid in %s" % ids2str(d.values())) diff --git a/anki/tags.py b/anki/tags.py index aa68b6766..46fe1149c 100644 --- a/anki/tags.py +++ b/anki/tags.py @@ -36,21 +36,22 @@ primary key(id))""") except: pass -def tagId(s, tag): +def tagId(s, tag, create=True): "Return ID for tag, creating if necessary." id = s.scalar("select id from tags where tag = :tag", tag=tag) - if id: + if id or not create: return id s.statement(""" insert or ignore into tags (tag) values (:tag)""", tag=tag) return s.scalar("select id from tags where tag = :tag", tag=tag) -def tagIds(s, tags): +def tagIds(s, tags, create=True): "Return an ID for all tags, creating if necessary." ids = {} - s.statements("insert or ignore into tags (tag) values (:tag)", - [{'tag': t} for t in tags]) + if create: + s.statements("insert or ignore into tags (tag) values (:tag)", + [{'tag': t} for t in tags]) tagsD = dict([(x.lower(), y) for (x, y) in s.all(""" select tag, id from tags where tag in (%s)""" % ",".join([