Pregunta

I am new with this phonegap and executeSql. I am trying to create a basic snippet to understand the concepts better. Anyway I have following code in my onDeviceReady function

 db = window.openDatabase("myapplication","1.0","My Application DB","200000");
 tx.executeSql("CREATE TABLE IF NOT EXISTS MYTABLE (id, stockcode, quantity)");

I have created a button named "save" and on tapping it saves a value into the database

function saveDb(tx) {
  var stockcode = "HP13-1";
  var quantity = "1";
  tx.executeSql("INSERT INTO mytable (stockcode, quantity) VALUES (?,?)", [stockcode, quantity]);
}

So far so good. I have another button named "show results" and on tapping it displays the results using following function

function getDbResults(tx) {
   tx.executeSql("SELECT * FROM MYTABLE", [], onSelectQuerySuccess, onDbError);
}
function onSelectQuerySuccess(tx, results) {
   $("#showresults").empty();
   dbresults = results;
   var len = results.rows.length;
   for (var i = 0; i<len; i++) {
       $("#showresults").append("<li>"+results.rows.item(i).stockcode+"</li>");
   }
   $("#showresults").listview("refresh");
}

This displays the desired result but after its doing that it returns error.code = 0 and error.message = "the statement callback raised an exception or statement error callback did not return false"

I am not sure how to resolve this issue. Any help in this regard would be highly appreciated.

¿Fue útil?

Solución

The answer I'm going to write points out some things that I don't understand and a solution proposition.

First of all I don't understand your CREATE TABLE statement, you are not giving any datatype (for example: ID INT NOT NULL, not just ID).

Second, try to provide a success and error callback everytime you have to interact with the DB.

Third, and this is the real proposed solution, try to return a boolean in the callbacks, as specified in this Apple document.

You're not specifying if the errors happens in any platform or only on a specific one, this could be another interesting info.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top