0

I'm trying to access the json1 extension in sqlite3 in python 3.6 in linux.

I see from here: https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.enable_load_extension

I can run:

# Load the fulltext search extension
con.execute("select load_extension('./fts3.so')")

# alternatively you can load the extension using an API call:
# con.load_extension("./fts3.so")

So, I assume similar should be possible with:

con.execute("select load_extension('./json1.so')")

If I can track down where that lives. But I cannot find json1.so in the sqlite3 source.

A couple places I have looked for answers:

First

Python - SQLite JSON1 load extension

gcc -g -fPIC -dynamiclib sqlite-src-3140100/ext/misc/json1.c -o json1

Looks good, but source of sqlite no longer contains an /ext/ or /ext/misc/ directory, so I can't compile this myself.

I am downloading via:

curl -O https://www.sqlite.org/2018/sqlite-autoconf-3240000.tar.gz tar -xvzf sqlite-autoconf-3240000.tar.gz

Second

http://charlesleifer.com/blog/using-the-sqlite-json1-and-fts5-extensions-with-python/

I tried this approach, and starts off looking good, but the step where the custom sqlite3 gets called into the python wrapper when re-compiled uses a library that does not support python3:

pysqlite is not supported on Python 3. When using Python 3, use the sqlite3 module from the standard library.

Mittenchops
  • 18,633
  • 33
  • 128
  • 246
  • I'd contact charles leifer for a fix – user1443098 Jul 19 '18 at 20:42
  • How is this question different from the question you linked? – abarnert Jul 19 '18 at 20:43
  • Which question? For the former, there no longer exists /ext or /ext/misc/ in the sqlite source, so it is not clear how to compile myself such that I will have the location of the extension. For the latter, the pysqlite extension does not work with python3. – Mittenchops Jul 19 '18 at 21:02
  • If I do use curl -O https://sqlite.org/2018/sqlite-src-3240000.zip I get sqlite-src-3240000/ext/misc/json1.c:26:10: fatal error: sqlite3ext.h: No such file or directory #include "sqlite3ext.h" ^~~~~~~~~~~~~~ compilation terminated. So I think a lot has changed since 2016. – Mittenchops Jul 19 '18 at 21:19
  • http://charlesleifer.com/blog/compiling-sqlite-for-use-with-python-applications/ – Mittenchops Jul 19 '18 at 22:27
  • If you're compiling the amalgamation version, it comes with the JSON1 extension as part of it. You just have to add the appropriate define when compiling. See [documentation](https://www.sqlite.org/amalgamation.html). – Shawn Jul 20 '18 at 00:03

0 Answers0