Skip to content Skip to sidebar Skip to footer

Can't Access Pre Populated Sqlite Database Using Phonegap/cordova In Android

We are trying to create a mobile app using PhoneGap/Cordova. We need to ship this app with a pre-populated SQLite db. We are able to copy the DB using below code. But when we try t

Solution 1:

In first place, can trying with the next DB file name:

0000000000000001.db

And for load file:

FiledbFile= getDatabasePath(".0000000000000001db");

The DB file needs to be in the next route:

yourProyect/assets/0000000000000001.db

I recommend use "SQLitePlugin":

SQLitePlugin GitHub

In the "onDeviceReady()" function i use:

if(!dbCreated){
    db = window.sqlitePlugin.openDatabase("0000000000000001", "1.0", "My Database", -1);
}

Solution 2:

I faced the same problem, but the answer above does not help me, so I am writing my experience, it may help.

I typically used a Cordova plugin named: me.rahul.plugins.sqlDB at https://github.com/an-rahulpandey/cordova-plugin-dbcopy

It is a plugin focused to copy files from Cordova www folder to the right folder on Android/iphone.

You have first to install the plugin, using:

$ cordova plugin add https://github.com/an-rahulpandey/cordova-plugin-dbcopy.git

Then on Device Ready event:

functiononDeviceReady() {
    console.log(">device is ready");
    window.plugins.sqlDB.copy("mydb.sqlite", copySuccess, copyError);
}

Solution 3:

To access pre-populated database you should first copy the database file in www directory.

Install this plugin DB-Copy plugin and copy the database from www directory into the device, using the copy plugin and then use Sqlite-storage plugin to access the database.

PS. The copy of database from www directory is need it because each OS has different location to store databases...

Post a Comment for "Can't Access Pre Populated Sqlite Database Using Phonegap/cordova In Android"