I m using cordova to build hybrid android app and im using this function which return database object its works fine everywhere in app
function openDB() {
var dbUser = null;
var dBVersion = localStorage.getItem("db_version");
if (dBVersion == null) {
try {
if (!window.openDatabase) {
console.log('db init failed');
} else {
dbUser = window.openDatabase("dbname", "1.0.1", "local", 100000);
}
} catch(error) {
console.log(e);
if (e.name == "INVALID_STATE_ERR") {
console.log("Invalid database version.");
} else {
console.log("Unknown error " + e + ".");
}
}
} else {
dbUser = window.openDatabase("dbname", dBVersion, "local", 100000);
}
console.log(dbUser);
//initialize tables
if (dbUser != null)
createTables(dbUser);
return dbUser;
}
but when i use social plugin like facebook and foursquare and return to app then my app wont able to access the database and give error
Uncaught Error: SECURITY_ERR: DOM Exception 18 at file:///android_asset/www/js/DB.js:27
dbUser = window.openDatabase("dbname", dBVersion, "local", 100000);
and the my app become blank as its wont able to access the database.
When do you execute your code?
If you check out this post you should only execute Database queries after your device is ready. So wait for the deviceready
event triggered from cordova.
document.addEventListener("deviceready", openDB, false);
Note, that this will only be triggered on the phone, not on the browser anymore.
I think for older cordova versions there was as well a limit of the database size. 100000
seems to be quite random, isn't it?
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.