Reasons to Use a Readable SQLite Database

The SQLiteOpenHelper Android class has a method for returning a readable database, as well as a database for reading and writing. Currently, I use only a writable database and have no problems, but I wonder what advantage it would be to switch to reading only if I read only in an async task (or activity).

There may be performance benefits, but I have not seen links to actual numbers. Also, if I keep switching between readable and rewritable, the changes have an overhead that can bring out all the performance benefits.

Does anyone have real numbers or experience? Is it worth implementing separate access?

+6
android sqlite sqlite3
source share
2 answers

I can’t comment on the performance benefits, but I always try to work on the principle of "good practice" (or "best") for any access to any data sources (text files, databases or something else).

Looking at things in general (and not Android), the decisions that need to be made when deciding on the access level come down to the operation being performed, as well as to any external influences.

Two examples that I can think of ...

  • If the external process may be responsible for storing data - in this case it can “open” the data source in such a way that it blocks everything except “read” access to any other process during the maintenance phase. In this case, your code will be denied access if you request read / write access when this is not necessary.
  • Risk of compromising data integrity - hacks into systems from the outside world can be achieved through a security hole using internal code that has read and write access to data when it is really needed only for read access.

OK, these points may or may not be related to Android (especially if your data source is specific to your application), but, as I said, I try to look at things in general and use the “best practice” approach. If I do not need to "write" access, I do not ask for it.

+5
source share
Good question. No numbers from me. Closest explanation (from SQLLiteOpenHandler javadoc)

"This (getReadableDatabase) will be the same object that getWritableDatabase () returned if only some problems, such as a full drive, require the database to be read-only. In this case, the read-only database object will be If the problem is fixed , a future getWritableDatabase () call may succeed, in which case the read-only database object will be closed and the read / write object will be returned in the future. "

+6
source share

All Articles