Reputation: 730
I am having a table called Demo in SQLite with Phonegap. I've inserted few values in it. Now I want to update one record.
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(updatemonthSaveingDB, errorCB);
function updatemonthSaveingDB(tx)
{
tx.executeSql("UPDATE DEMO SET data = " + submitval + " WHERE id = " + 8, [], updateCB, errorCB);
}
function errorCB(err)
{
alert("Error processing SQL: " + err.code);
}
Now when I throw this query, it shows *Error processing SQL: 0 * alert.
Upvotes: 3
Views: 9890
Reputation: 97
Give quote ''
beetween each column value.
I also remove [], updateCB, errorCB);
. it wouldn't work if you not declare updateCB
and errorCB
function.
I update the code. work for me.
function updatemonthSaveingDB(tx)
{
tx.executeSql("UPDATE DEMO SET data='" + submitval + "' WHERE id='8'");
}
Upvotes: 0
Reputation: 754
The problem is the way of passing variable inside a sqlite query is incorrect In this function
function updatemonthSaveingDB(tx)
{
tx.executeSql("UPDATE DEMO SET data = " + submitval + " WHERE id = " + 8, [], updateCB, errorCB);
}
sqlite consider "UPDATE DEMO SET data = " as a query because you have used " incorrectly. The correct way is:
function updatemonthSaveingDB(tx)
{
tx.executeSql("UPDATE DEMO SET data ='" +submitval+"' WHERE id = '"+8+"' ;", [], updateCB, errorCB);
}
Upvotes: 6
Reputation: 1887
I believe that what is happening is that your transaction is actually successful. If you go and look at this table of SQLite Error Codes (http://www.sqlite.org/c3ref/c_abort.html) you'll see that an error message of "0" reads as "/* Successful result */".
If "updateCB" is not actually a function (you don't define it here) is it possible that errorCB is being read as your success callback and being called as a result?
Upvotes: 0