开发者

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

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 packa开发者_如何学JAVAge 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜