On Friday, 31 January, 2020 17:59, Peng Yu <pengyu...@gmail.com> wrote:
>How to use extension-functions.c? It means that I have to compile it? Yes. Either as a loadable extension or as core builtin functions extending the amalgamation. >How to use it with python? db.load_extension(<file name containing the compiled extension load library>) for each connection db into which you want to load the extension. >For python, create_function should be a better solution? Thanks. Mayhaps yes, mayhaps no. Depends on your definition of "better". If you mean "simpler" then the answer is yes. If you mean many orders of magnitude slower than the C version, then the answer is also yes. >>> import sqlite3 >>> db=sqlite3.connect(':memory:') >>> def log(*arg): ... from math import log ... return log(*arg) ... >>> db.create_function('log', -1, log) >>> import math >>> db.execute('select log(1000)').fetchone() (6.907755278982137,) >>> math.log(1000) 6.907755278982137 >>> db.execute('select log(1000,10)').fetchone() (2.9999999999999996,) >>> math.log(1000,10) 2.9999999999999996 >>> db.execute('select log(1000,2)').fetchone() (9.965784284662087,) >>> math.log(1000,2) 9.965784284662087 sqlite3 also does not let you set a function as deterministic, while APSW does, functions defined in python using the sqlite3 wrapper are somewhat limited in where you can use them. APSW also lets you write virtual tables and vfs's in python, should you wish. I don't think sqlite3 can do that. -- The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume. _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users