如何安全地从另一个进程可能会使用一个数据库中读取? [英] How to safely read from a database that another process may be using?

查看:118
本文介绍了如何安全地从另一个进程可能会使用一个数据库中读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读的时候你的应用程序使用的WebView创建的数据库webview.db一些数据。然而,该数据库是由多包级别或者不通过API提供接入的方式多类进行管理。

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.

如果没有办法安全地在其上AQUIRE SQL查询/游标,是有办法的实际webview.db文件拷贝安全地在一个线程安全的方式?有没有得到一个腐败副本的危险吗?

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?

谢谢了

推荐答案

我认为所有的锁在s​​qlite的水平,而不是在java code,所以你应该能够与刚刚开放分贝脱身并从中读取,而不混淆的WebView。结果
然而,出于同样的原因,你应该为ppared锁错误$ P $,直到锁不见了重试查询。当web视图不改变数据报表数据库将被锁定。结果
希望web视图不把一个独占锁的所有数据库为它的运行的全部时间,但我没有看到一个原因。

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.

这篇关于如何安全地从另一个进程可能会使用一个数据库中读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆