Hi, I tried your code and it gave me an error after that I tried to open the db in the window.plugins.sqlDB.copy error function. The error said “Error in Success callbackId: sqlDB1540206385 : Error: Database location or iosDatabaseLocation value is now mandatory in openDatabase call”. I don’t know how solves it and I don’t know how use a prefilled database. I tried all the guides which are in internet. Coincidentally, have you solved your problem?
Hi Nadir. Finally I won and now I’m very happy. After a week where I tried everything, finally I succeed in it.
First of all I put the db in the folder www. Then I wrote all the code in my controller. The code is:
var dbName = “database_name.db”;
var db = null;
var query = “SELECT * FROM table_name”;
if (window.sqlitePlugin) { //device
//Copy and open the database
window.plugins.sqlDB.copy(dbName, 0, function () {
db = window.sqlitePlugin.openDatabase({name: dbName, location: 1}, function (db) {
db.executeSql(query,,function(result){
console.log(result.rows.length);
},function(err){
console.log(“Error:” + err.message);
});
}, function (err) {
console.log('Error opening the database: ’ + err.message);
});
}, function (error) {
console.error("Error copying the database: " + error.message);
db = window.sqlitePlugin.openDatabase({name: dbName, location: 1}, function (db) {
db.executeSql(query,,function(result){
console.log(result.rows.length);
},function(err){
console.log(“Error:” + err.message);
});
}, function (err) {
console.log('Error opening the database: ’ + err.message);
});
});
} else{ //browser
db = window.openDatabase(dbName, 1, dbName, -1);
}
I tried it with an android device and it works for me. I hope that it can help you and who needs!