Learning experience of Sqlte in Android development

Source: Internet
Author: User

  • To access the Android relational database SQLite, you must use a class like Sqliteopenhelper.

    If you don't use this class, it's more cumbersome. Since there is such a class, it is good to use it directly.

    Sqliteopenhelper is the helper class that operates on database creation and versioning. By inheriting the class, we write some methods to implement the operation of the database.

    Getreadabledatabase () Creates or opens a database. The database that is created or opened is readable.

    The query data is a read operation. Additions, deletions, and modifications are write operations.

    Sqlitedatabase is a number of ways to provide management of SQLite databases. such as INSERT, IsOpen, query, update.

    To operate on a database, you must obtain an object of the class such as sqlitedatabase to manipulate the database. How to get this object, first get a Sqliteopenhelper object, and then use the Sqliteopenhelper object Getreadabledatabase, Getwriteabledatabase to get a readable or writable database to get a Sqlitedatabase object, then use this object to manipulate the database.

    OnCreate (Sqlitedatabase db), OnOpen (Sqlitedatabase db), Onupgrade (sqlitedatabase db,int oldversion,int newversion) These three functions are callback functions that are called when an operation is performed. These three callback functions are called when you create a database, open a database, and update a database.

    The operation to create the table structure is written in the OnCreate (Swlitedatabase db) method

    Upgrading the database, adding tables, modifying table names can be written in the Onupgrade (sqlitedatabase db,int oldversion,int newversion) method

    Summarize:

    When you need to manipulate the SQLite database, you must have a class object such as Sqliteopenhelper, but since the class is abstract, you must write a class to inherit it. After inheritance, there are 2 functions: Getreadabledatabase, Getwriteabledatabase. These 2 objects are objects of the Sqlitedatabase class. When querying the database, it is necessary to use a class such as Getreadabledatabase, when the database is added, deleted, modified operation, it is necessary to use getwriteabledatabase such a class to get sqlitedatabase such an object.

    In addition, OnCreate, OnOpen, Onupgrade can also be replicated.

Learning experience of Sqlte in Android development

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.