From b72ab4aa7e891d0d72435e4f8297bcdd0ac6ff33 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 22 Apr 2011 10:58:53 -0600 Subject: [PATCH] Fix #768904 (Changing case only of a title does not update title sort) --- src/calibre/library/database2.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index d7f6c22925..6a94e725a0 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -2002,8 +2002,16 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): return False if isbytestring(title): title = title.decode(preferred_encoding, 'replace') + old_title = self.title(id, index_is_id=True) + # We cannot check if old_title == title as previous code might have + # already updated the cache + only_case_change = icu_lower(old_title) == icu_lower(title) self.conn.execute('UPDATE books SET title=? WHERE id=?', (title, id)) self.data.set(id, self.FIELD_MAP['title'], title, row_is_id=True) + if only_case_change: + # SQLite update trigger will not update sort on a case change + self.conn.execute('UPDATE books SET sort=? WHERE id=?', + (title_sort(title), id)) ts = self.conn.get('SELECT sort FROM books WHERE id=?', (id,), all=False) if ts: