From 350c619df11b404e542ec13ebaf2ced48b08b577 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Wed, 5 Aug 2015 11:33:24 +0200 Subject: [PATCH 1/2] Write the "real" series sort value to the existing column in the series table. --- src/calibre/db/schema_upgrades.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/calibre/db/schema_upgrades.py b/src/calibre/db/schema_upgrades.py index 902ade4b97..5083a07a28 100644 --- a/src/calibre/db/schema_upgrades.py +++ b/src/calibre/db/schema_upgrades.py @@ -615,3 +615,28 @@ class SchemaUpgrade(object): self.db.execute(script) + def upgrade_version_21(self): + ''' + Write the series sort into the existing sort column in the series table + ''' + + script = ''' + DROP TRIGGER series_insert_trg; + DROP TRIGGER series_update_trg; + + UPDATE series SET sort=title_sort(name); + + CREATE TRIGGER series_insert_trg + AFTER INSERT ON series + BEGIN + UPDATE series SET sort=title_sort(NEW.name) WHERE id=NEW.id; + END; + + CREATE TRIGGER series_update_trg + AFTER UPDATE ON series + BEGIN + UPDATE series SET sort=title_sort(NEW.name) WHERE id=NEW.id; + END; + ''' + self.db.execute(script) + From 2e6f3898baf7e5d8c208183bf8c9aa8f6e3b30a2 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Wed, 5 Aug 2015 12:09:47 +0200 Subject: [PATCH 2/2] drop the trigger only if it exists --- src/calibre/db/schema_upgrades.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/db/schema_upgrades.py b/src/calibre/db/schema_upgrades.py index 5083a07a28..bfa9c5bc83 100644 --- a/src/calibre/db/schema_upgrades.py +++ b/src/calibre/db/schema_upgrades.py @@ -621,8 +621,8 @@ class SchemaUpgrade(object): ''' script = ''' - DROP TRIGGER series_insert_trg; - DROP TRIGGER series_update_trg; + DROP TRIGGER IF EXISTS series_insert_trg; + DROP TRIGGER IF EXISTS series_update_trg; UPDATE series SET sort=title_sort(name);