frie
frie

Reputation: 153

What is the use of '_id' in ContentUris.withAppendedId

I have been struggling with the update of only 1 row in an SQlite databasetable.

Although I provided the _id value of the row that I wanted to update in the ContentUris.withAppendedId Uri, I still have to check in the 'WHERE'-part of the update statement whether the id of the record is the same.

When I leave the 'WHERE'-part of the update statement to 'null', the update statement tries to update ALL rows of the table instead of only the row with the id that was provided.

Upvotes: 2

Views: 1586

Answers (1)

Karakuri
Karakuri

Reputation: 38595

URIs define a resource. They do not define what operations can be made on that resource.

With regards to a ContentProvider (since you've included that in the tags for your question), you need to consider that the app with the ContentProvider and the app that wishes to access or modify its data may not be the same app. If you are implementing a ContentProvider, you would need to recognize URI of the kind you mentioned and adjust the WHERE clause accordingly, assuming you support that operation on that resource.

The other use for this is with insert operations, where the typical thing to return is a URI for the item that was just inserted. E.g. a successful insert on the URI content://authority/directory would return something like content://authority/directory/_id, where _id is the ID of the newly inserted row.

Upvotes: 1

Related Questions