0

我目前正在这样做。

有没有更好的办法?

public Cursor selectRostersForTeam(Activity activity, int teamId) {

    final String MY_QUERY = "SELECT r." + _ROSTER_ID + ", t." + _TEAM_ID + ", t." + TEAM_NAME + ", t." + TEAM_SEASON_WINS + ", t." + TEAM_SEASON_LOSSES + ", t." + TEAM_CHAMPIONSHIP_WINS + ", j." + _TEAMS_ROSTERS_ID + " FROM " + TABLE_TEAM + " AS p" + " JOIN " + TABLE_TEAMS_ROSTERS + " j ON (r." + _ROSTER_ID + " = j." + TEAMS_ROSTER_ROSTER_ID + ") " + " JOIN " + TABLE_TEAM + " ch ON (j." + TEAMS_ROSTER_TEAM_ID + " = t." + _TEAM_ID + ") WHERE j. " + TEAMS_ROSTER_TEAM_ID + " = " + teamId + ";";



    SQLiteDatabase db = getReadableDatabase();

    Cursor cursor = db.rawQuery(MY_QUERY, null);

    activity.startManagingCursor(cursor);

    return cursor;
}
4

1 回答 1

1

的替代方案rawQuery()query(),但不是为连接而设计的。

如果您认为您的连接足够重要,您可以从中创建一个视图,然后在表中使用它query()


注意:建议将值teamId作为参数传递,而不是将它们格式化为查询字符串:

rawQuery(..._TEAM_ID + " = ?", new String[] { Integer.toString(teamId) });
于 2012-10-16T12:13:41.517 回答