Phonegap - get if database already exist Phonegap - get if database already exist database database

Phonegap - get if database already exist


The var db = window.openDatabase("myDB", "1.0", "FiltersResults", 50000000); checks if you have a database called myDB if it exists it opens it. If not, it creates one and opens it. So if you are seeing it creating multiple Databases, below can be two reasons I can think of

  • You have more that one window running that url, just Quit the browser completely and open one widow with the URL
  • was a knowing UI related bug introduced in Safari 5.1.2, fixed in later versions.


Check the documentation: http://docs.phonegap.com/en/3.0.0/cordova_storage_storage.md.html#Storage

function populateDB(tx) {    tx.executeSql('DROP TABLE IF EXISTS DEMO');    tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');    tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');    tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');}function errorCB(err) {    alert("Error processing SQL: "+err.code);}function successCB() {    alert("success!");}var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);db.transaction(populateDB, errorCB, successCB);