简体   繁体   English

SQLITE3 和 Android 中的 rowid

[英]rowid in SQLITE3 and Android

I perform an insert on a database and I want to know what the rowid is for that insert.我在数据库上执行插入,我想知道该插入的 rowid 是什么。

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." Android 文档指出insert返回“新创建行的 URL”。 And the Uri method getFragment() is supposed to return everything after the /#. Uri 方法getFragment()应该返回 /# 之后的所有内容。 So, is my understanding correct that getFragment() would thus return to me the rowid?那么,我对getFragment()将因此返回给我的 rowid 的理解是否正确?

To parse the URI after an insert and get the id you should use ContentUris.parseId(uri) .要在插入后解析 URI 并获取 id,您应该使用ContentUris.parseId(uri)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM