Fix combination of type and user restriction not working

This commit is contained in:
Kovid Goyal 2020-07-26 20:17:40 +05:30
parent 01f14b8928
commit 2316f291e0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1838,14 +1838,15 @@ class DB(object):
ls = json.loads ls = json.loads
q = 'SELECT id, book, format, user_type, user, annot_data FROM annotations' q = 'SELECT id, book, format, user_type, user, annot_data FROM annotations'
data = [] data = []
if restrict_to_user or annotation_type: restrict_clauses = []
q += ' WHERE '
if restrict_to_user is not None: if restrict_to_user is not None:
data.extend(restrict_to_user) data.extend(restrict_to_user)
q += ' user_type = ? AND user = ?' restrict_clauses.append(' user_type = ? AND user = ?')
if annotation_type: if annotation_type:
data.append(annotation_type) data.append(annotation_type)
q += ' annot_type = ? ' restrict_clauses.append(' annot_type = ? ')
if restrict_clauses:
q += ' WHERE ' + ' AND '.join(restrict_clauses)
q += ' ORDER BY timestamp DESC ' q += ' ORDER BY timestamp DESC '
count = 0 count = 0
for (rowid, book_id, fmt, user_type, user, annot_data) in self.execute(q, tuple(data)): for (rowid, book_id, fmt, user_type, user, annot_data) in self.execute(q, tuple(data)):