在SqlDelight 文档中的示例中, HockeyPlayerModel
SqlDelight 从HockeyPlayer.sq
文件生成是在抽象类中实现的public abstract class HockeyPlayer implements HockeyPlayerModel
在这个类中,字符串SELECT_ALL_INFO
作为查询传递给db.rawQuery(SELECT_ALL_INFO, new String[0])
. 该字符串SELECT_ALL_INFO
是由select_all_info
里面的语句生成的HockeyPlayer.sq
。但是,在我的情况下,我的语句没有生成字符串。为什么是这样?
我的声明
names_for_groups:
SELECT DISTINCT name, exercise_set_group FROM exercise_set JOIN exercises
USING (exercise_id) WHERE workout_FK = ? ORDER BY exercise_set_group ASC ;
我对ExerciseSetModel
SqlDelight 生成的实现
@AutoValue
public abstract class DbExerciseSet implements ExerciseSetModel, DbItem {
public static final Factory<DbExerciseSet> FACTORY = new Factory<>(AutoValue_DbExerciseSet::new);
public static final RowMapper<DbExerciseSet> MAPPER = FACTORY.select_allMapper();
public static final RowMapper<NamesForGroups> NAMES_FOR_GROUPS_MAPPER =
FACTORY.names_for_groupsMapper(AutoValue_DbExerciseSet_NamesForGroups::new);
public List<NamesForGroups> namesForGroups(SQLiteDatabase db) {
List<NamesForGroups> namesForGroupsList= new ArrayList<>();
Cursor cursor = db.rawQuery(NAMES_FOR_GROUPS, new String[0]);
while (cursor.moveToNext() && NAMES_FOR_GROUPS_MAPPER.map(cursor) != null) {
//NamesForGroups namesForGroups = NAMES_FOR_GROUPS_MAPPER.map(cursor);
namesForGroupsList.add(NAMES_FOR_GROUPS_MAPPER.map(cursor));
}
return namesForGroupsList;
}
@AutoValue
public abstract static class NamesForGroups implements Names_for_groupsModel {}
@AutoValue
public abstract static class Exercises implements ExerciseModel {}
}
需要明确的是,在该行中找不到变量引用 NAMES_FOR_GROUPSdb.rawQuery(NAMES_FOR_GROUPS, new String[0])