rowid in SQLITE3 and Android

2019-06-24 01: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:

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?

1条回答
在下西门庆
2楼-- · 2019-06-24 02:04

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

查看更多
登录 后发表回答