我有以下Dao课程:
@Dao
public interface AchievementDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertIntoDatabase(AchievementModel... achievementModel);
@Query("SELECT * FROM achievements WHERE game = :game")
AchievementModel[] getAchievementDataForGame(String game);
@Query("UPDATE achievements SET pointsAchieved = pointsAchieved + :points WHERE achievementKey = :achievementKey")
void updatePointsForKey(double points, String achievementKey);
@Query("SELECT * FROM achievements WHERE achievementKey LIKE :achievementKey")
AchievementModel getAchievementForKey(String achievementKey);
}
和以下模型类:
@Entity(tableName = "achievements", indices = {@Index(value = {"achievementKey"}, unique = true)})
public class AchievementModel {
@PrimaryKey @NonNull
private String achievementKey;
private String title;
private String description;
private double pointsAchieved;
private int imageId;
private int viewType;
private String game;
public AchievementModel(@NonNull String achievementKey, String title, String description,
double pointsAchieved, int imageId, int viewType, String game) {
this.achievementKey = achievementKey;
this.title = title;
this.description = description;
this.pointsAchieved = pointsAchieved;
this.imageId = imageId;
this.viewType = viewType;
this.game = game;
}
@NonNull
public String getAchievementKey() {
return achievementKey;
}
public void setAchievementKey(@NonNull String achievementKey) {
this.achievementKey = achievementKey;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public double getPointsAchieved() {
return pointsAchieved;
}
public void setPointsAchieved(double pointsAchieved) {
this.pointsAchieved = pointsAchieved;
}
public int getImageId() {
return imageId;
}
public void setImageId(int imageId) {
this.imageId = imageId;
}
public int getViewType() {
return viewType;
}
public void setViewType(int viewType) {
this.viewType = viewType;
}
public String getGame() {
return game;
}
public void setGame(String game) {
this.game = game;
}
}
DAO类中的前2个查询工作正常,而最后2个查询updatePointsForKey和getAchievementForKey不起作用。从后台线程正确调用它们。请帮忙。请告诉我是否需要更多关于这个问题的信息。
答案 0 :(得分:0)
更新查询可能返回int而不是void ...你怎么看?