I'm working with Visual Studio 2013 and the Cordova Tools package.
I have most of my app working, and I'm now ready to add the DB logic. I have a DB full of quotes, and I need to tie that into the app.
Following this link: adding dynamic data with SQLite
I was able to get SQLite to talk to a DB (using the sqlitePlugin) However, I can't figure out how to use a pre-populated DB. It always created a new empty DB. I've found several articles on the web that keep saying "put the db in the www folder"... but the Cordova project doesn't have a www folder.
Putting the SQLite DB file in the root doesn't work, and I tried using a path and putting it in a sub-dir. No luck there either.
Has anyone been able to make this work?
Old question, but I will answer to serve as a reference: I solved this problem by changing the plugin. Previously, I was using plugin
cordova-sqlite-storage
(https://github.com/litehelpers/Cordova-sqlite-storage), but it doesn't copy the prepopulated database. It always creates an empty one.After days of fighting, I uninstalled the plugin and installed this one:
cordova-plugin-sqlite
(https://www.npmjs.com/package/cordova-plugin-sqlite). This one works like a charm, it will copy the DB in the www folder to the device. Just follow the instructions and don't forget thecreateFromLocation
parameter.The strange bit it that both plugins are from the same author, and both seem to be active projects. Go figure.
Pre-populated SQLite is supported by cordova-sqlite-ext project.
The steps are simple:
Then, use:
More information: https://github.com/litehelpers/cordova-sqlite-ext#pre-populated-databases
Many sites and answers point to use Cordova-sqlite-storage for this. In fact, this feature was in this project, but it was moved to Cordova-sqlite-ext (they are from the same creator).
I don't recomend using cordova-plugin-sqlite. It is deprecated.