开发者

rowid in SQLITE3 and Android

开发者 https://www.devze.com 2023-03-15 15:48 出处:网络
I perform an insert on a database and I want to know what the rowid is for that insert. Does this accomplish the task:

I perform an insert on a database and I want to know what the rowid is for that insert.

Does this accomplish the task:

Uri uri = ContentResolver.insert(url,values);    //Make insert
int rowid= Integer.parseInt(uri.getFragment());  //Get rowid

The Android documentation states that the insert returns "the URL of the newly created row." And the Uri开发者_开发知识库 method getFragment() is supposed to return everything after the /#. So, is my understanding correct that getFragment() would thus return to me the rowid?


To parse the URI after an insert and get the id you should use ContentUris.parseId(uri).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号