There is a define called SQLITE_EXTRA_INIT. Make this the name of some code to
run that does an sqlite3_auto_extension to add the extensions that you want to
load in each connection.
eg:
Append the following to the SQLITE3.C file:
/*
** This extension automatically sets the busy_timeout to 5 seconds when loaded
**
** It should be initialized with coreinit.c or other autoextension mechanism
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SQLITE_PRIVATE
#define SQLITE_PRIVATE static
#endif
#ifdef SQLITE_CORE
#include "sqlite3.h"
#else
#ifdef _HAVE_SQLITE_CONFIG_H
#include "config.h"
#endif
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
#endif
#ifdef _WIN32
#ifndef SQLITE_CORE
__declspec(dllexport)
#endif
#endif
#ifdef SQLITE_CORE
static
#endif
int sqlite3_autobusy_init(sqlite3 *db, char **pzErrMsg, const
sqlite3_api_routines *pApi)
{
SQLITE_EXTENSION_INIT2(pApi);
return sqlite3_busy_timeout(db, 5000);
}
#ifdef __cplusplus
}
#endif
which are the extension function(s), and then add code like the following after
that:
int core_init(const char* dummy)
{
int nErr = 0;
nErr += sqlite3_auto_extension((void*)sqlite3_autobusy_init);
return nErr ? SQLITE_ERROR : SQLITE_OK;
}
Then compile the newly generated SQLITE3.C that you have created with
-DSQLITE_EXTRA_INIT=core_init and, of course, -DSQLITE_CORE=1
Viola! Now, every connection will have all the extensions loaded into it. I
add about 30-odd extensions into SQLite this way so that they are always
compiled in and always loaded. You can even generate a shared library
containing the added functions, and you only need to expose the standard
sqlite3_* entry points, the extension entry points are local symbols only.
--
˙uʍop-ǝpısdn sı ɹoʇıuoɯ ɹnoʎ 'sıɥʇ pɐǝɹ uɐɔ noʎ ɟı
> -----Original Message-----
> From: sqlite-users [mailto:[email protected]]
> On Behalf Of David Burgess
> Sent: Monday, 12 June, 2017 18:57
> To: SQLite mailing list
> Subject: Re: [sqlite] Is sqlite3_auto_extension() same compilation unit
> ruled out?
>
> Have a look at the way readfile() and writefile() is implemented in the
> sqlite interpreter.
>
> On Tue, Jun 13, 2017 at 10:38 AM, petern <
> <mailto:[email protected]> [email protected]>
> wrote:
>
> > I have a situation where it would be convenient to locate externally
> > loadable SQLite extension code in the same compilation unit as the
> server
> > code. Is there a way for server main() to load those extensions located
> > within its own compilation unit? Does the necessity of #including both
> > sqlite3.h and sqlite3ext.h with SQLITE_EXTENSION_INIT1 macro rule this
> out?
> >
> > Documentation suggests sqlite3_auto_extension() loads a statically
> linked
> > extension entrypoint but trying this on same compilation unit's
> > sqlite3_extension_init() entrypoint results in segfault.
> >
> > FYI, environment is Linux.
> > _______________________________________________
> > sqlite-users mailing list
> > <mailto:[email protected]>
> > [email protected]
> > <http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users>
> > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> >
> _______________________________________________
> sqlite-users mailing list
> <mailto:[email protected]>
> [email protected]
> <http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users>
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users