插入后获取生成的id [英] Get generated id after insert
本文介绍了插入后获取生成的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Android 上使用 SQLite,我想知道获取我插入的行的生成 ID 的最佳方法.
I'm using the SQLite with Android, and I want to know the best way to get the generated id of the row I inserted.
我认为在包含之后进行搜索的解决方案,但它看起来并不是最好的方法.
A solution I think makes a search after include, but it doesn't look the best way.
推荐答案
insert
方法返回行的id
刚刚插入或 -1
如果插入过程中出现错误.
The insert
method returns the id
of row just inserted or -1
if there was an error during insertion.
long id = db.insert(...);
其中 db 是 SQLiteDatabase
.
这篇关于插入后获取生成的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文