diff -r e80160a19653 -r f74bad856bce lib/my_db.py --- a/lib/my_db.py Mon Oct 27 02:26:39 2003 -0500 +++ b/lib/my_db.py Thu Oct 30 03:24:25 2003 -0500 @@ -1,5 +1,3 @@ -#!/usr/bin/python - import pgdb import config from bkmark import Bookmark @@ -292,21 +290,24 @@ qry = self._bookmarks_selection(has_kw, except_kw) + ';' self.crs.execute(qry) return self.crs.fetchall() - def get_bookmarks_count(self, has_kw = [0], except_kw = []): + def get_bookmarks_count(self, has_kw = [0], except_kw = [], opt_kw = []): """ Return a count of bookmarks which would have been return on select_bookmarks qry. """ qry = """ - SELECT COUNT(id) FROM bookmarks - WHERE userid = %d AND id IN """ % self.userid - qry += "(" + self._bookmarks_selection(has_kw, except_kw) + ");" + SELECT keyword, COUNT(keyword) + FROM bookmarks_keywords + WHERE userid = %d + """ % self.userid + if len(opt_kw) > 0: + qry += "AND ( " + qry += " OR ".join(map(lambda e: "keyword = %d" % e, opt_kw)) + qry += ") " + qry += "AND bookmark IN (" + self._bookmarks_selection(has_kw, except_kw) + ") " + qry += "GROUP BY keyword ORDER BY keyword;" self.crs.execute(qry) - result = self.crs.fetchone() - if result: - return result[0] - else: - return 0 + return self.crs.fetchall() def get_folder_keyword(self, id): self.crs.execute(""" SELECT k.id, k.name