简体   繁体   English

SQLite更新查询在Phonegap中不起作用

[英]SQLite Update query is not working in Phonegap

I am having a table called Demo in SQLite with Phonegap. 我在SQLite中使用Phonegap有一个名为Demo的表。 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. 现在,当我抛出此查询时,它显示* 错误处理SQL:0 *警报。

The problem is the way of passing variable inside a sqlite query is incorrect In this function 问题是在sqlite查询中传递变量的方式不正确在此函数中

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: sqlite认为“UPDATE DEMO SET data =”作为查询,因为你使用了“错误。正确的方法是:

      function updatemonthSaveingDB(tx) 
{
    tx.executeSql("UPDATE DEMO SET data ='" +submitval+"' WHERE id = '"+8+"' ;", [],   updateCB, errorCB);
}

Give quote '' beetween each column value. 在每个列值之间给出引号''

I also remove [], updateCB, errorCB); 我也删除[], updateCB, errorCB); . it wouldn't work if you not declare updateCB and errorCB function. 如果你不声明updateCBerrorCB函数,它将无法工作。

I update the code. 我更新了代码。 work for me. 为我工作。

function updatemonthSaveingDB(tx) 
{
   tx.executeSql("UPDATE DEMO SET data='" + submitval + "' WHERE id='8'");
}

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 */". 如果你去查看这个SQLite错误代码表(http://www.sqlite.org/c3ref/c_abort.html),你会看到错误信息“0”读作“/ *成功的结果* / ”。

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? 如果“updateCB”实际上不是一个函数(你没有在这里定义),是否有可能将errorCB作为成功回调读取并作为结果被调用?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM