3

I have searched for houres but I couldn't really figure out wheter I can read a sqlite file on my sd card (phone's device storage) on android using the cordova-sqlite-ext plugin.

On https://www.npmjs.com/package/cordova-sqlite-storage it says that:

The following features are available in litehelpers / cordova-sqlite-ext: ... - Pre-populated database (Android/iOS/macOS/Windows)

So what I need is a sqlite database outside the webapp and a phonegap plugin that can read from this db. So, is it correct that the plugin above can do that???

Or is there any other way how to accomplish that task?

Suseday
  • 43
  • 3
  • have you read [this quetion](https://stackoverflow.com/questions/2834534/whats-the-simplest-way-to-import-an-sqlite-sql-file-into-a-web-sql-database)? It could fit to what you ask, all you would need is to be able to access to your SD card files – Kaddath Jan 18 '18 at 09:42
  • thanks. But that doesn't help. Problems is, that I can not reach a database for an sql statement that is outside the webapp. Same with files. webapp can not reach files on sd card. only with cordova-plugin-file you can do that. same 'reaching-out-to-the-outside-world' function i need for sql databases – Suseday Jan 18 '18 at 10:23

1 Answers1

1

cordova-sqlite-storage stores its database in the private storage directory of the app. This is accessible only to your app and is located on the internal data partition. For example, if your app package ID is foo.bar.com and your database has name: store.db then it will be located at /data/data/foo.bar.com/databases/store.db. The location data/data/foo.bar.com/ is referenced as cordova.file.applicationStorageDirectory from cordova-plugin-file.

You can use the cordova-sqlite-evcore-extbuild-free variant of cordova-sqlite-storage:

Custom Android database location (supports external storage directory)

The "external storage directory" is on the "SD card" which is usually the internal memory partition accessed via the mount points /sdcard/ or /storate/emulated/0/. Since Android 4.4, apps only have write access in the "application sandbox" directory on the SD card e.g. /sdcard/Android/data/foo.bar.com/ (cordova.file.externalApplicationStorageDirectory).

All other areas of the SD card are read-only (e.g. the root of /sdcard/ - cordova.file.externalRootDirectory) so while you could read from a database here, to write to it you'd need to copy it to either the private or external storage directory of the app. You could do this using cordova-plugin-file, for example.

DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • Thank you so much for the link to cordova-sqlite-evcore-extbuild-free!!! That seems to be exactly what I was searching for! I have searched for houres, but your link sounds just perfect – Suseday Jan 18 '18 at 14:13