0

SqlDelight 文档中的示例中, HockeyPlayerModelSqlDelight 从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 ;

我对ExerciseSetModelSqlDelight 生成的实现

@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])

4

1 回答 1

1

文档需要更新,我会这样做。我们不再在 SQLDelight 0.6.+ 中生成字符串,而是在工厂中有一个方法返回SQLDelightStatement用于查询的 a:

public List<NamesForGroups> namesForGroups(SQLiteDatabase db) {
    List<NamesForGroups> namesForGroupsList= new ArrayList<>();
    SQLDelightStatement query = FACTORY.name_for_groups();
    Cursor cursor = db.rawQuery(query.statement, query.args);
        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;
}
于 2017-04-27T15:17:27.640 回答