In SQLite, it is necessary to use an extension library to use mathematical functions and statistical functions, but it was a little devised to use it from Pyramid.
Download extension-functions.c from the following URL.
gcc -fPIC -shared /home/takaki/Desktop/extension-functions.c -o libsqlitefunctions.so
If you can start sqlite and do the following, the extension library is OK.
$ sqlite3
SQLite version 3.13.0 2016-05-18 10:57:30
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> select load_extension('./libsqlitefunctions.so');
sqlite> select sin(3.14/2);
0.999999682931835
sqlite>
Make the following changes from the normal template file.
model/__init__.py
def get_session_factory(engine):
@event.listens_for(engine, "connect")
def connect(dbapi_connection, connection_rec):
dbapi_connection.enable_load_extension(True)
dbapi_connection.execute("SELECT load_extension('{0}');".format(FULL_PATH_OF_LIB))
factory = sessionmaker()
factory.configure(bind=engine)
return factory
Recommended Posts