getWritableDatabase()VS getReadableDatabase() [英] getWritableDatabase() VS getReadableDatabase()

查看:245
本文介绍了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 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.

更多信息<一个href="http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#getReadableDatabase%28%29">here.

这篇关于getWritableDatabase()VS getReadableDatabase()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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