Trying to use Spatialite in a Rust binary.
I read in the
installation/usage instructions that it is enough to link libspatialite
against the binary from which you wish to use it, and its SQL functions
are then available to you if libsqlite3 is also present and linked. Is
bool bCreateSpatialiteDb=true;
int i_rc = sqlite3_open_v2( filename, psqlite_handle, flags, zVfs ); if ( i_rc == SQLITE_OK ) { // avoid 'not authorized' error sqlite3_enable_load_extension( sqlite_handle, 1 ); // always returns SQLITE_OK
// activating Foreign Key constraints [needed for proper internal spatialite support for admin tables (CASCADE)] ( void )sqlite3_exec( sqlite_handle, "PRAGMA foreign_keys = 1", nullptr, 0, nullptr ); QString sExtension = QStringLiteral( "mod_spatialite" );
i_rc = sqlite3_load_extension( sqlite_handle, sExtension.toUtf8().constData(), nullptr, &errMsg );
if ( i_rc == SQLITE_OK ) { // Spatialite is now active and usable [libspatialite.so/mod_libspatialite.so has been found]
if (bCreateSpatialiteDb)
{
char *errMsg = nullptr;
if ( sqlite3_exec( dbSqliteHandle(), "InitSpatialMetaData(1)", nullptr, nullptr, &errMsg ) == SQLITE_OK ) {
// The needed Spatialite Database Metadata has been created
}
} } }
that true, or am I expected to call any functions to initialize it first?
Just curious--I don't see libspatialite.so in output of running ldd on
my binary. So for now I'm thinking this is a rustc issue and am
preparing to follow up there, but I want to be sure that all I need to
do is link the library if I only want to use the SQL functions.
Thanks.
Thanks! My interest is in linking with libspatialite rather than
using an extension. It looks like, in that case, you do have to
call a function to initialize the library. I thought that linking
would somehow make the spatial SQL functions available to the
embedded SQLite. I just want to use enough of the API to make the
SQL functions available, then use the functions from SQL.
A Rust binary is a binary of an application written in the Rust
programming language. https://www.rust-lang.org
--
You received this message because you are subscribed to the Google Groups "SpatiaLite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spatialite-use...@googlegroups.com.
To post to this group, send email to spatiali...@googlegroups.com.
Visit this group at https://groups.google.com/group/spatialite-users.
For more options, visit https://groups.google.com/d/optout.
Nice. I'd prefer the link option for easier deployment as well. So it looks like you do have to call a function in the Spatialite API to make the functions available to queries.
Is the source of your spatialite crate available anywhere? I was thinking of building a spatialite-sys crate for this purpose, though I had no idea how large the API surface is.
Thanks.
Nice. I'd prefer the link option for easier deployment as well. So it looks like you do have to call a function in the Spatialite API to make the functions available to queries.
Is the source of your spatialite crate available anywhere? I was thinking of building a spatialite-sys crate for this purpose, though I had no idea how large the API surface is.
but it surely is a very (very) bad idea on
Android and on any other Unix-like platform, because it
will negate all the many benefits deriving from the
centralized distribution of standard packages (that is
almost fully based on dynamic libraries).
2. loading spatialite as a dynamic extension to SQLite (via
the "load_extension" SQL call) surely is the cleanest,
simplest and safest mechanism you can adopt in order to
achieve a real and effective cross-platform portability.
Did I miss your build.rs? Couldn't find it, though I'm still a
bit coffee-deprived this morning. :)
In any case, I knocked this together:
https://gitlab.com/ndarilek/spatialite-sys
Links directly against libspatialite dynamically, with a pkg-config fallback where present. Is that basically what you did as well? I'm wondering if I need any extra munging in build.rs.
I understand there's still higher level work to do. My intent with this is to package away the spatialite linking/dependency in a separate crate so higher-level apps don't need to concern themselves with that. Even though it is only a few lines of integration work, it probably makes sense to standardize on these lower-level building blocks where possible, then build higher-level adapters to rusqlite and others as needed.
Thanks.
Did I miss your build.rs? Couldn't find it, though I'm still a bit coffee-deprived this morning. :)
In any case, I knocked this together:
https://gitlab.com/ndarilek/spatialite-sys
Links directly against libspatialite dynamically, with a pkg-config fallback where present. Is that basically what you did as well? I'm wondering if I need any extra munging in build.rs.
I understand there's still higher level work to do. My intent with this is to package away the spatialite linking/dependency in a separate crate so higher-level apps don't need to concern themselves with that. Even though it is only a few lines of integration work, it probably makes sense to standardize on these lower-level building blocks where possible, then build higher-level adapters to rusqlite and others as needed.