I'm making a database application, and my program works and I've understood most of the tutorial I've been following. However, one aspect remains unclear to me.
There is an inner class of MyDBHelper extending SQLiteOpenHelper. Outer variables include the SQLiteDatabase called d. The code for the MyDBHelper is:
private static class MyDBHelper extends SQLiteOpenHelper {
MyDBHelper(Context c) {
super(c, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(DATABASE_CREATE);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVers, int newVers) {
Log.w(TAG, "Upgrading database from version " + oldVers + " to " + newVers + ", which will destroy all old data.");
db.execSQL("DROP TABLE IF EXISTS GM");
onCreate(db);
}
}
My question is how does this actually create the initial database. It occurs in the onCreate() method, but as far as I can see, this is never called. I understand that it is called when the database is created for the first time, but where? And furthermore, how is it passed a SQLiteDatabase db? I haven't passed any database to the method. And how is my SQLiteDatabase db variable from the outer class set to the created database? Could someone talk me through this like an idiot?