Skip to content

Add extension loading support - #1525

Open
fnc12 wants to merge 3 commits into
devfrom
feature/load-extension
Open

Add extension loading support#1525
fnc12 wants to merge 3 commits into
devfrom
feature/load-extension

Conversation

@fnc12

@fnc12 fnc12 commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • storage.enable_load_extension(bool) — toggles extension loading through sqlite3_db_config's SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION option, which enables the C API while deliberately leaving the load_extension() SQL function disabled, as recommended for security. Returns the C API result code.
  • storage.load_extension(file[, entryPoint]) — wraps sqlite3_load_extension, propagating its error message (e.g. the dlopen failure text) in the thrown std::system_error.

No wrapper for the load_extension() SQL function — deliberate, per the security recommendation above.

Availability gate

Both wrappers sit behind a new SQLITE_ORM_LOAD_EXTENSION_SUPPORTED macro in functional/sqlite3_config.h (next to SQLITE_ORM_JSON_SUPPORTED): on unless SQLite was built with SQLITE_OMIT_LOAD_EXTENSION, and off on Apple platforms by default — Apple's system SQLite strips sqlite3_load_extension from both the library and its header without defining the omit macro (while still shipping sqlite3ext.h, so no __has_include telltale exists). Building against an unrestricted SQLite on Apple (Homebrew, vcpkg) can be declared with SQLITE_ORM_ENABLE_LOAD_EXTENSION.

Testing

  • New load extension test: the load of an inexistent file must fail with a translated error both with loading disabled (default) and enabled. The assertion is deliberately just REQUIRE_THROWS_AS, since Debian-family SQLite builds enable the C API by default, changing which error fires.
  • Verified the wrappers empirically against Homebrew SQLite 3.53.3 on macOS (not authorized → enable → dlopen error propagated → disable) and Ubuntu's system SQLite on Linux.
  • Full unit test suite passes; all examples build.

🤖 Generated with Claude Code

storage.enable_load_extension() toggles extension loading via
SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, which deliberately leaves the
load_extension() SQL function disabled, as recommended for security.
storage.load_extension() wraps sqlite3_load_extension and surfaces its
error message in the thrown std::system_error.

Both are gated by SQLITE_ORM_LOAD_EXTENSION_SUPPORTED: on unless SQLite
was built with SQLITE_OMIT_LOAD_EXTENSION, and off on Apple platforms,
whose system SQLite strips the API from the header without defining the
omit macro - building against an unrestricted SQLite there can be
declared with SQLITE_ORM_ENABLE_LOAD_EXTENSION.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@fnc12
fnc12 marked this pull request as draft September 7, 2026 12:57
fnc12 and others added 2 commits September 7, 2026 18:08
Like the journal mode, the setting set by enable_load_extension() is now
stored on the storage and re-applied to every connection it opens, so it
works with on-demand connections, not only with open_forever() ones.

Also cover the success path: series.c is additionally built as a
run-time loadable extension (except on Apple platforms, whose system
SQLite omits the loading API), and a new test loads it - with both a
derived and an explicit entry point - and queries generate_series
through it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The wrapper .c file tripped over the clang-format lint, whose
configuration supports only C++. A subdirectory achieves the same
isolation from the SQLITE_CORE source file property without it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@fnc12
fnc12 requested a review from trueqbit September 7, 2026 13:45
@fnc12
fnc12 marked this pull request as ready for review September 7, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant