【问题标题】:sqlite3 in Node.js does not return the lastID from INSERT callbackNode.js 中的 sqlite3 不会从 INSERT 回调返回 lastID
【发布时间】:2017-01-27 05:56:32
【问题描述】:
db.run("INSERT INTO test VALUES (?)", [testVal], function(err) {
      console.log(err);
      console.log(this.lastId);
      console.log(this);
})

错误 - 返回空值, this.lastID - 返回未定义, this - 返回 Window 对象

如何获得最后一个插入标识符?

【问题讨论】:

    标签: javascript node.js sqlite


    【解决方案1】:

    实际上你必须使用lastID(大写D)。

    db.run("INSERT INTO foo ...", function(err) {
        // err is null if insertion was successful
        console.warn("inserted id:", this.**lastID**);
    });
    

    来源:https://github.com/mapbox/node-sqlite3/issues/206

    【讨论】:

      猜你喜欢
      • 2015-12-09
      • 2013-06-13
      • 1970-01-01
      • 2016-01-07
      • 1970-01-01
      • 2014-03-01
      • 2017-05-10
      • 2015-07-16
      • 1970-01-01
      相关资源
      最近更新 更多