微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在创建一个应用程序,我在表中插入数据.在表中插入数据后,我想得到该行的id,以便我可以根据它进行进一步的操作.
我试图使用sqlite的last_insert_rowid()函数,但没有找到运气.
任何人都可以告诉哪个是最后一个插入行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
)

Websql中的results.insertId类似于MysqL中的MysqL_insert_id() –

MysqL_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n",MysqL_insert_id());

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐