From 2316f291e0775cd6f477663743fa2f51bc87f580 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 26 Jul 2020 20:17:40 +0530 Subject: [PATCH] Fix combination of type and user restriction not working --- src/calibre/db/backend.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index 2290b28f64..b9ca4818a0 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -1838,14 +1838,15 @@ class DB(object): ls = json.loads q = 'SELECT id, book, format, user_type, user, annot_data FROM annotations' data = [] - if restrict_to_user or annotation_type: - q += ' WHERE ' + restrict_clauses = [] if restrict_to_user is not None: data.extend(restrict_to_user) - q += ' user_type = ? AND user = ?' + restrict_clauses.append(' user_type = ? AND user = ?') if 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 ' count = 0 for (rowid, book_id, fmt, user_type, user, annot_data) in self.execute(q, tuple(data)):