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 to do a lot of encapsulation, provided a number of columns of classes and APIs. 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 versioning.

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 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, such as the database corruption cannot open, will call to this interface's oncorruption function.


Sqlitedatabase provides some operational functions for the database, such as Query,insert,delete. This is only a case:query. The green lines on the way represent the direction of the call flow of query. With the SQLITEDATABSE query function, you can get a Sqlitecursor object that implements the cursor interface. Sqlitecursor represents the result set after querying the database. If this process calls SQLITEDATABSE, then the cursor interface is actually sqlitecursor object, if it is a cross-process, such as 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. This is not a detailed description of the structure of the cursor in a later article.

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.

Sqliteconnectionpool controls the type of connection, there can be only one writable connection for the Wal-mode database, and multiple read connections. This can be done at the same time as reading and writing. When a writable connection is already in use, if the thread is requesting a write connection at this point, then the threads will go into the wait queue until there is a writable connection available. For the journal Mode database, 4.2 of the code is allowed to have only one connection.

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

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.