krv
krv

Reputation: 2920

phonegap sqllite Database: the statement callback raised exception

i am having this strange "the statement callback raised an exception or error did not return false"

it is just a simple databases example. my code is on github here: https://github.com/prantikv/phonegapDBdemo

please read the comments in the code it explains everything.

i suspect the problem is in the ajax callbacks for the database. if that is true than how can i make the ajax callback wait for data in sql-lite/phonegap?

function formSent(){//fired when form is submited
  alert("formSent called");
 db.transaction(queryDB, errorTrans);
 return false;
}
function errorTrans(err){ //error for formsent
alert("formsent "+err.message+"|"+err.code);//error is generated here
}


function createSuccess(){//just alerts on success
alert("DB Created");
}

function populateDB(tx) {//transaction obj is passed. Table Created not populated
  alert("populateDB called");
   tx.executeSql('CREATE TABLE IF NOT EXISTS myDB (id , data)');
}

function onDeviceReady(){
 db= window.openDatabase("Database", "1.0", "Display Name", 4*1024*1024);
 db.transaction(populateDB, createERR, createSuccess);

}
function createERR(err){//error for create
alert("Create "+err.message);

}

AM i supposed to add return false for every database callback.if yes then which Boolean is to be returned when?

The phonegap doc examples dont have it http://docs.phonegap.com/en/2.2.0/cordova_storage_storage.md.html#Database

Upvotes: 0

Views: 3139

Answers (1)

Roope Hakulinen
Roope Hakulinen

Reputation: 7405

The error message usually isn't because of SQL, it is rather about exception that happens when you are executing callback for it. So you most probably have JS error happening.

I found

tx.executeSql('INSERT INTO myDB VALUES (?,?)', [username,email], insertSuccess, errorInsert);

on line 47 of index.js. It is lacking the (id,data) before VALUES. This causes the next SQL call

tx.executeSql('SELECT * FROM myDB', [], querySuccess, errorSelect);

to fail. Fix that and then try again.

Upvotes: 4

Related Questions