How to safely read from a database that another process may be using?

好久不见. 提交于 2019-12-11 07:30:17

问题


I would like to read some data from the webview.db database that is created when your app uses a WebView. However, that database is managed by classes that are mostly package level or do not provide much in the way of access through apis.

Since I can't share their database objects or locks, how can I safely read content from that database without getting "database is locked" errors or similar exceptions?

I only need to read, I do not need to write.

If there is no way to safely aquire sql queries/cursors on it, is there a way to safely copy the actual webview.db file in a thread safe manner? Is there any danger of getting a corrupt copy?

Thanks much


回答1:


I think all the locks are at the sqlite level, not in the java code, so you should be able to get away with just opening the db and reading from it without confusing the webview.
However, for the same reason you should be prepared for lock errors and retry your queries until the lock is gone. The db will be locked when the webview does data altering statements.
Hopefully the webview doesn't put an exclusive lock on all the db for the whole time it's running, but i don't see a reason for that.



来源:https://stackoverflow.com/questions/5840295/how-to-safely-read-from-a-database-that-another-process-may-be-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!