Sqliteopenhelper in layman's.

Source: Internet
Author: User

1. What is Sqliteopenhelper?

It is literally meaning: The tool class that helps to open sqlitedatabase.

2.SQLiteOpenHelper function?

Mainly: some operations in 1.onCreate () to help initialize the database. such as building tables, etc.

2. In Onupgrade (), Help update the database, delete the old table, create a new table, and so on.

3. Why use Sqliteopenhelper?

This tool class is derived from the Java singleton pattern. The essence is a single case, efficient.

4. How do I use it?

Sqliteopenhelper is an abstract class. You need to inherit it to create an instance that you already need.

The main methods to be implemented are OnCreate () and Onupgrade ();

public class Mysqliteopenhelper extends Sqliteopenhelper {string Sql;public mysqliteopenhelper (context context, string Name,cursorfactory Factory, int version) {Super (context, name, Factory, version);} Called when the database is created. This is usually the creation of tables, etc. about the initialization of the database operations. @Overridepublic void OnCreate (Sqlitedatabase db) {db.execsql (SQL);} Called when the database is updated. So what are the criteria for the update? Based on comparing the database name to the current version//and the previous version, if the current version is newer, it will be called. Older will call downgrade (), @Overridepublic void Onupgrade (sqlitedatabase db, int oldversion, int newversion) {//update operation. such as deleting an old table, creating a new table, and so on. }//calls @overridepublic void Ondowngrade (sqlitedatabase db, int oldversion, int newversion) when newversion is smaller than oldversion {// TODO auto-generated Method Stubsuper.ondowngrade (db, Oldversion, newversion);}}


----------------------------------------------------------Welcome to the exchange.

Sqliteopenhelper in layman's.

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.