4
function insertToProject(cast, pName)
{
    db.execute('INSERT INTO project (cd, pn) VALUES (?,?)', cast, pName);
        var x = last_insert_rowid();
        return x;
}

我一直在尝试在钛 appcelerator 中使用 javascript。谁能告诉我我做错了什么?

4

2 回答 2

5

For this you can use the lastInsertRowId property of database object.

You can use like:

var x = db.lastInsertRowId;

lastInsertRowId

lastInsertRowId : Number

The identifier of the last populated row

Please check this link for more details : Titanium.Database.DB

于 2012-12-29T11:02:18.853 回答
2

你也可以这样做:

  db.transaction(function(tx) {
      tx.executeSql("INSERT INTO project (cd, pn) VALUES (?,?)", cast, 
                function(tx, res) {
                    var id = res.insertId;
                });
      });

因此,获取成功插入的结果,然后获取其属性insertId

于 2016-12-16T11:27:59.467 回答