Recently I started a small project to build an incremental sql database of meta information related to debian packages. In the process I discovered that the newly available feature of sqlite3 to add custom collation doesn’t work well with the sqlite3 bindings present in python 2.5 . The reason is that in order to load a collation at run time, you must explicitly enable the extension loading mechanism. The binding present in python 2.5 (fixed in python 2.6) do not expose this C function.

In order to enable call this function, and instead of patching and recompiling python, I wrote a small python module using swig.

briefly (not tested, but you should get the idea):

import storm.database
import sqlitext

db_url = 'sqlite:db'
database = stm.create_database(db_url)
store = stm.Store(database)
sqlitext.enable_extension(store._connection._raw_connection,1)
store.execute('''SELECT load_extension('./libcollate_debian.so')''')

The code is available here: https://gforge.inria.fr/plugins/scmsvn/viewcvs.php/trunk/torchone/sqlite/?root=sodiac