Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in new get_item_id() db lookup. Names in the authors table … #2445

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/calibre/db/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def __init__(self, name, metadata, link_table=None):
if name == 'authors':
# Legacy
self.unserialize = lambda x: x.replace('|', ',') if x else ''
# Need serialize for get_item_id because in authors, commas become bars
self.serialize = lambda x: x.replace(',', '|') if x else ''
else:
self.serialize = lambda x: x
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
Expand Down Expand Up @@ -269,12 +273,14 @@ def item_ids_for_names(self, db, item_names: Iterable[str], case_sensitive: bool
if case_sensitive:
colname = self.metadata['column']
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} = ?',
((self.serialize(item_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))
return ans
serialized_names = {self.serialize(v) for v in item_names}
ans = dict.fromkeys(serialized_names)
ans.update(db.get(f'SELECT {colname}, id FROM {self.metadata["table"]} WHERE {colname} IN ({inq})', serialized_names))
return {(self.unserialize(k) if self.unserialize else k):v for k,v in ans.items()}
if len(item_names) == 1:
q = icu_lower(item_names[0])
for iid, name in self.id_map.items():
Expand Down
Loading