From 3d353816487f3e359bbe20780da43c8a5516752e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 24 Feb 2009 11:50:59 -0800 Subject: [PATCH] Fix #1926 (Author column sorts by original name instead of latest database entry) --- src/calibre/library/database2.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 1e88a670f4..22266487e8 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -916,12 +916,18 @@ class LibraryDatabase2(LibraryDatabase): else: aid = self.conn.execute('INSERT INTO authors(name) VALUES (?)', (a,)).lastrowid try: - self.conn.execute('INSERT INTO books_authors_link(book, author) VALUES (?,?)', (id, aid)) + self.conn.execute('INSERT INTO books_authors_link(book, author) VALUES (?,?)', + (id, aid)) except IntegrityError: # Sometimes books specify the same author twice in their metadata pass + ss = authors_to_sort_string(authors) + self.conn.execute('UPDATE books SET author_sort=? WHERE id=?', + (ss, id)) self.conn.commit() - self.data.set(id, FIELD_MAP['authors'], ','.join([a.replace(',', '|') for a in authors]), row_is_id=True) - self.data.set(id, FIELD_MAP['author_sort'], self.data[self.data.row(id)][FIELD_MAP['authors']], row_is_id=True) + self.data.set(id, FIELD_MAP['authors'], + ','.join([a.replace(',', '|') for a in authors]), + row_is_id=True) + self.data.set(id, FIELD_MAP['author_sort'], ss, row_is_id=True) self.set_path(id, True) if notify: self.notify('metadata', [id])