com.neomades.database.DatabaseOpenHelper |
You create a subclass implementing onCreate(Database)
,
onUpgrade(Database, int, int)
and optionally
onOpen(Database)
, and this class takes care of opening the database
if it exists, creating it if it does not, and upgrading it as necessary.
Transactions are used to make sure the database is always in a sensible
state.
This class can be used to execute some SQL queries for upgrading database.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
abstract void |
onCreate(Database db)
Called when the database is created for the first time.
| ||||||||||
abstract void |
onOpen(Database db)
Called when the database has been opened.
| ||||||||||
abstract void |
onUpgrade(Database db, int oldVersion, int newVersion)
Called when the database needs to be upgraded.
|
Called when the database is created for the first time. This is where the creation of tables and the initial population of the tables should happen.
db | the database |
---|
Called when the database has been opened. This method is called after the database connection has been configured and after the database schema has been created, upgraded or downgraded as necessary.
db | the database |
---|
Called when the database needs to be upgraded. The implementation should use this method to drop tables, add tables, or do anything else it needs to upgrade to the new schema version.
db | the database |
---|---|
oldVersion | the old database version |
newVersion | the new database version |