Skip to content Skip to sidebar Skip to footer

Open Prepopulated Sqlite Database In Cordova (for Android) And Visual Studio

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

Solution 1:

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 the createFromLocation parameter.

The strange bit it that both plugins are from the same author, and both seem to be active projects. Go figure.

Solution 2:

Old question, but I will answer to serve as a reference (2)!

Pre-populated SQLite is supported by cordova-sqlite-ext project.

The steps are simple:

  • put the database file in the www directory and open the database like: www/sample.db

Then, use:

var db = window.sqlitePlugin.openDatabase({name: "sample.db", createFromLocation: 1});

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.

Post a Comment for "Open Prepopulated Sqlite Database In Cordova (for Android) And Visual Studio"