Skip to content

Add support for overriding the entrypoint for sqlite3_load_extension() #261

@weitzj

Description

@weitzj

The current plugin supports loading extensions as seen in: https://github.com/mattn/go-sqlite3/blob/master/sqlite3_load_extension.go#L28 using:

C.sqlite3_load_extension(c.db, cext, nil, nil)

whereas the method is defined as (https://www.sqlite.org/c3ref/load_extension.html)

int sqlite3_load_extension(
  sqlite3 *db,          /* Load the extension into this database connection */
  const char *zFile,    /* Name of the shared library containing extension */
  const char *zProc,    /* Entry point.  Derived from zFile if 0 */
  char **pzErrMsg       /* Put error message here if not 0 */
);

I would like to have/provide support for overriding the third argument, the entrypoint to the extension.

My problem:

I want to load the spatialite extension via go-sqlite3 on Android. spatialite comes in 2 flavours, either as a shared library (libspatialite.so) or as an sqlite3 extension mod_spatialite.so. Since mod_spatialite.so has to be built with Android ndk-build, and ndk-build only supports library names of the form libMODULENAME.so, the resulting spatialite extension filename is called libspatialite.so, whilst the entrypoint still points to the original modulename, mod_spatialite.so and thus will be sqlite3_modspatialite_init.

Sqlite will automatically guess an entrypoint given a filename, if no entrypoint is given:

  • libspatialite.so has the (guessed) entrypoint sqlite3_spatialite_init
  • mod_spatialite.so has the (guessed) entrypoint sqlite3_modspatialite_init

What I need:

load_extension('libspatialite.so','sqlite3_modspatialite_init')

I do not know, what would be a good variant how to integrate this in go-sqlite3. Maybe an Extension struct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions