Android Implementation Statement _android when creating or upgrading a database

Source: Internet
Author: User
Tags deprecated sqlite

This article describes the statements that are executed when Android creates or upgrades a database, and if you are creating or upgrading a database, use the constructor with the list parameter, and the construction method with the SQL statement will execute when the database is created or upgraded.

The specific program code is as follows:

Import java.util.List;
Import Android.content.Context;
Import Android.database.sqlite.SQLiteDatabase;
Import Android.database.sqlite.SQLiteDatabase.CursorFactory;
Import Android.database.sqlite.SQLiteOpenHelper;
 public class Simplesqliteopenhelper extends Sqliteopenhelper {private static final int init_version = 1;
 /** * Statements that are executed when a database is created or upgraded.
 * * Private list<string> sqlstatementexed;
 /** * If you are creating or upgrading a database, use the construction method with the list parameter. * @param context * to ' open ' or create the database * @param name * of the database file, or null fo R an in-memory database * @param factory * To use for creating cursor objects, or NULL for the default * @param ve Rsion * Number of the database (starting at 1); If the database is * older, onupgrade (sqlitedatabase, int, int) would be used to * upgrade the database; 
 If the database is newer, * Ondowngrade (sqlitedatabase, int, int) would be used to * downgrade the database * * Public Simplesqliteopenhelper (Context, String name, Cursorfactory factory, int version) {Super (context, name, Factory, version);
 sqlstatementexed = null; /** * Constructs a method with SQL statements.
 This SQL statement will be executed when the database is created or upgraded. * @param context * to ' open ' or create the database * @param name * of the database file, or null fo R an in-memory database * @param factory * To use for creating cursor objects, or NULL for the default * @param ve Rsion * Number of the database (starting at 1); If the database is * older, onupgrade (sqlitedatabase, int, int) would be used to * upgrade the database; If the database is newer, * Ondowngrade (sqlitedatabase, int, int) would be used to * downgrade the database *
 @param sqlstatementexed * Statements that will be executed when the database is created or upgraded. */Public Simplesqliteopenhelper (context, String name, Cursorfactory factory, int version, list<string> s
 qlstatementexed) {Super (context, name, Factory, version);
 this.sqlstatementexed = sqlstatementexed;
 }/** * If you are creating or upgrading a database, use the construction method with the list parameter.  * @param context * To use to open or create the database * @param name * of the database file, or null for In-memory Database * @param version * Number of the database (starting at 1); If the database is * older, onupgrade (sqlitedatabase, int, int) would be used to * upgrade the database; 
 If the database is newer, * Ondowngrade (sqlitedatabase, int, int) would be used to * downgrade the database * *
 Public Simplesqliteopenhelper (context, String name, int version) {Super (context, name, null, version);
 sqlstatementexed = null;
 /** * If you are creating or upgrading a database, use the construction method with the list parameter.  * @param context * To use to open or create the database * @param name * of the database file, or null for In-memory Database */Public simplesqliteopenhelper (context, String name) {Super (context, name, NULL, Init_ve
 Rsion);
 sqlstatementexed = null;
 /** * If you are creating or upgrading a database, use the construction method with the list parameter. * @param conText * To use to open or create the database * @param name * of the database file, or null for a in-memory D Atabase * @param version * Number of the database (starting at 1); If the database is * older, onupgrade (sqlitedatabase, int, int) would be used to * upgrade the database; If the database is newer, * Ondowngrade (sqlitedatabase, int, int) would be used to * downgrade the database *
 @param sqlcreatestatement * The statement to be executed when the database is created or upgraded. */Public Simplesqliteopenhelper (context, String name, int version, list<string> sqlcreatestatement) {s
 Uper (context, name, null, version);
 this.sqlstatementexed = sqlcreatestatement;
 /** * @param context * @param name * @param sqlcreatestatement * The statement to be executed when the database is created or upgraded.  */Public Simplesqliteopenhelper (context, String name, list<string> sqlcreatestatement) {Super (context,
 Name, NULL, init_version);
 this.sqlstatementexed = sqlcreatestatement; } * * (NON-JAVADOc) * @see * android.database.sqlite.sqliteopenhelper#oncreate (Android.database.sqlite *.
 sqlitedatabase) */@Override @Deprecated public void onCreate (Sqlitedatabase db) {exesqlstatementexed (db); }/* * (NON-JAVADOC) * @see * Android.database.sqlite.sqliteopenhelper#onupgrade (Android.database.sqlite *. sqlitedatabase, int, int) */@Override @Deprecated public void Onupgrade (sqlitedatabase db, int oldversion, int newver
 Sion) {if (NewVersion > Oldversion) {exesqlstatementexed (db);
 }/** The SQL statement that executes when the database is initialized or upgraded ... * * private void exesqlstatementexed (Sqlitedatabase db) {if (sqlstatementexed!= null) {for (String statement:sqlst
  atementexed) {db.execsql (statement);

 }
 }
 }
}

I hope the method described in this article will help you with the development of Android programs.

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.