Wrap call to dbapi.check_collection to prevent a forced API change.

This commit is contained in:
John Ralls 2021-07-03 15:45:48 -07:00
parent c177c13f99
commit df270adc94

View File

@ -224,6 +224,16 @@ class DBAPI(DbGeneric):
if self.transaction == None: if self.transaction == None:
self.dbapi.rollback() self.dbapi.rollback()
def _collation(self, locale):
"""
Get the adjusted collation if there is one, falling back on
the locale.collation.
"""
collation = self.dbapi.check_collation(locale)
if collation == None:
return locale.collation
return collation
def transaction_begin(self, transaction): def transaction_begin(self, transaction):
""" """
Transactions are handled automatically by the db layer. Transactions are handled automatically by the db layer.
@ -366,7 +376,7 @@ class DBAPI(DbGeneric):
if sort_handles: if sort_handles:
self.dbapi.execute('SELECT handle FROM person ' self.dbapi.execute('SELECT handle FROM person '
'ORDER BY surname ' 'ORDER BY surname '
'COLLATE "%s"' % self.dbapi.check_collation(locale)) 'COLLATE "%s"' % self._collation(locale))
else: else:
self.dbapi.execute("SELECT handle FROM person") self.dbapi.execute("SELECT handle FROM person")
rows = self.dbapi.fetchall() rows = self.dbapi.fetchall()
@ -397,7 +407,7 @@ class DBAPI(DbGeneric):
'THEN mother.given_name ' + 'THEN mother.given_name ' +
'ELSE father.given_name ' + 'ELSE father.given_name ' +
'END) ' + 'END) ' +
'COLLATE "%s"' % self.dbapi.check_collation(locale)) 'COLLATE "%s"' % self._collation(locale))
self.dbapi.execute(sql) self.dbapi.execute(sql)
else: else:
self.dbapi.execute("SELECT handle FROM family") self.dbapi.execute("SELECT handle FROM family")
@ -426,7 +436,7 @@ class DBAPI(DbGeneric):
if sort_handles: if sort_handles:
self.dbapi.execute('SELECT handle FROM citation ' self.dbapi.execute('SELECT handle FROM citation '
'ORDER BY page ' 'ORDER BY page '
'COLLATE "%s"' % self.dbapi.check_collation(locale)) 'COLLATE "%s"' % self._collation(locale))
else: else:
self.dbapi.execute("SELECT handle FROM citation") self.dbapi.execute("SELECT handle FROM citation")
rows = self.dbapi.fetchall() rows = self.dbapi.fetchall()
@ -445,7 +455,7 @@ class DBAPI(DbGeneric):
if sort_handles: if sort_handles:
self.dbapi.execute('SELECT handle FROM source ' self.dbapi.execute('SELECT handle FROM source '
'ORDER BY title ' 'ORDER BY title '
'COLLATE "%s"' % self.dbapi.check_collation(locale)) 'COLLATE "%s"' % self._collation(locale))
else: else:
self.dbapi.execute("SELECT handle from source") self.dbapi.execute("SELECT handle from source")
rows = self.dbapi.fetchall() rows = self.dbapi.fetchall()
@ -464,7 +474,7 @@ class DBAPI(DbGeneric):
if sort_handles: if sort_handles:
self.dbapi.execute('SELECT handle FROM place ' self.dbapi.execute('SELECT handle FROM place '
'ORDER BY title ' 'ORDER BY title '
'COLLATE "%s"' % self.dbapi.check_collation(locale)) 'COLLATE "%s"' % self._collation(locale))
else: else:
self.dbapi.execute("SELECT handle FROM place") self.dbapi.execute("SELECT handle FROM place")
rows = self.dbapi.fetchall() rows = self.dbapi.fetchall()
@ -492,7 +502,7 @@ class DBAPI(DbGeneric):
if sort_handles: if sort_handles:
self.dbapi.execute('SELECT handle FROM media ' self.dbapi.execute('SELECT handle FROM media '
'ORDER BY desc ' 'ORDER BY desc '
'COLLATE "%s"' % self.dbapi.check_collation(locale)) 'COLLATE "%s"' % self._collation(locale))
else: else:
self.dbapi.execute("SELECT handle FROM media") self.dbapi.execute("SELECT handle FROM media")
rows = self.dbapi.fetchall() rows = self.dbapi.fetchall()
@ -520,7 +530,7 @@ class DBAPI(DbGeneric):
if sort_handles: if sort_handles:
self.dbapi.execute('SELECT handle FROM tag ' self.dbapi.execute('SELECT handle FROM tag '
'ORDER BY name ' 'ORDER BY name '
'COLLATE "%s"' % self.dbapi.check_collation(locale)) 'COLLATE "%s"' % self._collation(locale))
else: else:
self.dbapi.execute("SELECT handle FROM tag") self.dbapi.execute("SELECT handle FROM tag")
rows = self.dbapi.fetchall() rows = self.dbapi.fetchall()