From ad9a66cc1e0ab1d4a53a69bca11a78a94cadfb11 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 23 Sep 2024 08:00:54 +0530 Subject: [PATCH] =?UTF-8?q?Fix=20#2445=20(Fix=20bug=20in=20new=20get=5Fite?= =?UTF-8?q?m=5Fid()=20db=20lookup.=20Names=20in=20the=20authors=20table=20?= =?UTF-8?q?=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/calibre/db/tables.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/db/tables.py b/src/calibre/db/tables.py index f162011e6b85..d90fe79cf9b8 100644 --- a/src/calibre/db/tables.py +++ b/src/calibre/db/tables.py @@ -65,9 +65,11 @@ def __init__(self, name, metadata, link_table=None): 'datetime': c_parse, 'bool': bool }.get(dt) + self.serialize = None if name == 'authors': # Legacy self.unserialize = lambda x: x.replace('|', ',') if x else '' + self.serialize = lambda x: x.replace(',', '|') self.link_table = (link_table if link_table else 'books_%s_link'%self.metadata['table']) if self.supports_notes and dt == 'rating': # custom ratings table @@ -268,12 +270,16 @@ def item_ids_for_names(self, db, item_names: Iterable[str], case_sensitive: bool item_names = tuple(item_names) if case_sensitive: colname = self.metadata['column'] + serialized_names = tuple(map(self.serialize, item_names)) if self.serialize else item_names if len(item_names) == 1: - iid = db.get(f'SELECT id FROM {self.metadata["table"]} WHERE {colname} = ?', ((item_names[0],)), all=False) + iid = db.get(f'SELECT id FROM {self.metadata["table"]} WHERE {colname} = ?', ((serialized_names[0],)), all=False) return {item_names[0]: iid} inq = ('?,' * len(item_names))[:-1] ans = dict.fromkeys(item_names) - ans.update(db.get(f'SELECT {colname}, id FROM {self.metadata["table"]} WHERE {colname} IN ({inq})', item_names)) + res = db.get(f'SELECT {colname}, id FROM {self.metadata["table"]} WHERE {colname} IN ({inq})', serialized_names) + if self.unserialize: + res = ((self.unserialize(name), iid) for name, iid in res) + ans.update(res) return ans if len(item_names) == 1: q = icu_lower(item_names[0])