Skip to content Skip to sidebar Skip to footer

Phonegap Wait For Database Transaction To Complete

I'm creating a Phonegap application that will perform differently on first run. The way that I am detecting the first run is by seeing of one of the database tables exists. As you

Solution 1:

You need to write it in callback form:

vardataBaseExists(yep, nope) {
  database.transaction(function(tx) {
    tx.executeSql('CREATE TABLE GLOBAL (uid, property, value)');
  }, function(){
    if (yep) {
      yep.apply(this, arguments);
    }
  }, function(){
    if (nope) {
      nope.apply(this, arguments);
    }
  });
};


var itDoes = function() {
  console.log("great");
};

var itDoesNot = function() {
  console.log("what a pity");
};


databaseExists(itDoes, itDoesNot);

Solution 2:

You need callbacks, but if don't need checking existment of your tables, you can do that easily with localStorage.

e.g.

if(localStorage.getItem('init') === null){
   //initlocalStorage.setItem('init', true);
}

You will avoid dealing with database.

and maybe this gonna be helpful "CREATE TABLE IF NOT EXISTS..."

Solution 3:

I know there's gonna be programmers don't like my solution, but I love it!

var myfEspereti=false;

functionEspereti(pStatus)
{
    if (pStatus==="wait")
    {
        myfEspereti = true;
        while(myfEspereti)
        {

        }
    }
    elseif (pStatus==="go")
    {
        myfEspereti=false;
    }
}

and then call Espereti ("wait") when you want to wait for an async call. Inside the async call, when it's finish, call Espereti ("go") and that's it!

Post a Comment for "Phonegap Wait For Database Transaction To Complete"