我正在创建一个应用程序,在其中我在表中插入数据。在表中插入数据后,我想获取该行的 id,以便我可以根据它做进一步的操作。
我尝试使用 last_insert_rowid() sqlite 的功能,但没有找到运气。
任何人都可以告诉哪个是获取最后插入的行 ID 的最佳方法。
任何想法表示赞赏。
提前致谢。
最佳答案
您可以像这样获取表上最后一次插入的 ID -
tx.executeSql("INSERT INTO profile('name','label','list_order','category') values(?,?,?,?)",
[currentProfile.name, currentProfile.label, currentProfile.list_order, currentProfile.category],
function(tx, results){
var lastInsertId = results.insertId; // this is the id of the insert just performed
},
failCB
)
results.insertId
在 WebSQL 中类似于 mysql_insert_id()
在 MySQL 中 -mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n", mysql_insert_id());
关于cordova - 如何从phonegap android中的sqlite获取最后插入的行ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19400790/