From f75aa9302a021e8f96f1465f8d9fbe8c4049fd81 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Thu, 1 Jul 2021 11:45:23 -0700 Subject: [PATCH] Always use filtered collation names. Store the Sqlite3 collations in the __collations array to short-circuit re-creation. Fixes https://gramps-project.org/bugs/view.php?id=12343. --- gramps/plugins/db/dbapi/dbapi.py | 35 +++++++------------------------ gramps/plugins/db/dbapi/sqlite.py | 2 ++ 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/gramps/plugins/db/dbapi/dbapi.py b/gramps/plugins/db/dbapi/dbapi.py index 40e71655f..007978b46 100644 --- a/gramps/plugins/db/dbapi/dbapi.py +++ b/gramps/plugins/db/dbapi/dbapi.py @@ -364,12 +364,9 @@ class DBAPI(DbGeneric): :type locale: A GrampsLocale object. """ if sort_handles: - if locale != glocale: - self.dbapi.check_collation(locale) - self.dbapi.execute('SELECT handle FROM person ' 'ORDER BY surname ' - 'COLLATE "%s"' % locale.get_collation()) + 'COLLATE "%s"' % self.dbapi.check_collation(locale)) else: self.dbapi.execute("SELECT handle FROM person") rows = self.dbapi.fetchall() @@ -386,9 +383,6 @@ class DBAPI(DbGeneric): :type locale: A GrampsLocale object. """ if sort_handles: - if locale != glocale: - self.dbapi.check_collation(locale) - sql = ('SELECT family.handle ' + 'FROM family ' + 'LEFT JOIN person AS father ' + @@ -403,7 +397,7 @@ class DBAPI(DbGeneric): 'THEN mother.given_name ' + 'ELSE father.given_name ' + 'END) ' + - 'COLLATE "%s"' % locale.get_collation()) + 'COLLATE "%s"' % self.dbapi.check_collation(locale)) self.dbapi.execute(sql) else: self.dbapi.execute("SELECT handle FROM family") @@ -430,12 +424,9 @@ class DBAPI(DbGeneric): :type locale: A GrampsLocale object. """ if sort_handles: - if locale != glocale: - self.dbapi.check_collation(locale) - self.dbapi.execute('SELECT handle FROM citation ' 'ORDER BY page ' - 'COLLATE "%s"' % locale.get_collation()) + 'COLLATE "%s"' % self.dbapi.check_collation(locale)) else: self.dbapi.execute("SELECT handle FROM citation") rows = self.dbapi.fetchall() @@ -452,12 +443,9 @@ class DBAPI(DbGeneric): :type locale: A GrampsLocale object. """ if sort_handles: - if locale != glocale: - self.dbapi.check_collation(locale) - self.dbapi.execute('SELECT handle FROM source ' 'ORDER BY title ' - 'COLLATE "%s"' % locale.get_collation()) + 'COLLATE "%s"' % self.dbapi.check_collation(locale)) else: self.dbapi.execute("SELECT handle from source") rows = self.dbapi.fetchall() @@ -474,12 +462,9 @@ class DBAPI(DbGeneric): :type locale: A GrampsLocale object. """ if sort_handles: - if locale != glocale: - self.dbapi.check_collation(locale) - self.dbapi.execute('SELECT handle FROM place ' 'ORDER BY title ' - 'COLLATE "%s"' % locale.get_collation()) + 'COLLATE "%s"' % self.dbapi.check_collation(locale)) else: self.dbapi.execute("SELECT handle FROM place") rows = self.dbapi.fetchall() @@ -505,12 +490,9 @@ class DBAPI(DbGeneric): :type locale: A GrampsLocale object. """ if sort_handles: - if locale != glocale: - self.dbapi.check_collation(locale) - self.dbapi.execute('SELECT handle FROM media ' 'ORDER BY desc ' - 'COLLATE "%s"' % locale.get_collation()) + 'COLLATE "%s"' % self.dbapi.check_collation(locale)) else: self.dbapi.execute("SELECT handle FROM media") rows = self.dbapi.fetchall() @@ -536,12 +518,9 @@ class DBAPI(DbGeneric): :type locale: A GrampsLocale object. """ if sort_handles: - if locale != glocale: - self.dbapi.check_collation(locale) - self.dbapi.execute('SELECT handle FROM tag ' 'ORDER BY name ' - 'COLLATE "%s"' % locale.get_collation()) + 'COLLATE "%s"' % self.dbapi.check_collation(locale)) else: self.dbapi.execute("SELECT handle FROM tag") rows = self.dbapi.fetchall() diff --git a/gramps/plugins/db/dbapi/sqlite.py b/gramps/plugins/db/dbapi/sqlite.py index f27fe8e32..1d22a5719 100644 --- a/gramps/plugins/db/dbapi/sqlite.py +++ b/gramps/plugins/db/dbapi/sqlite.py @@ -117,6 +117,8 @@ class Connection: collation = locale.get_collation().translate(self.__tmap) if collation not in self.__collations: self.__connection.create_collation(collation, locale.strcoll) + self.__collations.append(collation) + return collation def execute(self, *args, **kwargs): """