2017-04-27 247 views
0

在該示例中SqlDelight documentation,從HockeyPlayer.sq文件由SqlDelight產生的HockeyPlayerModel在一個抽象類public abstract class HockeyPlayer implements HockeyPlayerModelSqlDelight不產生SQL查詢字符串SQL語句

被實現在這個類中,字符串SELECT_ALL_INFO在作爲傳遞查詢到db.rawQuery(SELECT_ALL_INFO, new String[0])。字符串SELECT_ALL_INFOHockeyPlayer.sq內的select_all_info聲明生成。但是,在我的情況下,我的表述不會產生字符串。爲什麼是這樣?

我的發言

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 ; 

通過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_GROUPS沒有在該行發現db.rawQuery(NAMES_FOR_GROUPS, new String[0])

回答

1

文檔生成我的ExerciseSetModel的實施需要更新,我會這樣做。我們不再在SQLDelight 0.6生成的字符串+取而代之的是對工廠的方法,可返回用於查詢SQLDelightStatement

與文檔更改
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; 
} 
+0

滿拉請求:https://github.com/square/sqldelight/pull/628 – Anstrong

+0

非常感謝;我在這段時間裏一直在絞盡腦汁 –