On Tue, 30 Mar 2021 07:24:05 -0700 (PDT), Benedikt Rothe wrote:
> Regarding your workaround-suggestions: As a newbie to sqlite I don't
> know the "classic approach". Could you give me a hint?
>
Hi Benedikt,
note that this approch only works on C and C++ and is not available
on Python, Java, PHP and alike that can only support the LOAD_EXTENSION
mechanism.
I see from your code samples that you are well familiar with C/C++,
so in your case it could be a feasible solution.
step 1: initializing SpatiaLite
--------------------------------
immediately after establishing a new connection(sqlite3_open) you
must register the spatialite extension. nothing complex, just
two lines of code.
--------------------
#include <sqlite3.h>
#include <spatialite/gaiageo.h>
#include <spatialite.h>
const char *db_path = "something.sqlite";
int ret;
sqlite3 *handle;
void *cache;
ret = sqlite3_open_v2 (path, &handle, SQLITE_OPEN_READONLY, NULL);
if (ret != SQLITE_OK)
{
... some appropriate error handling ...
}
cache = spatialite_alloc_connection ();
spatialite_init_ex (handle, cache, 0);
--------------------
after this your connection will be able to support
the extened functionalities provided by SpatiaLite.
void *cache simply is an opaque block of memory
internally required by each SpatiaLite enabled
connection.
step 2: finalizing SpatiaLite
--------------------------------
when closing the DB connection you must free the
SpatiaLite's internal cache associated to that
connection.
------------------------
sqlite3_close (handle);
spatialite_cleanup_ex (cache);
------------------------
step 3: building the executable binary
----------------------------------------
you must directly link both libsqlite3 and
libspatialite to your own binary code.
details vary depending on the compiler/linker
you are using. on Linux or MinGW it usually
is something like:
gcc myprog.c -o myprog.exe \
-lspatialite -lsqlite3
it could be eventually required to link all
the other depending libraries such ad GEOS,
PROJ, libxml2 and so on (it's strongly compiler
specific).
usefull resources
---------------------
download the source tarballs and study what
spatialite_gui or the CLI tools do when opening
or closing a DB connection.
even more simple, on the "examples" folder
of libspatialite you'll find several small
C sources (demoX.c) exemplifying all that
is supposed to be needed.
bye Sandro