def db_getHint(self, hintid): #{{{ cu = self.db.cursor() cu.execute("select hint from hints where rowid=%d" % hintid) row = cu.fetchone() if row: hint = str(row[0]) log("# Getting hint %d: %s" % (hintid, hint)) return True, hint else: return False, 0
def db_getAllHints(self, keys=[]): #{{{ cu = self.db.cursor() key = "%" + "%".join(keys) + "%" cu.execute("select rowid from hints where hint like ?", (key,)) rows = cu.fetchall() if rows: hintids = [int(x[0]) for x in rows] log("# Getting all hint ids for [%s]: %s" % (key, ",".join([str(x) for x in hintids]))) return True, hintids else: return False, []
def db_getRandomHint(self, keys=[]): #{{{ cu = self.db.cursor() key = "%" + "%".join(keys) + "%" cu.execute("select rowid, hint from hints where hint like ? order by random() limit 1", (key,)) row = cu.fetchone() if row: hintid = int(row[0]) hint = str(row[1]) log("# Getting random hint for %s: [%d] %s" % (key, hintid, hint)) return True, hintid, hint else: return False, 0, 0
def db_getAllHints(self, keys=[]): #{{{ cu = self.db.cursor() key = "%" + "%".join(keys) + "%" cu.execute("select rowid from hints where hint like ?", (key, )) rows = cu.fetchall() if rows: hintids = [int(x[0]) for x in rows] log("# Getting all hint ids for [%s]: %s" % (key, ",".join([str(x) for x in hintids]))) return True, hintids else: return False, []
def db_getRandomHint(self, keys=[]): #{{{ cu = self.db.cursor() key = "%" + "%".join(keys) + "%" cu.execute( "select rowid, hint from hints where hint like ? order by random() limit 1", (key, )) row = cu.fetchone() if row: hintid = int(row[0]) hint = str(row[1]) log("# Getting random hint for %s: [%d] %s" % (key, hintid, hint)) return True, hintid, hint else: return False, 0, 0
def db_delHint(self, hintid): #{{{ cu = self.db.cursor() cu.execute("delete from hints where rowid=%d" % hintid) log("# Deleted hint %d" % hintid) self.db.commit()
def db_addHint(self, hint): #{{{ cu = self.db.cursor() cu.execute("insert into hints values(?)", (hint,)) log("# Added hint %d" % cu.lastrowid) self.db.commit() return cu.lastrowid
def db_addHint(self, hint): #{{{ cu = self.db.cursor() cu.execute("insert into hints values(?)", (hint, )) log("# Added hint %d" % cu.lastrowid) self.db.commit() return cu.lastrowid