You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are several reasonably popular sqlite library modifications with certain features on top: e.g., sqlcipher with encryption. They are drop-in compatible with the basic sqlite.
It would be useful to let the user choose another library when opening a database in SQLite.jl.
Currently, to use sqlcipher I just forked SQLite.jl, changed the jll library name, and renamed the package to SQLCipher (registered). The only relevant change is: replace using SQLite_jll with using SQLCipher_jll: libsqlcipher as libsqlite.
I imagine something like SQLite.DB("filename", libsqlite=...) should be possible somehow, but not totally sure...
This is tricky because we have to hard-code dependencies to make them useable and performant. I don't have major issues with making changes to the core sqlite_jll package if it's not disruptive for normal cases and just making some of these features the "default" for everyone. We did that w/ a few features already like thread safety.
The problem w/ passing it as a keyword arg is that there are some dozens, maybe even hundreds of places where you'd have to support and plumb through passing a custom sqlite library. Having your own fork that makes the change is also not unreasonable, honestly. If other's start asking for the same functionality, we could possibly even register; it would just be slightly annoying to keep the SQLCipher up to date w/ changes that happen here.
Another idea is that we just take both binary packages as dependencies in SQLite and then bake the library selection into a global Ref that each ccall would check. We do something slightly similar in ODBC.jl for letting users use different odbc libraries (and taking all possible choices as dependencies). I'd be open to something like that as long as the extra dependencies seem to warrant it.
we have to hard-code dependencies to make them useable and performant
That's my understanding of the current state as well. Unfortunately, this loses a major feature of dynamic libraries: they can naturally be replaceable by other libraries having the same interface, at runtime.
I don't have major issues with making changes to the core sqlite_jll package if it's not disruptive for normal cases and just making some of these features the "default" for everyone
sqlcipher is a separate library based on a specific sqlite version, not just a compilation option.
I don't have major issues with making changes to the core sqlite_jll package if it's not disruptive for normal cases and just making some of these features the "default" for everyone
Some of the sqlite extensions are proprietary, not open source (Example)-- so this is unfortunately not possible in many cases.
I'd also like this functionality, but yes, I don't see an easy way to achieve this.
Revisiting this — modern JLLWrappers + Preferences.jl already solve the drop-in case (sqlcipher, SEE) with zero code changes to SQLite.jl, which sidesteps both concerns raised here: no kwarg to plumb through the ccall sites, and it works for proprietary closed-source libs too since the user points at their own .so.
SQLite_jll resolves libsqlite at load time via a libsqlite_path preference. Add to your project's LocalPreferences.toml:
Verified end-to-end (Julia 1.11, SQLite_jll 3.51.2): with the shipped lib, SELECT sqlite_version() returns 3.51.2; after pointing libsqlite_path at a different system libsqlite (3.45.1), the same query returns 3.45.1, and /proc/<pid>/maps confirms only the overridden .so is mapped. The dlopen is on the literal path, so the override file can be named libsqlcipher.so — no SONAME rename needed.
Caveats: it's per-environment (one engine per process, not per-DB()), editing the preference triggers one recompile, and the target must be ABI-compatible with the sqlite3 C API (sqlcipher/SEE are by design). But for "I want this project to use sqlcipher/SEE instead of stock sqlite," this covers it.
If that matches the intent here, happy to send a short docs PR (a "Using an alternative SQLite library" section) rather than any invasive change.
per-environment is quite limiting...
and not sure I understand how exactly it looks from user PoV: say I install SQLite.jl and SQLCipher_jll, how to use the latter then?
Following up on the earlier LocalPreferences.toml override note — that one used a system-libsqlite3 version swap to prove the mechanism. I've now upgraded it to real SQLCipher, built from source, with
encryption actually exercised end-to-end through unmodified SQLite.jl.
Setup — built SQLCipher from source (community 4.16.0, SQLite core 3.53.1, OpenSSL provider) and
pointed SQLite.jl at it with nothing but:
(file encrypted.db → data, and the header is different every time — SQLCipher salt randomization.)
No key ⇒ locked out — reopening and querying without PRAGMA key throws:
SQLiteException("file is not a database")
With key ⇒ rows decrypt — reopen, PRAGMA key='...', and all rows read back intact.
Interop — the file SQLite.jl wrote is read back by the standalone sqlcipher CLI with the same key,
and rejected without it.
I also confirmed the live library is genuinely SQLCipher via Libdl.dlopen(..., RTLD_NOLOAD) + Libdl.dlpath (resolves to the SQLCipher .so) and by resolving the SQLCipher-exclusive symbol sqlcipher_codec_pragma through that handle; a stock-SQLite_jll control shows none of these
(no cipher_version, no libcrypto mapped, no sqlcipher_* symbols).
Two small gotchas worth recording: (1) changing libsqlite_path auto-triggers SQLite_jll
precompilation — no manual cache clearing needed to swap engines; (2) PRAGMA key ordering matters —
it must be the first statement after opening.
Net: [SQLite_jll] libsqlite_path is a clean, code-change-free way to run SQLite.jl on a SQLCipher
drop-in with full transparent encryption.
Yes, my ai drafted the walkthrough for me, I thought you were asking for one. I cant's tell if your objection was aimed at lack of brevity or you are questioning the solution aproach itself? I tested it locally first before posting.
TLDR - [SQLite_jll] libsqlite_path in LocalPreferences.toml does what your SQLCipher fork does, without the fork - PRAGMA cipher_version returns 4.16.0 through unmodified SQLite.jl. Happy to send a docs PR or test a different approach.
Thanks @JohnCobbler, the preference route is the right answer here: setting libsqlite_path under [SQLite_jll] in LocalPreferences.toml points SQLite.jl at another SQLite build, such as SQLCipher, with no change to SQLite.jl. A short section in the docs showing that would be welcome as a PR from anyone. Closing the issue, since no code change is needed.
I still don't understand how that would work in practice. A actual concrete explanation would help!
For the simplest scenario: say I have a package that needs sqlcipher. What exactly do I put in that package so users install it as ]add MyPackage and everything works properly?
Sorry for the slow response here. Yeah, the ability to use preferences would work in a specific Project environment/app, but wouldn't work for a case where you wanted your package to use a certain sqlite lib for any downstream users. i.e. it's end-user-controlled. Not sure if that's the case you're asking for @aplavin, but I assume so. For that case to work, we'd need to make the sqlite lib string be configurable, probably as a field in the SQLite.DB struct, defaulitng to sqlite_jll. I think that should work. I'll have my bot post the example of how you can use teh Preferences approach for end-users.
This writes a LocalPreferences.toml next to the project's Project.toml. Restart Julia. From then on, plain using SQLite in that project runs on SQLCipher:
julia>using SQLite
julia> db = SQLite.DB("secret.db");
julia> DBInterface.execute(db, "PRAGMA key = 'my key'"); # must be the first statement
Tested on macOS with Julia 1.12, SQLite.jl 1.11.0 and SQLCipher_jll 4.13.0: PRAGMA cipher_version returns 4.13.0 community, the file on disk has no SQLite format 3 header, and reading it without the key fails with "file is not a database".
Limits:
It applies to every SQLite.DB in the process.
The stored path is specific to the machine. Re-run the set_preferences! line after updating SQLCipher_jll, or it keeps pointing at the old build.
SQLite_jll has to be listed in the project (hence the add line), because Julia only reads preferences for packages the project lists.
Yes that's what I thought as well – not really convenient... Will continue using SQLCipher.jl then, very unfortunate but apparently unavoidable duplication of code: it's literally the SQLite.jl package, just with library switched.
Let me throw some tokens at what it would look like to make that configurable. We've had this kind of problem with HTTP before around how to "bake in" middleware client-side in downstream libraries. We finally settled on the HTTP.@client macro, which essentially provides your own package's HTTP "verbs", but with your own layers baked in. e.g. you get AWS.get, AWS.post, AWS.put, etc. So it "feels" HTTP-like, basically the same interface, but you get to get the customized stack.
Would something like that work in your case? either via a wrapper struct or via interface methods? If you can help me settle on what would work, I feel like we could adapt SQLite to probably make it work.
Idk, something like SQLite.DB(<path>, library=<library path>) maybe? Default = from sqlite_jll, but if user installs sqlcipher_jll, they can just pass library path from it.
Activity
quinnj commentedon Oct 20, 2021
This is tricky because we have to hard-code dependencies to make them useable and performant. I don't have major issues with making changes to the core sqlite_jll package if it's not disruptive for normal cases and just making some of these features the "default" for everyone. We did that w/ a few features already like thread safety.
The problem w/ passing it as a keyword arg is that there are some dozens, maybe even hundreds of places where you'd have to support and plumb through passing a custom sqlite library. Having your own fork that makes the change is also not unreasonable, honestly. If other's start asking for the same functionality, we could possibly even register; it would just be slightly annoying to keep the SQLCipher up to date w/ changes that happen here.
Another idea is that we just take both binary packages as dependencies in SQLite and then bake the library selection into a global
Refthat eachccallwould check. We do something slightly similar in ODBC.jl for letting users use different odbc libraries (and taking all possible choices as dependencies). I'd be open to something like that as long as the extra dependencies seem to warrant it.aplavin commentedon Oct 20, 2021
That's my understanding of the current state as well. Unfortunately, this loses a major feature of dynamic libraries: they can naturally be replaceable by other libraries having the same interface, at runtime.
sqlcipher is a separate library based on a specific sqlite version, not just a compilation option.
aviks commentedon Jan 10, 2022
Some of the sqlite extensions are proprietary, not open source (Example)-- so this is unfortunately not possible in many cases.
I'd also like this functionality, but yes, I don't see an easy way to achieve this.
JohnCobbler commentedon Jun 4, 2026
Revisiting this — modern
JLLWrappers+Preferences.jlalready solve the drop-in case (sqlcipher, SEE) with zero code changes to SQLite.jl, which sidesteps both concerns raised here: no kwarg to plumb through theccallsites, and it works for proprietary closed-source libs too since the user points at their own.so.SQLite_jllresolveslibsqliteat load time via alibsqlite_pathpreference. Add to your project'sLocalPreferences.toml:Verified end-to-end (Julia 1.11, SQLite_jll 3.51.2): with the shipped lib,
SELECT sqlite_version()returns3.51.2; after pointinglibsqlite_pathat a different system libsqlite (3.45.1), the same query returns3.45.1, and/proc/<pid>/mapsconfirms only the overridden.sois mapped. Thedlopenis on the literal path, so the override file can be namedlibsqlcipher.so— no SONAME rename needed.Caveats: it's per-environment (one engine per process, not per-
DB()), editing the preference triggers one recompile, and the target must be ABI-compatible with the sqlite3 C API (sqlcipher/SEE are by design). But for "I want this project to use sqlcipher/SEE instead of stock sqlite," this covers it.If that matches the intent here, happy to send a short docs PR (a "Using an alternative SQLite library" section) rather than any invasive change.
aplavin commentedon Jun 4, 2026
per-environment is quite limiting...
and not sure I understand how exactly it looks from user PoV: say I install SQLite.jl and SQLCipher_jll, how to use the latter then?
JohnCobbler commentedon Jun 4, 2026
Following up on the earlier
LocalPreferences.tomloverride note — that one used a system-libsqlite3version swap to prove the mechanism. I've now upgraded it to real SQLCipher, built from source, with
encryption actually exercised end-to-end through unmodified SQLite.jl.
Setup — built SQLCipher from source (community
4.16.0, SQLite core 3.53.1, OpenSSL provider) andpointed SQLite.jl at it with nothing but:
Engine identity (the smoking gun) — stock SQLite returns zero rows for
PRAGMA cipher_version;through the override it returns the cipher version:
Encryption round-trips through the normal SQLite.jl API.
PRAGMA keymust come first, before anyschema/DML:
Results:
SQLite format 3\0magic:file encrypted.db→data, and the header is different every time — SQLCipher salt randomization.)PRAGMA keythrows:PRAGMA key='...', and all rows read back intact.sqlcipherCLI with the same key,and rejected without it.
I also confirmed the live library is genuinely SQLCipher via
Libdl.dlopen(..., RTLD_NOLOAD)+Libdl.dlpath(resolves to the SQLCipher.so) and by resolving the SQLCipher-exclusive symbolsqlcipher_codec_pragmathrough that handle; a stock-SQLite_jllcontrol shows none of these(no
cipher_version, nolibcryptomapped, nosqlcipher_*symbols).Two small gotchas worth recording: (1) changing
libsqlite_pathauto-triggersSQLite_jllprecompilation — no manual cache clearing needed to swap engines; (2)
PRAGMA keyordering matters —it must be the first statement after opening.
Net:
[SQLite_jll] libsqlite_pathis a clean, code-change-free way to run SQLite.jl on a SQLCipherdrop-in with full transparent encryption.
aplavin commentedon Jun 4, 2026
seems like pure llm comments
JohnCobbler commentedon Jun 5, 2026
Yes, my ai drafted the walkthrough for me, I thought you were asking for one. I cant's tell if your objection was aimed at lack of brevity or you are questioning the solution aproach itself? I tested it locally first before posting.
TLDR - [SQLite_jll] libsqlite_path in LocalPreferences.toml does what your SQLCipher fork does, without the fork - PRAGMA cipher_version returns 4.16.0 through unmodified SQLite.jl. Happy to send a docs PR or test a different approach.
quinnj-bot commentedon Nov 18, 2026
Thanks @JohnCobbler, the preference route is the right answer here: setting
libsqlite_pathunder[SQLite_jll]inLocalPreferences.tomlpoints SQLite.jl at another SQLite build, such as SQLCipher, with no change to SQLite.jl. A short section in the docs showing that would be welcome as a PR from anyone. Closing the issue, since no code change is needed.[comment generated via AI]
aplavin commentedon Nov 18, 2026
I still don't understand how that would work in practice. A actual concrete explanation would help!
For the simplest scenario: say I have a package that needs sqlcipher. What exactly do I put in that package so users install it as
]add MyPackageand everything works properly?quinnj commentedon Nov 21, 2026
Sorry for the slow response here. Yeah, the ability to use preferences would work in a specific Project environment/app, but wouldn't work for a case where you wanted your package to use a certain sqlite lib for any downstream users. i.e. it's end-user-controlled. Not sure if that's the case you're asking for @aplavin, but I assume so. For that case to work, we'd need to make the sqlite lib string be configurable, probably as a field in the
SQLite.DBstruct, defaulitng to sqlite_jll. I think that should work. I'll have my bot post the example of how you can use teh Preferences approach for end-users.quinnj-bot commentedon Nov 21, 2026
Here's the end-user Preferences setup Jacob mentioned. In the project or app environment that should use SQLCipher:
This writes a
LocalPreferences.tomlnext to the project'sProject.toml. Restart Julia. From then on, plainusing SQLitein that project runs on SQLCipher:Tested on macOS with Julia 1.12, SQLite.jl 1.11.0 and SQLCipher_jll 4.13.0:
PRAGMA cipher_versionreturns4.13.0 community, the file on disk has noSQLite format 3header, and reading it without the key fails with "file is not a database".Limits:
SQLite.DBin the process.set_preferences!line after updatingSQLCipher_jll, or it keeps pointing at the old build.SQLite_jllhas to be listed in the project (hence theaddline), because Julia only reads preferences for packages the project lists.[comment generated via AI]
aplavin commentedon Nov 21, 2026
Yes that's what I thought as well – not really convenient... Will continue using SQLCipher.jl then, very unfortunate but apparently unavoidable duplication of code: it's literally the SQLite.jl package, just with library switched.
quinnj commentedon Nov 22, 2026
Let me throw some tokens at what it would look like to make that configurable. We've had this kind of problem with HTTP before around how to "bake in" middleware client-side in downstream libraries. We finally settled on the
HTTP.@clientmacro, which essentially provides your own package's HTTP "verbs", but with your own layers baked in. e.g. you getAWS.get,AWS.post,AWS.put, etc. So it "feels" HTTP-like, basically the same interface, but you get to get the customized stack.Would something like that work in your case? either via a wrapper struct or via interface methods? If you can help me settle on what would work, I feel like we could adapt SQLite to probably make it work.
aplavin commentedon Nov 22, 2026
Idk, something like
SQLite.DB(<path>, library=<library path>)maybe? Default = from sqlite_jll, but if user installs sqlcipher_jll, they can just pass library path from it.