diff --git a/ankiqt/ui/activetags.py b/ankiqt/ui/activetags.py index cd0e1fb04..a9b9cf8dd 100644 --- a/ankiqt/ui/activetags.py +++ b/ankiqt/ui/activetags.py @@ -52,7 +52,7 @@ class ActiveTagsChooser(QDialog): ("models", "select tags from models", "contents.png"), ("cms", "select name from cardModels", "Anki_Card.png")): d = {} - tagss = self.deck.s.column0(sql) + tagss = self.deck.db.column0(sql) for tags in tagss: for tag in parseTags(tags): d[tag] = 1 diff --git a/ankiqt/ui/addcards.py b/ankiqt/ui/addcards.py index 3b6b3ea87..463f0460b 100644 --- a/ankiqt/ui/addcards.py +++ b/ankiqt/ui/addcards.py @@ -218,7 +218,7 @@ question or answer on all cards."""), parent=self) self.modelChooser.deinit() self.editor.close() ui.dialogs.close("AddCards") - self.parent.deck.s.flush() + self.parent.deck.db.flush() self.parent.deck.rebuildCSS() self.parent.reset() saveGeom(self, "add") diff --git a/ankiqt/ui/cardlist.py b/ankiqt/ui/cardlist.py index 5f9e5dabe..1aa290995 100644 --- a/ankiqt/ui/cardlist.py +++ b/ankiqt/ui/cardlist.py @@ -165,7 +165,7 @@ where cards.factId = facts.id """ query += sort else: # field value - ret = self.deck.s.all( + ret = self.deck.db.all( "select id, numeric from fieldModels where name = :name", name=self.sortKey[1]) fields = ",".join([str(x[0]) for x in ret]) @@ -182,14 +182,14 @@ where cards.factId = facts.id """ "and fields.factId = cards.factId" + ads + " order by cards.ordinal, %s") % (fields, order) # run the query - self.cards = self.deck.s.all(query) + self.cards = self.deck.db.all(query) if self.deck.getInt('reverseOrder'): self.cards.reverse() self.reset() def updateCard(self, index): try: - self.cards[index.row()] = self.deck.s.first(""" + self.cards[index.row()] = self.deck.db.first(""" select id, question, answer, combinedDue, reps, factId, created, modified, interval, factor, noCount, type, (select tags from facts where facts.id = cards.factId), (select created from facts where @@ -212,7 +212,7 @@ facts.id = cards.factId), firstAnswered from cards where id = :id""", def getCard(self, index): try: - return self.deck.s.query(Card).get(self.getCardID(index)) + return self.deck.db.query(Card).get(self.getCardID(index)) except IndexError: return None @@ -368,7 +368,7 @@ class EditDeck(QMainWindow): self.config['iconSize'])) self.dialog.toolBar.toggleViewAction().setText(_("Toggle Toolbar")) # flush all changes before we load - self.deck.s.flush() + self.deck.db.flush() self.model = DeckModel(self.parent, self.parent.deck) self.dialog.tableView.setSortingEnabled(False) self.dialog.tableView.setShowGrid(False) @@ -457,7 +457,7 @@ class EditDeck(QMainWindow): ("models", "select tags from models", "contents.png"), ("cms", "select name from cardModels", "Anki_Card.png")): d = {} - tagss = self.deck.s.column0(sql) + tagss = self.deck.db.column0(sql) for tags in tagss: for tag in parseTags(tags): d[tag] = 1 @@ -553,20 +553,20 @@ class EditDeck(QMainWindow): "question", "answer", "created", "modified", "due", "interval", "reps", "factor", "noCount", "firstAnswered"): return - old = self.deck.s.scalar("select sql from sqlite_master where name = :k", + old = self.deck.db.scalar("select sql from sqlite_master where name = :k", k="ix_cards_sort") if old and key in old: return self.parent.setProgressParent(self) self.deck.startProgress(2) self.deck.updateProgress(_("Building Index...")) - self.deck.s.statement("drop index if exists ix_cards_sort") + self.deck.db.statement("drop index if exists ix_cards_sort") self.deck.updateProgress() if key in ("question", "answer"): key = key + " collate nocase" - self.deck.s.statement( + self.deck.db.statement( "create index ix_cards_sort on cards (%s)" % key) - self.deck.s.statement("analyze") + self.deck.db.statement("analyze") self.deck.finishProgress() self.parent.setProgressParent(None) @@ -788,14 +788,14 @@ class EditDeck(QMainWindow): self.dialog.tableView.selectionModel().selectedRows()] def selectedFacts(self): - return self.deck.s.column0(""" + return self.deck.db.column0(""" select distinct factId from cards where id in (%s)""" % ",".join([ str(self.model.cards[idx.row()][0]) for idx in self.dialog.tableView.selectionModel().selectedRows()])) def selectedFactsAsCards(self): - return self.deck.s.column0( + return self.deck.db.column0( "select id from cards where factId in (%s)" % ",".join([str(s) for s in self.selectedFacts()])) @@ -946,7 +946,7 @@ where id in (%s)""" % ",".join([ sf = self.selectedFacts() if not sf: return - mods = self.deck.s.column0(""" + mods = self.deck.db.column0(""" select distinct modelId from facts where id in %s""" % ids2str(sf)) if not len(mods) == 1: @@ -955,7 +955,7 @@ where id in %s""" % ids2str(sf)) parent=self) return # get cards to enable - cms = [x.id for x in self.deck.s.query(Fact).get(sf[0]).\ + cms = [x.id for x in self.deck.db.query(Fact).get(sf[0]).\ model.cardModels] d = AddCardChooser(self, cms) if not d.exec_(): @@ -965,7 +965,7 @@ where id in %s""" % ids2str(sf)) self.parent.setProgressParent(self) self.deck.startProgress() self.deck.setUndoStart(n) - facts = self.deck.s.query(Fact).filter( + facts = self.deck.db.query(Fact).filter( text("id in %s" % ids2str(sf))).order_by(Fact.created).all() self.deck.updateProgress(_("Generating Cards...")) ids = [] @@ -986,7 +986,7 @@ where id in %s""" % ids2str(sf)) def onChangeModel(self): sf = self.selectedFacts() - mods = self.deck.s.column0(""" + mods = self.deck.db.column0(""" select distinct modelId from facts where id in %s""" % ids2str(sf)) if not len(mods) == 1: @@ -1088,7 +1088,7 @@ where id in %s""" % ids2str(sf)) sf = self.selectedFacts() if not sf: return - mods = self.deck.s.column0(""" + mods = self.deck.db.column0(""" select distinct modelId from facts where id in %s""" % ids2str(sf)) if not len(mods) == 1: @@ -1151,12 +1151,12 @@ where id in %s""" % ids2str(sf)) restoreGeom(win, "findDupes") fields = sorted(self.currentCard.fact.model.fieldModels, key=attrgetter("name")) # per-model data - data = self.deck.s.all(""" + data = self.deck.db.all(""" select fm.id, m.name || '>' || fm.name from fieldmodels fm, models m where fm.modelId = m.id""") data.sort(key=itemgetter(1)) # all-model data - data2 = self.deck.s.all(""" + data2 = self.deck.db.all(""" select fm.id, fm.name from fieldmodels fm""") byName = {} for d in data2: @@ -1291,7 +1291,7 @@ class AddCardChooser(QDialog): restoreGeom(self, "addCardModels") def displayCards(self): - self.cms = self.parent.deck.s.all(""" + self.cms = self.parent.deck.db.all(""" select id, name, active from cardModels where id in %s order by ordinal""" % ids2str(self.cms)) diff --git a/ankiqt/ui/clayout.py b/ankiqt/ui/clayout.py index 2e2207bfe..d086e6d2b 100644 --- a/ankiqt/ui/clayout.py +++ b/ankiqt/ui/clayout.py @@ -36,10 +36,10 @@ class CardLayout(QDialog): else: self.model = factOrModel # see if there's an available fact - id = self.deck.s.scalar( + id = self.deck.db.scalar( "select id from facts where modelId = :id", id=self.model.id) if id: - self.fact = self.deck.s.query(Fact).get(id) + self.fact = self.deck.db.query(Fact).get(id) else: # generate a dummy one self.fact = self.deck.newFact(self.model) @@ -51,8 +51,8 @@ class CardLayout(QDialog): self.plastiqueStyle = QStyleFactory.create("plastique") if self.card: # limited to an existing template - self.cards = [self.deck.s.query(Card).get(id) for id in - self.deck.s.column0( + self.cards = [self.deck.db.query(Card).get(id) for id in + self.deck.db.column0( "select id from cards where factId = :fid " "order by ordinal", fid=self.fact.id)] type = 0 @@ -210,7 +210,7 @@ class CardLayout(QDialog): self.form.allowEmptyAnswer.setChecked(card.allowEmptyAnswer) self.form.alignment.setCurrentIndex(card.questionAlign) self.form.typeAnswer.clear() - self.typeFieldNames = self.deck.s.column0(""" + self.typeFieldNames = self.deck.db.column0(""" select fieldModels.name as n from fieldModels, cardModels where cardModels.modelId = fieldModels.modelId and cardModels.id = :id @@ -477,7 +477,7 @@ order by n""", id=card.id) f.name = _("Field %d") % (len(self.model.fieldModels) + 1) self.deck.addFieldModel(self.model, f) try: - self.deck.s.refresh(self.fact) + self.deck.db.refresh(self.fact) except: # not yet added self.updateFact() @@ -488,7 +488,7 @@ order by n""", id=card.id) def updateFact(self): oldFact = self.fact - model = self.deck.s.query(Model).get(oldFact.model.id) + model = self.deck.db.query(Model).get(oldFact.model.id) fact = self.deck.newFact(model) for field in fact.fields: try: diff --git a/ankiqt/ui/facteditor.py b/ankiqt/ui/facteditor.py index df542e4db..7ef910ead 100644 --- a/ankiqt/ui/facteditor.py +++ b/ankiqt/ui/facteditor.py @@ -88,7 +88,7 @@ class FactEditor(object): def refresh(self): if self.fact: try: - self.deck.s.refresh(self.fact) + self.deck.db.refresh(self.fact) except InvalidRequestError: # not attached to session yet, add cards dialog will handle return @@ -576,7 +576,7 @@ class FactEditor(object): "where fieldModelId = :fmid and value = :val and id != :id " "and chksum = :chk") val = self.textForField(field) - return not self.deck.s.scalar( + return not self.deck.db.scalar( req, val=val, fmid=field.fieldModel.id, id=field.id, chk=fieldChecksum(val)) @@ -586,7 +586,7 @@ class FactEditor(object): old = self.fact.tags self.fact.tags = canonifyTags(unicode(self.tags.text())) if old != self.fact.tags: - self.deck.s.flush() + self.deck.db.flush() self.deck.updateFactTags([self.fact.id]) self.fact.setModified(textChanged=True, deck=self.deck) self.deck.flushMod() diff --git a/ankiqt/ui/importing.py b/ankiqt/ui/importing.py index 26b8f0ea8..06644d183 100644 --- a/ankiqt/ui/importing.py +++ b/ankiqt/ui/importing.py @@ -224,7 +224,7 @@ you can enter it here. Use \\t to represent tab."""), self.dialog.status.setText(txt) self.file = None self.maybePreview() - self.parent.deck.s.flush() + self.parent.deck.db.flush() self.parent.reset() self.modelChooser.deinit() diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 161b76306..afe6e7b4b 100755 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -392,7 +392,7 @@ Please do not file a bug report with Anki.
""") self.disableCardMenuItems() elif state == "deckFinished": self.currentCard = None - self.deck.s.flush() + self.deck.db.flush() self.hideButtons() self.disableCardMenuItems() self.switchToCongratsScreen() @@ -417,7 +417,7 @@ Please do not file a bug report with Anki.
""") if self.lastState == "editCurrentFact": return self.moveToState("saveEdit") self.mainWin.actionRepeatAudio.setEnabled(False) - self.deck.s.flush() + self.deck.db.flush() self.showEditor() elif state == "saveEdit": self.mainWin.actionRepeatAudio.setEnabled(True) @@ -491,10 +491,10 @@ Please do not file a bug report with Anki.
""") if self.state != "showAnswer": return # force refresh of card then remove from session as we update in pure sql - self.deck.s.refresh(self.currentCard) - self.deck.s.refresh(self.currentCard.fact) - self.deck.s.refresh(self.currentCard.cardModel) - self.deck.s.expunge(self.currentCard) + self.deck.db.refresh(self.currentCard) + self.deck.db.refresh(self.currentCard.fact) + self.deck.db.refresh(self.currentCard.cardModel) + self.deck.db.expunge(self.currentCard) # answer self.deck.answerCard(self.currentCard, quality) self.lastQuality = quality @@ -514,7 +514,7 @@ Please do not file a bug report with Anki.
""") %s... is a leech.""") % stripHTML(stripSounds(self.currentCard.question)).\ replace("\n", " ")[0:30]) - if isLeech and self.deck.s.scalar( + if isLeech and self.deck.db.scalar( "select 1 from cards where id = :id and type < 0", id=cardId): txt += _(" It has been suspended.") self.setNotice(txt) @@ -997,7 +997,7 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors") self.onNew(path=path) # ensure all changes come to us self.deck.modified = 0 - self.deck.s.commit() + self.deck.db.commit() self.deck.syncName = u"something" self.deck.lastLoaded = self.deck.modified if self.config['syncUsername'] and self.config['syncPassword']: @@ -1667,14 +1667,14 @@ not be touched.""") % # counts & time for today todayStart = self.deck.failedCutoff - 86400 sql = "select count(), sum(userTime) from revlog" - (reps, time_) = self.deck.s.first( + (reps, time_) = self.deck.db.first( sql + " where time > :start", start=todayStart) h['timeToday'] = sessionColour % ( anki.utils.fmtTimeSpan(time_ or 0, short=True, point=1)) h['repsToday'] = sessionColour % reps # and yesterday yestStart = todayStart - 86400 - (reps, time_) = self.deck.s.first( + (reps, time_) = self.deck.db.first( sql + " where time > :start and time <= :end", start=yestStart, end=todayStart) h['timeTodayChg'] = str( @@ -1684,10 +1684,10 @@ not be touched.""") % limit = self.deck.sessionTimeLimit start = self.deck.sessionStartTime or time.time() - limit start2 = self.deck.lastSessionStart or start - limit - last10 = self.deck.s.scalar( + last10 = self.deck.db.scalar( "select count(*) from revlog where time >= :t", t=start) - last20 = self.deck.s.scalar( + last20 = self.deck.db.scalar( "select count(*) from revlog where " "time >= :t and time < :t2", t=start2, t2=start) @@ -2198,7 +2198,7 @@ it to your friends. if self.deck and not self.deck.syncName: if interactive: if (not self.config['mediaLocation'] - and self.deck.s.scalar("select 1 from media limit 1")): + and self.deck.db.scalar("select 1 from media limit 1")): ui.utils.showInfo(_("""\ Syncing sounds and images requires a free file synchronization service like \ DropBox. Click help to learn more, and OK to continue syncing."""), diff --git a/ankiqt/ui/modelproperties.py b/ankiqt/ui/modelproperties.py index 35c48b48a..11920ca68 100644 --- a/ankiqt/ui/modelproperties.py +++ b/ankiqt/ui/modelproperties.py @@ -71,7 +71,7 @@ class ModelProperties(QDialog): if txt[0]: self.currentCard.name = txt[0] self.needRebuild = True - self.deck.updateCardTags(self.deck.s.column0( + self.deck.updateCardTags(self.deck.db.column0( "select id from cards where cardModelId = :id", id=self.currentCard.id)) self.updateCards() diff --git a/ankiqt/ui/sync.py b/ankiqt/ui/sync.py index 68cb8f9ad..47909c2db 100755 --- a/ankiqt/ui/sync.py +++ b/ankiqt/ui/sync.py @@ -263,7 +263,7 @@ sync was aborted. Please report this error.""") # server to save, then save local client.server.finish() self.deck.lastLoaded = self.deck.modified - self.deck.s.commit() + self.deck.db.commit() self.setStatus(_("Sync complete.")) else: changes = False