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.
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.