|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectSQLiteOpenHelper
org.hermit.android.provider.DatabaseHelper
public class DatabaseHelper
This class helps open, create, and upgrade the database file.
Applications may use this class as is, or override it, for example to
provide a database upgrade handler. If you don't wish to override it,
nothing need be done. If you wish to subclass it, then create your
subclass and override TableProvider.getHelper()
to return it.
Constructor Summary | |
---|---|
DatabaseHelper(Context context,
DbSchema schema)
Creater a helper instance. |
Method Summary | |
---|---|
protected DbSchema |
getSchema()
Get the database schema. |
void |
onCreate(SQLiteDatabase db)
Called when the database is created for the first time. |
void |
onUpgrade(SQLiteDatabase db,
int oldVersion,
int newVersion)
Called when the database needs to be upgraded. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DatabaseHelper(Context context, DbSchema schema)
context
- Application context.schema
- Schema for this database.Method Detail |
---|
public void onCreate(SQLiteDatabase db)
The default implementation creates all the fields specified in all of the table schemas. Subclasses may override this, for example to add special fields.
db
- The new database.public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
The default implementation simply deletes all tables and calls
#onOpen(SQLiteDatabase)
. Subclasses may override this method
to do a more intelligent upgrade.
If you add new columns you can use ALTER TABLE to insert them into a live table. If you rename or remove columns you can use ALTER TABLE to rename the old table, then create the new table and then populate the new table with the contents of the old table.
db
- The new database.oldVersion
- The old database version.newVersion
- The new database version.protected DbSchema getSchema()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |