1

I am setting up a Spatialite database (SQLite + Spatialite extension) and an associated Go program running in a docker container that queries the database and returns data.

Go-spatialite, in my understanding will dynamically load the spatialite library at runtime in order to query the database. Everything runs fine when running the Go program locally and querying the service with Postman.

However, when using the container, the Go program fails to find the spatialite extension:

"error":"shaxbee/go-spatialite: spatialite extension not found."

I use go-spatialite (shaxbee) package and database/sql package. I have installed Spatialite locally.

I open the database connection like this:

db, err := sql.Open("spatialite", "path/to/my/db")
if err != nil {
    logVar.WithError(err).Fatal("Impossible to open database")
}
if err := db.Ping(); err != nil {
    logVar.WithError(err).Fatal("Cannot connect to database")
}

I used this Dockerfile to adapt mine (that is based on alpine-glibc) in order to install the Spatialite library during image building. According to the Spatialite package, it looks for different for spatialite library and load it.

When checking /usr/local/lib/ in the container, the libraries are there:

libspatialite.a
libspatialite.la
libspatialite.so
libspatialite.so.7
libspatialite.so.7.1.0
libsqlite3.so
libsqlite3.so.0
libsqlite3.so.0.8.6

It seems to me that the program does not know where to get the libraries. Do you have any ideas ?

Thanks

Ullaakut
  • 3,554
  • 2
  • 19
  • 34
mich
  • 347
  • 3
  • 10

1 Answers1

0

That Dockerfile sets up a container with libspatialite version 4.3.0a.

...

RUN wget "http://www.gaia-gis.it/gaia-sins/freexl-1.0.4.tar.gz" && tar zxvf freexl-1.0.4.tar.gz && cd freexl-1.0.4 && ./configure && make && make install

RUN wget "http://www.gaia-gis.it/gaia-sins/libspatialite-4.3.0a.tar.gz" && tar zxvf libspatialite-4.3.0a.tar.gz && cd libspatialite-4.3.0a && ./configure && make && make install

RUN wget "http://www.gaia-gis.it/gaia-sins/readosm-1.1.0.tar.gz" && tar zxvf readosm-1.1.0.tar.gz && cd readosm-1.1.0 && ./configure && make && make install

RUN wget "http://www.gaia-gis.it/gaia-sins/spatialite-tools-4.3.0.tar.gz" && tar zxvf spatialite-tools-4.3.0.tar.gz && cd spatialite-tools-4.3.0 && ./configure && make && make install
...

From one of the recent commits to go-spatialite, we can see that the required version is 5.

var LibNames = []entrypoint{
    {"mod_spatialite", "sqlite3_modspatialite_init"},
    {"libspatialite.so", "sqlite3_modspatialite_init"},
    {"libspatialite.so.5", "spatialite_init_ex"},
    {"libspatialite.so", "spatialite_init_ex"},
}

(spatialite.go)

Use a container with version 5 of libspatialite to resolve your issue.

Momer
  • 3,158
  • 22
  • 23
  • With the 4.3.0 version, I had libspatialite.so.7 in my usr/local/bin. Even by replacing the version of libspatialite to 5, it still was libspatialite.so.7. I'll try to figure why it is .7 version. – mich Aug 16 '18 at 08:53