首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SQLite将数值变量添加到js中的现有值

SQLite将数值变量添加到js中的现有值
EN

Stack Overflow用户
提问于 2015-05-01 01:26:03
回答 1查看 38关注 0票数 0

我有下面的表格

代码语言:javascript
复制
buildingcode buildingreceiptno buildingaddress buildingpay
1012         2                 address 1       0
1001         3                 address 2       0
1003         0                 address 3       0

我想通过一个数值变量来更新某个楼盘代码的楼盘收据

我使用了以下代码,但它不起作用

代码语言:javascript
复制
t.executeSql('UPDATE buildings SET buildingpay = ?, buildingreceiptno = buildingreceiptno + numericalValue WHERE buildingaddress = ?', 
     [myrow.payamount.toFixed(2), myrow.buildingaddress]);

myrow.payamount.toFixed(2),myrow.buildingaddress是正确的变量

EN

回答 1

Stack Overflow用户

发布于 2015-05-01 03:25:53

你可以改进它,但这应该是你的问题的一个有效的解决方案:

代码语言:javascript
复制
db.transaction(function(tx) {

  // Get buildingreceiptno value
  tx.executeSql(
    "SELECT buildingreceiptno FROM buildings  WHERE buildingaddress = ?", 
    [myrow.buildingaddress], 
    function(tx, res) {
        var buildingreceiptno = res.rows.item(0).buildingreceiptno;
        tx.executeSql(
            "UPDATE buildings SET buildingpay = ?, buildingreceiptno = ? WHERE buildingaddress = ?",
            [myrow.payamount.toFixed(2), buildingreceiptno + numericalValue, myrow.buildingaddress], 
            function(tx, res) { console.log(tx, res); }, 
            function(tx, err) { console.log('ERROR: ', tx, err); }
        );
    }, 
    function(tx, err) { console.log('ERROR: ', tx, err); }); 
  });

总是使用错误回调来打印错误,这很有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29974123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档