]> git.phdru.name Git - m_librarian.git/commitdiff
Add unicode-aware function 'lower()' to SQLite
authorOleg Broytman <phd@phdru.name>
Sun, 27 Mar 2016 21:12:11 +0000 (00:12 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 27 Mar 2016 21:12:11 +0000 (00:12 +0300)
m_librarian/db.py

index 99a2843aa42f3ad5f347a86efaecde0b30b6a1d5..cd2f6442582a99e60f46bbd84969f3063be053ef 100755 (executable)
@@ -45,6 +45,18 @@ if not db_uri:
 sqlhub.processConnection = connection = connectionForURI(db_uri)
 
 if connection.dbName == 'sqlite':
+    def lower(s):
+        return s.lower()
+
+    sqlite = connection.module
+
+    class MLConnection(sqlite.Connection):
+        def __init__(self, *args, **kwargs):
+            super(MLConnection, self).__init__(*args, **kwargs)
+            self.create_function('lower', 1, lower)
+
+    connection._connOptions['factory'] = MLConnection
+
     # Speedup SQLite connection
     connection.query("PRAGMA synchronous=OFF")
     connection.query("PRAGMA count_changes=OFF")