David K.
David K.

Reputation: 6371

SQL cursors in android

Suppose I run some query and get a cursor which I want to use to update the entries in the database. What happens if the database is updated while the cursor is not closed? For example, suppose the cursor is pointing at the 1st entry in the result set and I run a query that updates the 10th element. Does the current cursor reflect those changes?

Upvotes: 1

Views: 675

Answers (2)

EboMike
EboMike

Reputation: 77762

The cursor is a copy of the results in memory, so you can modify the database at will. Since it's a copy, it won't reflect any changes - you'd need to requery for that.

However, it is absolutely imperative that you close it as soon as possible, to save memory and to make your app not crash when you switch activities.

Upvotes: 2

Matthew
Matthew

Reputation: 44919

You need to call cursor.requery() in order to reload changes from the database.

Upvotes: 4

Related Questions