function insertToProject(cast, pName)
{
db.execute('INSERT INTO project (cd, pn) VALUES (?,?)', cast, pName);
var x = last_insert_rowid();
return x;
}
我一直在尝试在钛 appcelerator 中使用 javascript。谁能告诉我我做错了什么?
function insertToProject(cast, pName)
{
db.execute('INSERT INTO project (cd, pn) VALUES (?,?)', cast, pName);
var x = last_insert_rowid();
return x;
}
我一直在尝试在钛 appcelerator 中使用 javascript。谁能告诉我我做错了什么?
For this you can use the lastInsertRowId
property of database object.
You can use like:
var x = db.lastInsertRowId;
lastInsertRowId
: NumberThe identifier of the last populated row
Please check this link for more details : Titanium.Database.DB
你也可以这样做:
db.transaction(function(tx) {
tx.executeSql("INSERT INTO project (cd, pn) VALUES (?,?)", cast,
function(tx, res) {
var id = res.insertId;
});
});
因此,获取成功插入的结果,然后获取其属性insertId