One of my methods returns a Cursor from some SQLite query results.
As I'm navigating through the cursor, there are some records I want to change/update. Can I update directly with the cursor? Or do I have to manually UPDATE
using the record ID from the cursor?
The sqlite3. Cursor class is an instance using which you can invoke methods that execute SQLite statements, fetch data from the result sets of the queries. You can create Cursor object using the cursor() method of the Connection object/class.
Cursors are what contain the result set of a query made against a database in Android. The Cursor class has an API that allows an app to read (in a type-safe manner) the columns that were returned from the query as well as iterate over the rows of the result set.
moveToFirst() method moves the cursor to the first row.
You can not directly update records with the cursor. Read the Android Cursor doc.
You need to implement a Content Provider that allows to update the record, in short you need to override the update function in your ContentProvider class.
public int update(Uri uri, ContentValues values, String where, String[] whereArgs)
In short you'll have to update them, this is not done directly from the data received in the Cursor.
This and this link should help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With