I'm trying to create an Android app that can handle a history of played games and their scores, but as I expand from the Notepad tutorial, this is turning into a rat's nest of repeated statements like this:
private static final String GAME_TABLE_CREATE =
"create table " + GAME_TABLE + " (_id integer primary key autoincrement, "
+ "title text not null);";
private static final String PLAY_TABLE_CREATE =
"create table " + PLAY_TABLE + " (_id integer primary key autoincrement, "
+ "game_id integer, game_date date);";
private static final String PLAYER_TABLE_CREATE =
"create table " + PLAYER_TABLE + " (_id integer primary key autoincrement, "
+ "name text not null);";
private static final String SCORE_TABLE_CREATE =
"create table " + SCORE_TABLE + " (_id integer primary key autoincrement, "
+ "game_id int, player_id int, score int);";
...
public void onCreate(SQLiteDatabase db) {
db.execSQL(GAME_TABLE_CREATE);
db.execSQL(PLAY_TABLE_CREATE);
db.execSQL(PLAYER_TABLE_CREATE);
db.execSQL(SCORE_TABLE_CREATE);
}
This seems like a nightmare for readability and maintainability. Any advice on how to better manage multiple SQL tables, and turn these kinds of lists into nice clean loops? I was thinking about trying to do it via resource string-arrays, but haven't been able to figure out how to manage that.