Introduction to SQLite database in Android

Introduction to SQLite:

SQLite is an open source lightweight relational database adopted by Android system. Android allows each application to have its own independent database. The database location of each application is generally / data / data / < package_ Name > / databases. In order to facilitate the use of developers, Android API encapsulates the addition, deletion, query and modification. The sqliteopenhelper class can facilitate the creation and management of the database. However, before using the database formally, we also need to know two basic knowledge points.

Content values and cursor:

Content values are expressed in the form of key value pairs. They are used to insert new rows into the database table. Each contentvalues is mapped to fields and corresponding values in the database.

Cursor is a return method for SQLite data query in Android. It is actually a pointer to the result set in the underlying data. It does not provide a copy of the extracted and returned results. In short, cursor provides a convenient and easy to manage way to control the position (row) of the pointer in the result set.

For cursor, the following methods are often used to control the position of cursor cursor in the underlying data result set:

01. Movetofirst(): move the cursor to the first row in the query result set.

02. Movetonext(): move the cursor to the next line.

03. Movetoprevious(): move the cursor to the previous line

04. Getcount(): returns the number of rows in the query result set

05. Getcolumnindexorthrow(): returns the index of the column with the specified name. Note: the index starts from 0. If there is no column with the name, an exception will be thrown.

06. Getcolumnname(): returns the name of the specified column index.

07. Getcolumnnames(): returns a string array of all column names in the current query result set.

08. Movetoposition(): move the cursor to the specified line.

09. Getposition(): returns the current cursor position.

Create and simply operate SQLite database:

1. We can customize our own SQLite class and let it inherit sqliteopenhelper class to realize personalized and customized SQLite help class.

2. Create a new database and upgrade to a new database by overriding its constructor, oncreate() and onupgrade() methods, respectively.

The above is a brief introduction to the SQLite database in Android introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>