cordova - 如何从phonegap android中的sqlite获取最后插入的行ID

标签 cordova android-sqlite lastinsertid

我正在创建一个应用程序,在其中我在表中插入数据。在表中插入数据后,我想获取该行的 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/

相关文章:

android - 单击主页按钮后,Phonegap Android 应用程序重新启动而不是恢复

MySQL 查询到 SQLite 查询过去 24 小时的事件

java - 有两个sql插入的事务

zend-framework2 - Zend/ZF2/TableGateway mysql_insert_id 替换?

ios - Cordova iOS CallKit - 来自电话历史记录(最近选项卡)的调用停止工作

ios - Crosswalk for iOS 的使用

android - 如何通过索引获取 SQLite 中的一行(而不是通过 id)

android - 如何将数据从Sqlite迁移到Realm

database - 当整数列上的 auto_increment 达到数据库中的 max_value 时会发生什么?

javascript - 将 localForage 与 Cordova 结合使用的正确方法是什么?