【发布时间】:2011-05-14 01:52:23
【问题描述】:
我正在尝试创建一个 Android 应用程序,它可以处理玩过的游戏的历史及其分数,但是当我从记事本教程中扩展时,这变成了像这样重复语句的老鼠窝:
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);
}
这对于可读性和可维护性来说似乎是一场噩梦。关于如何更好地管理多个 SQL 表并将这些类型的列表变成漂亮干净的循环的任何建议?我正在考虑尝试通过资源字符串数组来做到这一点,但一直无法弄清楚如何管理它。
【问题讨论】: