Android sqlitedatabase Analysis

Source: Internet
Author: User
Tags sqlite database

The compact SQLite database used by the data store in Android.

In order to facilitate the Java layer to use sqlite,android do a lot of encapsulation. Provides classes and APIs for some columns. This article exposes the class diagram relationships behind these packages.

The ritual, first:


Sqliteopenhelper is a helper class provided by the Android SDK to manage database creation and version number control.

A Sqlitedatabase object can be obtained by sqliteopenhelper function getreadabledatabase and function getwritabledatabase. The user inherits the Sqliteopenhelper class, implements its abstract function, realizes the database table creation, the version number upgrade and so on function.

From UML you can see that there is a member variable pointing to the Databaseerrorhandler interface in Sqlitedatabase. This object is used to handle the case where the database exception occurred. We can implement this interface to handle the exception case of the data, for example, the database corruption can not open, it will call to the Oncorruption function of this interface.


Sqlitedatabase provides some operational functions for the database. For example, query. Insert,delete and so on. This is just a case:query. The green lines on the way represent the direction of the call flow of query.

With Sqlitedatabse's query function, a Sqlitecursor object can be obtained. It implements the cursor interface.

Sqlitecursor represents the result set after querying the database. Assuming that this process calls SQLITEDATABSE, then the cursor interface is actually a Sqlitecursor object, assuming that a cross-process, for example, through the ContentProvider query interface queries a URI to take a CUROSR interface, Then the actual object will be a cursor object that supports cross-process communication. Here does not do a specific description of the narrative, in the future of the article to explain the structure of the cursor alone.

One feature of SQLITEDATABSE is the encapsulation of multi-threaded access.

Each thread has a session saved to communicate with the database. The actual communication process is seesion from the Connect pool to get a sqliteconnection connection, through this connection to operate the native layer of the real database. Each time you operate the database, you must get a connection.

The Sqliteconnectionpool controls the type of connection. For the Wal-mode database, you can only have a writable connection and can have multiple read connections. So reading and writing can be done at the same time. When a writable connection is already occupied. Assuming that the thread is requesting a write connection at this point, it will enter the wait queue until there is a writable connection available. For the journal Mode database, 4.2 of the code is simply agreeing to have a connection.

Sqliteprogram represents a variety of resources for database operations. It holds the SQL statement. The database object that is being manipulated, and the number of parameters that the SQL statement binds to.

Android sqlitedatabase Analysis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.