B4J Library SQLite Enable Loading of Extensions

NOTE this is for B4J only (Erel has stated that you can't enable extension loading on Android/iOS - link)

Small Java library with two methods that enable or disable loading of extensions for SQLite.

  • EnableLoading(SQL) - enable loading of SQLite extensions
  • DisableLoading(SQL) - disable loading of SQLite extensions

You can get some precompiled extensions here.


Extensions must be in the same folder as your JAR (or Objects folder during debug) - alternatively (not tested) you can use the full path when calling load_extension. You must load the correct library for your OS (eg DLL for Windows and SO for Linux)

How to use;

B4X:
Dim SQL As SQL
SQL.InitializeSQLite(File.DirApp,"Test.sqlite",True)

Log(SQL.IsInitialized)

Dim e As EnableSQLiteExtensions

e.EnableLoading(SQL) ' Enable loading
SQL.ExecNonQuery("SELECT load_extension('crypto.dll')") ' Extension should be in the same folder as your JAR or Objects folder
e.DisableLoading(SQL) ' You can disable loading once you have loaded your extension

Log(SQL.ExecQuerySingleResult("select hex(crypto_md5('abc'));"))
 

Attachments

  • EnableSQLiteExtenions.zip
    2.1 KB · Views: 14
Last edited:

aeric

Expert
Licensed User
Longtime User
Hi Trevor,
I tested your example with sqlite-jdbc-3.39.3.0 it works but not work for sqlite-jdbc-3.7.2
B4X:
java.lang.NoClassDefFoundError: org/sqlite/SQLiteConnection
Can you put information on the minimum version?
 

tchart

Well-Known Member
Licensed User
Longtime User
Hi Trevor,
I tested your example with sqlite-jdbc-3.39.3.0 it works but not work for sqlite-jdbc-3.7.2
B4X:
java.lang.NoClassDefFoundError: org/sqlite/SQLiteConnection
Can you put information on the minimum version?
Hey Aeric. I’ll confirm tomorrow. Thanks for posting as I’m using 3.50 and didn’t think to test older versions.
 

aeric

Expert
Licensed User
Longtime User
Hey Aeric. I’ll confirm tomorrow. Thanks for posting as I’m using 3.50 and didn’t think to test older versions.
From Google AI it said minimum is 3.7.15 and it may depends on what extensions.
 

tchart

Well-Known Member
Licensed User
Longtime User
From Google AI it said minimum is 3.7.15 and it may depends on what extensions.
Its a bit vague as its on the Xerial side - SQLite could load extensions since 2006 (3.3.6) if it was compiled with that option.

The JavaDoc for Xerial suggests 3.8.11 as the minimum but the method was changed in 3.18 to use native bindings.

I'd say stick to 3.18 and above.
 
Top