Open Masoud-kamali opened 3 years ago
Probably the extension was compiled against a different architecture or a different version of SQLite3.
Any updates on this issue?
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.
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?
@shenzhuxi I encountered the same problem and was able to fix it in https://github.com/WiseLibs/better-sqlite3/pull/1137.
@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.
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 https://github.com/WiseLibs/better-sqlite3/commit/e28e04ade65ab8a656c848455f7a1e4fb5cc9fd8.
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.
Is there any way to load this extension in nodeJS or this library can not do that?