Fix for ticket 121: Checking for null return on native openDatabase call not enough as only allowed one DB per PhoneGap app. Have to proxy openDatabase and check at runtime.

This commit is contained in:
Fil Maj 2011-04-06 10:50:24 -07:00
parent 626119ae3b
commit bf164f4161

View File

@ -385,10 +385,22 @@ var CupcakeLocalStorage = function() {
}
};
PhoneGap.addConstructor(function() {
if (typeof window.openDatabase === "undefined" || window.openDatabase("test", "1.0", "TestDB", 1000) == null) {
var setupDroidDB = function() {
navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
window.droiddb = new DroidDB();
}
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);
if (db == null) {
setupDroidDB();
return DroidDB_openDatabas/e(name, version, desc, size);
} else return db;
}
}
if (typeof window.localStorage === "undefined") {
navigator.localStorage = window.localStorage = new CupcakeLocalStorage();