getWritableDatabase()和getReadableDatabase()之间的区别? [英] Difference between getWritableDatabase() and getReadableDatabase()?

查看:173
本文介绍了getWritableDatabase()和getReadableDatabase()之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用读取和写入数据库没有任何问题。但我找不出差别。我在互联网上搜索,但它不是很清楚。任何人都可以告诉我的区别?在这种情况下,我使用 getWritableDatabase() getReadableDatabase()

I use reading and writing to the database without any problems . But i can not find out the difference. I search in Internet but it 's not quite clear. Can anyone tell me the difference? In which case do I use getWritableDatabase() or getReadableDatabase()?

推荐答案

检查参考

1级


创建和/或打开数据库。这将是通过getWritableDatabase()返回
的相同对象,除非有一些问题,例如完整磁盘,
需要以只读方式打开数据库。在这种情况下,将返回
只读数据库对象。如果问题是固定的,一个
未来调用getWritableDatabase()可能会成功,在这种情况下,
只读数据库对象将被关闭,读/写对象
将返回未来。

Create and/or open a database. This will be the same object returned by getWritableDatabase() unless some problem, such as a full disk, requires the database to be opened read-only. In that case, a read-only database object will be returned. If the problem is fixed, a future call to getWritableDatabase() may succeed, in which case the read-only database object will be closed and the read/write object will be returned in the future.

与getWritableDatabase()一样,此方法可能需要很长时间才能返回,因此您不应该从应用程序中调用主线程,包括来自ContentProvider.onCreate()。
返回

Like getWritableDatabase(), this method may take a long time to return, so you should not call it from the application main thread, including from ContentProvider.onCreate(). Returns

a database object valid until getWritableDatabase() or close() is called. 

抛出
SQLiteException如果无法打开数据库

Throws SQLiteException if the database cannot be opened

自:API 1级


创建和/或打开将用于阅读的数据库和
写入。第一次调用时,数据库将被打开
和onCreate(SQLiteDatabase),onUpgrade(SQLiteDatabase,int,int)
和/或onOpen(SQLiteDatabase)将被调用。

Create and/or open a database that will be used for reading and writing. The first time this is called, the database will be opened and onCreate(SQLiteDatabase), onUpgrade(SQLiteDatabase, int, int) and/or onOpen(SQLiteDatabase) will be called.

成功打开后,数据库将被缓存,因此每次需要写入数据库时​​,都可以调用
方法。 (确保
在不再需要数据库时调用close()。)错误例如bad
权限或完整磁盘可能导致此方法失败,但未来
尝试可能会成功如果问题是固定的。

Once opened successfully, the database is cached, so you can call this method every time you need to write to the database. (Make sure to call close() when you no longer need the database.) Errors such as bad permissions or a full disk may cause this method to fail, but future attempts may succeed if the problem is fixed.

数据库升级可能需要很长时间,你不应该从应用程序主线程调用此方法,包括从ContentProvider.onCreate()。
返回

Database upgrade may take a long time, you should not call this method from the application main thread, including from ContentProvider.onCreate(). Returns

a read/write database object valid until close() is called 

抛出
SQLiteException如果无法打开数据库进行写入

Throws SQLiteException if the database cannot be opened for writing

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

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