Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not load mod_spatialite extension #520

Open
Masoud-kamali opened this issue Dec 28, 2020 · 7 comments
Open

can not load mod_spatialite extension #520

Masoud-kamali opened this issue Dec 28, 2020 · 7 comments

Comments

@Masoud-kamali
Copy link

Hi guys,
I used loadExtension for add mod_spatialite exntesion. as you said, I add .dll file to my directory and after that i load this extension.
but sometimes it can not find this module and some other says it is 32bit file and can not load in 64bit.
actually I checked it with sqlite3.exe and mod_spatialite.dll in cmd and it works.

this is my code and './spatialite/mod_spatialite' is my path.

const Database = require('better-sqlite3');
const db = new Database('foobar.sqlite', { verbose: console.log });
db.loadExtension('./spatialite/mod_spatialite');

Is there any way to load this extension in nodeJS or this library can not do that?

@JoshuaWise
Copy link
Member

Probably the extension was compiled against a different architecture or a different version of SQLite3.

@JoshuaWise
Copy link
Member

Any updates on this issue?

@jonscarbrough
Copy link

I concur on this issue. I've downloaded 3.35.2 (per instructions on compilation page). Built libspatialite 5.0.1 after building sqlite3. All I get is Segmentation fault (core dumped) when trying to load mod_spatialite. I've tried using the library name specifically, with/without the path to the .so and all produce the segmentation fault. I initially had the same issue with node-sqlite3 but after ensuring that libspatialite was built with the same sqlite3 build, I could load mod_spatialite.so (but only after putting a symlink into /usr/lib64). I figured this was the same reason why better-sqlite3 got the seg fault when loading the extension but the prior path to resolution with node-sqlite3 didn't work for better-sqlite3.

@shenzhuxi
Copy link

shenzhuxi commented Jan 28, 2022

I can actually load mod_spatialite (either from Ubuntu or compiled from the src).

const Database = require('better-sqlite3');
const db = new Database('test.db', { verbose: console.log });
//db.loadExtension('mod_spatialite');
db.loadExtension('../libspatialite-5.0.1/src/.libs/mod_spatialite');
console.log(db.prepare('SELECT spatialite_version()').get());

Then it will get "Segmentation fault" when run 'SELECT InitSpatialMetaData(0)' or 'SELECT InitSpatialMetaData(1)'.

It looks like a time out problem, because if I open the db file after the error, I can see the spatial tables initialised.
Is it because sqlite_version(): "3.37.2" from better-sqlite3 is different from sqlite 3.31.1 from Ubuntu?

@merceyz
Copy link
Contributor

merceyz commented Feb 7, 2024

@shenzhuxi I encountered the same problem and was able to fix it in #1137.

@shenzhuxi
Copy link

shenzhuxi commented Mar 15, 2024

@shenzhuxi I encountered the same problem and was able to fix it in #1137.

Thanks! It seems working now.
I used node 18.

However with electron.js (28.2.7) it still crashes. after 'SELECT InitSpatialMetaData();' if using ':memory:' like https://github.com/WiseLibs/better-sqlite3/blob/master/.github/workflows/build.yml#L50.

If real db file is used, it will crash after "AddGeometryColumn".

I tried "node_modules/.bin/electron-rebuild -f -w better-sqlite3" and nothing happened. If I switch to electron 29, I can see the recompiling and error messages. So I suspect a prebuilt dist skipped the rebuilding with node 18 and electron 28.

@shenzhuxi
Copy link

It seems work in with electron.js (tested on 2.8 and 2.9) since 9.4.4.
I guess this issue has been resolved by e28e04a.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants