I need to put some example data into a Sqlite database when my android app is run for the for the first time.
My database works great and I have a working method that puts example data into the database. But my problem is where do I call it? I only want my sample data to be inserted when the database is first created. The user can then remove it
My first idea was to call my createSampleData() in onCreate, but then the db will be called recursively and the app crashes.
In my onCreate all my tables are create. Maybe I should put something in those statements? Should I somehow see if these tables get created and then insert the example data?
Fumbling here.
public void onCreate(SQLiteDatabase database) {
String sessionTableQuery = "CREATE TABLE " + SESSION_TABLE + "(" + "id INTEGER PRIMARY KEY AUTOINCREMENT," + "comment TEXT," + "date DATETIME DEFAULT CURRENT_TIMESTAMP)"; String exerciseTableQuery = "CREATE TABLE " + EXERCISE_TABLE + " (" + "exercisId INTEGER PRIMARY KEY AUTOINCREMENT," + "name TEXT," + "weight INTEGER," + "reps INTEGER," + "rpm INTEGER," + "score FLOAT," + "sessionId INTEGER NOT NULL)"; String customTimerSessionTableQuery = "CREATE TABLE " + CUSTOM_TIMER_SESSION_TABLE + "(" + "id INTEGER PRIMARY KEY AUTOINCREMENT," + "name TEXT," + "rounds INTEGER," + "date DATETIME DEFAULT CURRENT_TIMESTAMP)"; String customTimerTableQuery = "CREATE TABLE " + CUSTOM_TIMER_TABLE + " (" + "timerId INTEGER PRIMARY KEY AUTOINCREMENT," + "name TEXT," + "millis INTEGER," + "metronome BOOL," + "rpm INTEGER," + "type INTEGER," + "sessionId INTEGER NOT NULL)"; database.execSQL(sessionTableQuery); database.execSQL(exerciseTableQuery); database.execSQL(customTimerSessionTableQuery); database.execSQL(customTimerTableQuery); }