isScriptFile ramifications for SQLITE_EXTRA_INIT
(1) By David Jones (vman59) on 2026-04-22 20:39:01 [source]
A side-effect of 3.53's support for testing if a file is a script rather than a database is that an SQLITE_EXTRA_INIT function you've added to the CLI can be called multiple times. For reason's not clear to me, isScriptFile() initializes sqlite3 to do a test open of the candidate file and then calls sqlite3_shutdown().
The shell.c program never called sqlite3_shutdown() before, so its presence in isScriptFile() makes the first subsequent call to sqlite3_initialize() start over and call SQLITE_EXTRA_INIT again. It's something you can deal with, but it was a surprise to see it.
(2) By Stephan Beal (stephan) on 2026-04-23 11:53:37 in reply to 1 [link] [source]
isScriptFile ramifications for SQLITE_EXTRA_INIT
After having discussed this with the team...
That behavior change was not specifically intentional, but we believe it to be correct, in the sense that (A) sqlite3_initialize() and sqlite3_shutdown() are intended to be used in pairs1 and (B) a client which implements SQLITE_EXTRA_INIT also needs to implement SQLITE_EXTRA_SHUTDOWN if their extension is to be well-behaved in the face of multiple init/shutdown calls.
For reason's not clear to me, isScriptFile() initializes sqlite3 ...
The shell has to account for libraries built with OMIT_AUTOINIT, thus it explicitly calls sqlite3_initialize(). isScriptFile() calls into sqlite3_open_v2() to determine whether a given filename argument is a database or not, which necessitates initializing the library, but the shell's own requirements call for the library being in a clean state after that point, thus isScriptFile() may (depending on where it's called) call sqlite3_shutdown().
Neither SQLITE_EXTRA_INIT nor SQLITE_EXTRA_SHUTDOWN have been formally documented, in that they appear neither in sqlite3.h nor in the website documentation, so we do not consider this to be a backwards-compatibility break.
- ^ That's a simplification. The full details are in www:/c3ref/initialize.html