Issue #85: window.openDatabase throws DOM Exception 18 on Android 3.1

Instead of checking the userAgent catch the exception.  If we do get an exception it will setup our version of Droid Db.
This commit is contained in:
macdonst 2011-05-17 23:40:03 +08:00
parent 2177cd0a39
commit 6c3eefe6f9

View File

@ -397,16 +397,28 @@ PhoneGap.addConstructor(function() {
navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
window.droiddb = new DroidDB();
}
if ((typeof window.openDatabase === "undefined") || (navigator.userAgent.indexOf("Android 3.") != -1)) {
if (typeof window.openDatabase === "undefined") {
setupDroidDB();
} else {
window.openDatabase_orig = window.openDatabase;
window.openDatabase = function(name, version, desc, size) {
var db = window.openDatabase_orig(name, version, desc, size);
window.openDatabase = function(name, version, desc, size){
// Some versions of Android will throw a SECURITY_ERR so we need
// to catch the exception and seutp our own DB handling.
var db = null;
try {
db = window.openDatabase_orig(name, version, desc, size);
}
catch (ex) {
db = null;
}
if (db == null) {
setupDroidDB();
return DroidDB_openDatabase(name, version, desc, size);
} else return db;
}
else {
return db;
}
}
}