SQL cursors in android

2019-05-30 23:27发布

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?

2条回答
做个烂人
2楼-- · 2019-05-30 23:55

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

查看更多
爷的心禁止访问
3楼-- · 2019-05-31 00:06

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.

查看更多
登录 后发表回答