> Behalf Of Thomas Kurz
> Sent: Thursday, April 26, 2018 7:06 AM
> Subject: [sqlite] copmile SQLite with extension?
> 
> I have a project with heavily uses the libsqlitefunctions 
> extension. It is a bit annoying to "select 
> load_extension('...')" for every connection.
> 
> Is it possible to compile an sqlite.dll which already has the 
> extension embedded so that the functions provided can be used 
> without further initialization required?

Here are couple things you might consider:
*  In most of my projects, I statically link the various extensions and
sqlite, rather than load them dynamically.  To do this, you may also need to
make some subtle changes in your extension code.  In particular there is a
difference between SQLITE_EXTENSION_INIT1 and SQLITE_EXTENSION_INIT3 that
determines if the extension code makes calls to bound sqlite code, or
through a 'vtable' provided by the host application.  There is a complier
constant SQLITE_CORE that is meant to be defined if you are linking sqlite
statically, and it can be used to swtich between that behaviour.  E.g., my
extension code starts with this:

#ifndef SQLITE_CORE
#include <sqlite3ext.h>
//declares extern the vtable of all the sqlite3 functions (for loadable
modules only)
SQLITE_EXTENSION_INIT3
#else
#include <sqlite3.h>
#endif

*  you still mention a DLL, though.  Maybe you are putting all of SQLite in
a dll, but want that dll to contain your extension code?  I believe that the
static linking stuff I mention above is still relevant in that case, since
the extension would be statically linked to the sqlite core.

*  even if you link all that stuff statically, you still have to register
your extensions.  Moreover, extensions are associated with databases, and so
(I believe) you are meant to do it again if you ATTACH another db.  In the
'extension in a dll' form, you are meant to export a method under a
well-known name that is used by the load_extension function (you can change
the name, but you'll have to specify it explicitly).  If you statically
link, you will still need to call this registration method explicitly.
There is help in this method:

sqlite3_auto_extension()

Which will invoke your registration function for you, for every attached
database.  This makes it more-or-less transparent when you use the rest of
the sqlite library -- your extensions are just there.

Again, I'm unclear on your question about compiling sqlite.dll, but I am
interpreting that to mean:  "I still want sqlite to be a separate dll for
some reason, rather than statically linking it, but I want that dll to have
sqlite, and my extension, and auto register them so I don't have to."  If
so, I believe all my above statements are accurate:
*  the extension should be treated as statically linked to sqlite with the
relevant changes to some of the SQLITE_EXTENSION_xxx macros.
*  the registration still needs to be performed; you can do that wherever
you're doing other library initialization
*  you can make that registration more transparent by using the
sqlite3_auto_extension() mechanism

HTH

-dave


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to