getWritableDatabase()VS getReadableDatabase()getWritableDatabase、VS、getReadableDatabase

由网友(那时雨°╮)分享简介:我创建一个数据库,辅助类和一些在它的方法,我只是查询数据库和其他人,我写它。I am creating a database helper class and for some of the methods within it I am only querying the database and others I...

我创建一个数据库,辅助类和一些在它的方法,我只是查询数据库和其他人,我写它。

I am creating a database helper class and for some of the methods within it I am only querying the database and others I am writing to it.

我的理解是这两种方法都起来打开数据库,并让程序要么只是读取或写入到数据库。

My understanding is both these methods will open the database up and let the program either just read or write to the database.

有关的查询语句是值得只是使用getReadableDatabase()或有两个方法之间的性能差异很小。

For the query statements is it worth just using getReadableDatabase() or is there very little difference in performance between the two methods.

感谢您的时间。

推荐答案

他们返回相同的对象,除非磁盘已满或有一些权限错误的力量来打开只读模式数据库。这个名字是有点混乱,虽然:)

They return the same object unless the disk is full or there is some permission error that forces to open the database in read-only mode. The name is a bit confusing though :)

作为一个经验法则,你应该把任何调用UI线程之外的这些方法。这两种可能需要很长的时间来恢复。

As a rule of thumb you should put any call to these methods outside the UI thread. Both can take a long time to return.

如果您不打算写数据库只使用 getReadableDatabase ,因为这将有助于您的code清晰度和意向。

If you are not going to write the database just use getReadableDatabase as it will contribute to your code clarity and intention.

更多信息here.

阅读全文

相关推荐

最新文章